Module:Dir/doc

From "PTTLink Wiki"
Jump to navigation Jump to search

This is the documentation page for Module:Dir

This module provides functions for determining whether a given language code is LTR or RTL.

  • It uses the RTL or LTR status of languages defined in the data returned by Module:Dir/RTL overrides.
  • Otherwise, if a language code is not mapped, it uses the language direction provided by the MediaWiki language library (but this only works for a limited number of distinct languages in the same viewed page, as the MediaWiki library sets a quota on the number of languages for which it can load localized data). For this reason, if a page uses lots of languages (for example with Template:Multilingual description) the data should be as complete as possible to avoid reaching this quota.

This module includes a quick test function whose status is displayed at top of its description page: this status is OK if there are no errors in the data, i.e. only valid or known language codes are mapped. When you run it in the console, it regenerates the Lua code that may be imported to Module:Dir/RTL overrides, and containing deduplicated and sorted code lists, including missing codes detected and supported by the MediaWiki API.

Usage

From wikitext

From wikitext, this module may be used through a template, Template:Dir. Please see the template page for documentation.

However, the template version is standalone and does not need to use this Lua module (for performance reason, in order to avoid the extra cost of instantiating a Lua engine).

This module is still faster than preprocessing a template from Lua. So the list of RTL languages in the template version should be kept in sync with the list of overrides used by this module.

From Lua

From Lua you can use the module's isRTL function. First, load the module:

local dir = require('Module:Dir')

Then you can use the function like this:

dir.isRTL(lang) -- returns false or true
The lang variable is the language code string. The function returns true if the language for the code is detected as RTL, and it returns false if it is LTR or if the code is absent or invalid.
dir.select(lang, rtl, ltr)  -- returns either the rtl or ltr parameter values
Same thing except that you can define the value to return for each case.

Testing

In the Lua console, you can run the included quick test to scan the data defined in Module:Dir/RTL overrides: it provides a detailed report of invalid language codes, missing languages known by MediaWiki, and helps maintaining this data.

For seeing the complete list of languages, tested with their directionality defined here along with other properties, look at the comprehensive results on Module talk:Multilingual description/sort/testcases.