Acciones

Módulo

Módulo:Dir/doc

De La Venciclopedia

Esta es la página de documentación de Módulo: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 Módulo: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 Plantilla: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 Módulo: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 must be used through a template, Plantilla:Dir. Please see the template page for documentation.

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 Módulo: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.