Module:Common/doc

From Dune: Awakening Community Wiki
Jump to navigation Jump to search

This is the documentation page for Module:Common

Module:Common

Shared stateless helper functions, which can be loaded in other Lua modules via:

local common = require("Module:Common")

Usage

This module also exposes a few permanent utility entry points.

Replace tildes with another character

Tildes are good delimiters in the wiki context, as the alternatives are commas, which are common in prose, and pipes, which are special wikitext characters.

By default, tildes ~ will be replaced by pipes |:

{{#invoke:Common|replaceTilde|Item 1~Item 2~Item 3}}

Optionally, a character can be specified to be used as the replacement. For example, comma:

{{#invoke:Common|replaceTilde|Item 1~Item 2~Item 3|,}}

Render a tilde-delimited string as a bullet list

Converts a tilde-separated string into a bullet list. The list items are left-aligned (by default), while the list as a whole remains centered.

{{#invoke:Common|bulletList|Item 1~Item 2~Item 3}}

Optionally, set link=true to wrap each item as a wikilink:

{{#invoke:Common|bulletList|Item 1~Item 2~Item 3|link=true}}

Optionally, set leftAlign=no to omit the left-alignment, allowing invoking elements to control text alignment instead:

{{#invoke:Common|bulletList|Item 1~Item 2~Item 3|leftAlign=no}}

Get URL-safe version of a given string

MessageBundle keys are built from a slugified (URL-safe) version of a string. Use this to check the exact slug a given input will produce.

If no value is specified, it defaults to the current page's title:

{{#invoke:Common|checkSlug}}

A specific string can also be provided instead:

{{#invoke:Common|checkSlug|Terrarium of Muad'Dib}}

Get an auto-localised string from a MessageBundle

Retrieves a string for a given key from a specified MessageBundle. It auto-switches to the language that the viewer's page is currently on, and falls back to the English source if no translation exists for the current language.

{{#invoke:Common|localise|Vehicles|sandbike-name}}

Optionally, set link=true to wrap the result as a stable link to the English page name, e.g. [[Wildlife of Arrakis|Fauna von Arrakis]]:

{{#invoke:Common|localise|DLC|wildlife-of-arrakis-name|link=true}}

Resolve translation of a specified page

Checks whether a translated subpage exists for a given page title, and returns the subpage path if so, e.g. Buildables/de. If no translation exists, the original title is returned unchanged.

This is intended for building wikilinks manually, so that readers on a translated page continue to stay in their language, as far as possible, when navigating to other pages:

[[{{#invoke:Common|localiseTitle|Buildables|de}}|Bauwerke]]

Note that link targets which are redirects are not resolved, so their translations will not be picked up.

Parameters

replaceTilde

1
string
The string containing tildes ~ to replace.
2 (optional)
string
The character to replace the tildes with.
Defaults to pipe |.

bulletList

1
string
The tilde-separated string of items to convert into a bullet list.
link (optional)
boolean
If specified with a truthy value, each item will be wrapped in double square brackets, rendering it as a wikilink.
Valid values:
true
yes
1
leftAlign (optional)
boolean
If set to a falsy value, the inline text-align:left style is omitted from the list wrapper, so the caller's own CSS can control alignment instead.
Defaults to true.

checkSlug

1 (optional)
string
The string to generate a slug for.
If omitted, defaults to the current page's title.

localise

1
string
The name of the MessageBundle to look up (without the "MessageBundle:" prefix).
2
string
The key to retrieve from the MessageBundle.
link (optional)
boolean
If true, wraps the result as [[English|Translation]] instead of just plain text.
Defaults to false.

localiseTitle

1
string
The English title of the target page.
2
string
Language code of the translated subpage to look for.