Module:Common/doc
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.
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 stay in their language when following the link:
[[{{#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
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.