Module:Dir/doc : Différence entre versions

De Wiklou, le Wiki du Biclou
Aller à : navigation, rechercher
m
 
m (1 révision importée)
 
(Aucune différence)

Version actuelle datée du 18 janvier 2016 à 13:56

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 somplete 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.

Usage

From wikitext

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

From Lua

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

<source lang="lua"> local dir = require('Module:Dir') </source>

Then you can use the function like this:

<source lang="lua"> dir.isRTL(lang) -- returns false or true </source>

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.

<source lang="lua"> dir.select(lang, rtl, ltr) -- returns either the rtl or ltr parameter values </source>

Same thing except that you can define the value to return for each case.

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.