Jump to content
Toggle menu
  • 8 articles
  • 75 files
  • 7 users
  • 37.8K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Multilingual/doc: Difference between revisions

From Neodyland Wiki
de>PerfektesChaos
t
m 22 revisions imported
 
(17 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{LuaModuleDoc}}
'''<code>Multilingual</code>''' – Module with functions in context of languages, language codes, language names.
<onlyinclude>'''<code>Multilingual</code>''' – Module with functions in context of languages, language codes, language names.


== {{Anker|template}} Functions for templates ==
== Functions for templates ==
All functions expect one unnamed parameter <code>1</code> with the key information, and sometimes more optionals. Whitespace ahead and after any content is ignored. Upcasing of language code segments like in <code>en-US</code> does not matter; results are downcased.
All functions expect one unnamed parameter <code>1</code> with the key information, and sometimes more optionals. Whitespace ahead and after any content is ignored. Upcasing of language code segments like in <code>en-US</code> does not matter; results are downcased.


The return value is an empty string (“nothing”), if the parameter value does not fulfil the expectations. If there is a result or the query condition is true, at least one visible character will be returned. The result does not begin or end with a space.
The return value is an empty string (“nothing”), if the parameter value does not fulfil the expectations. If there is a result or the query condition is true, at least one visible character will be returned. The result does not begin or end with a space.


; findCode   {{Anker|findCode}}
; fair
: Format language code according to RFC 5646 and check validity
:* ''Result:'' empty, if invalid
; findCode
: Retrieve code of language name in local (current project) language.
: Retrieve code of language name in local (current project) language.
: A code itself will be identified, too.
: A code itself will be identified, too.
; format   {{Anker|format}}
; format
: Format one or more languages.
: Format one or more languages.
:* <code>1</code> – language list or single item
:* <code>1</code> – language list or single item
Line 27: Line 29:
:* <code>separator</code> – list separator, else <code>split</code>
:* <code>separator</code> – list separator, else <code>split</code>
:* <code>start</code> – prepend first list element, if any
:* <code>start</code> – prepend first list element, if any
; getBase   {{Anker|getBase}}
; getBase
: Retrieve base language from possibly combined ISO language code.
: Retrieve base language from possibly combined ISO language code.
; getName   {{Anker|getName}}
; getName
: Which name is assigned to this language code?
: Which name is assigned to this language code?
:* <code>2</code> – language of the answer
:* <code>2</code> – language of the answer
Line 35: Line 37:
:** <code>!</code> – in project language
:** <code>!</code> – in project language
:** Any ISO code.
:** Any ISO code.
; isLang   {{Anker|isLang}}
; isLang
: Could this be an ISO language code?
: Could this be an ISO language code?
:* ''nothing'' – if not
:* ''nothing'' – if not
; isLangWiki   {{Anker|isLangWiki}}
; isLangWiki
: Could this be a Wiki language version?
: Could this be a Wiki language version?
:* ''nothing'' – if not
:* ''nothing'' – if not
; kannDeutsch   {{Anker|kannDeutsch}}
; kannDeutsch
: Might someone with this language code understand German?
: Might someone with this language code understand German?
:* ''nothing'' – if not
:* ''nothing'' – if not
; userLang   {{Anker|userLang}}
; userLang
: Try to support user language by application.
: Try to support user language by application.
:* <code>1</code> – space separated list of available ISO 639 codes
:* <code>1</code> – space separated list of available ISO 639 codes
Line 51: Line 53:
:** If the current user language is a variant like <code>en-US</code> or <code>en-GB</code> and that is not mentioned explicitly in list, base language (here&nbsp;<code>en</code>) will be tried.
:** If the current user language is a variant like <code>en-US</code> or <code>en-GB</code> and that is not mentioned explicitly in list, base language (here&nbsp;<code>en</code>) will be tried.
:** If nothing matches and no list is provided, the project language (here&nbsp;<code>{{CONTENTLANGUAGE}}</code>), at least <code>en</code> for English will be returned.
:** If nothing matches and no list is provided, the project language (here&nbsp;<code>{{CONTENTLANGUAGE}}</code>), at least <code>en</code> for English will be returned.
; failsafe
: Version ID: <code>{{#invoke:Multilingual|failsafe}}</code>
: optional parameter <code>1</code> – required version
:: result: empty, if requirement not met


=== Examples (test page) ===
=== Examples (test page) ===
A [[Wikipedia:Lua/Modul/Multilingual/Test|test page]] illustrates practical use.
A [[Wikipedia:Lua/Modul/Multilingual/Test|test page]] illustrates practical use.
</onlyinclude>
== Functions for Lua modules (API) ==
== {{Anker|Lua}} Functions for Lua modules (API) ==


All functions described above can be used by other modules:
All functions described above can be used by other modules:
Line 68: Line 73:
</syntaxhighlight>
</syntaxhighlight>
Subsequently there are available:
Subsequently there are available:
; Multilingual.[[#findCode|findCode]]( ask )   {{Anker|findCode()}}
; Multilingual.fair( ask )
; Multilingual.[[#format|format]]( apply, alien, alter, active, alert, frame, assembly, adjacent )   {{Anker|format()}}
:* ''ask'' – string, or table according to getLang()
; Multilingual.findCode( ask )
; Multilingual.format( apply, alien, alter, active, alert, frame, assembly, adjacent )
:* ''apply'' – string with language list or single item
:* ''apply'' – string with language list or single item
:* ''alien'' – language of the answer
:* ''alien'' – language of the answer
Line 85: Line 92:
:* ''adjacent'' – string with list separator, else ''assembly''
:* ''adjacent'' – string with list separator, else ''assembly''
:* ''ahead'' – string for optional prepending first element, if any
:* ''ahead'' – string for optional prepending first element, if any
; Multilingual.[[#getBase|getBase]]( ask )   {{Anker|getBase()}}
; Multilingual.getBase( ask )
; Multilingual.[[#getName|getName]]( ask, alien )   {{Anker|getName()}}
; Multilingual.getLang( ask )
: Split language code into components
: Returns: ''table''
:: <code>.base</code> – Basic language (2–3 lowercase letters)
:: <code>.region</code> – Country (2 uppercase letters)
:: <code>.script</code> – Scripting (4 letters, capitalized)
:: <code>.year</code> – year (4 digits)
:: <code>.extension</code> – Extension (1 lowercase letter)
:: <code>.other</code> – More
:: <code>.legal</code> – ''true'' if valid
:: <code>.n</code> – Number of components
; Multilingual.getName( ask, alien )
:* ''alien'' – language of the answer
:* ''alien'' – language of the answer
:** <code>nil false "*"</code> – native
:** <code>nil false "*"</code> – native
:** <code>"!"</code> – current project
:** <code>"!"</code> – current project
:** Any ISO code.
:** Any ISO code.
; Multilingual.[[#isLang|isLang]]( ask )   {{Anker|isLang()}}
; Multilingual.isLang( ask )
; Multilingual.[[#isLangWiki|isLangWiki]]( ask )   {{Anker|isLangWiki()}}
; Multilingual.isLangWiki( ask )
; Multilingual.[[#kannDeutsch|kannDeutsch]]( ask )   {{Anker|kannDeutsch()}}
; Multilingual.kannDeutsch( ask )
; Multilingual.[[#userLang|userLang]]( accept, frame )   {{Anker|userLang()}}
; Multilingual.userLang( accept, frame )
:* ''accept'' – string with space separated list of available ISO 639 codes
:* ''accept'' – string with space separated list of available ISO 639 codes
:* ''frame'' – if available
:* ''frame'' – if available
; Multilingual.failsafe( atleast )
:* atleast<br />''optional''<br />''nil'' or required version
:* Returns: ''string'' or ''false''
If succeeding, the ''Multilingual.get*()'' return a string, the ''Multilingual.is*()'' <code>true</code>; on failure <code>false</code>.
If succeeding, the ''Multilingual.get*()'' return a string, the ''Multilingual.is*()'' <code>true</code>; on failure <code>false</code>.


Line 103: Line 124:


== Dependencies ==
== Dependencies ==
None.
* [[Module:WLink|WLink]]
* [[../../WLink|WLink]]
* [[Module:Multilingual/config|/config]] – optional project specific adaption
* [[../config|/config]] – optional project specific adaption
 
[[Kategorie:Wikipedia:Lua/Modul/Dokumentation|Multilingual/en]]

Latest revision as of 16:37, 12 August 2026

Multilingual – Module with functions in context of languages, language codes, language names.

Functions for templates

edit

All functions expect one unnamed parameter 1 with the key information, and sometimes more optionals. Whitespace ahead and after any content is ignored. Upcasing of language code segments like in en-US does not matter; results are downcased.

The return value is an empty string (“nothing”), if the parameter value does not fulfil the expectations. If there is a result or the query condition is true, at least one visible character will be returned. The result does not begin or end with a space.

fair
Format language code according to RFC 5646 and check validity
  • Result: empty, if invalid
findCode
Retrieve code of language name in local (current project) language.
A code itself will be identified, too.
format
Format one or more languages.
  • 1 – language list or single item
  • slang – language of the answer, if not native
    • * – native (default)
    • ! – current project
    • any valid code
  • shift – capitalization
    • c – capitalize all
    • d – downcase everything
    • f – capitalize first item only
    • m – downcase every first word in item only
  • link=1 – link items
  • scream – category title in case of error
  • split – split pattern, if list expected; e.g. split=, – otherwise 1 is regarded as single item
  • separator – list separator, else split
  • start – prepend first list element, if any
getBase
Retrieve base language from possibly combined ISO language code.
getName
Which name is assigned to this language code?
  • 2 – language of the answer
    • * – in that language itself (default)
    • ! – in project language
    • Any ISO code.
isLang
Could this be an ISO language code?
  • nothing – if not
isLangWiki
Could this be a Wiki language version?
  • nothing – if not
kannDeutsch
Might someone with this language code understand German?
  • nothing – if not
userLang
Try to support user language by application.
  • 1 – space separated list of available ISO 639 codes
  • Result:
    • If the current user language is not a list element, the first element is used.
    • If the current user language is a variant like en-US or en-GB and that is not mentioned explicitly in list, base language (here en) will be tried.
    • If nothing matches and no list is provided, the project language (here en), at least en for English will be returned.
failsafe
Version ID: 2020-12-10
optional parameter 1 – required version
result: empty, if requirement not met

Examples (test page)

edit

A test page illustrates practical use.

Functions for Lua modules (API)

edit

All functions described above can be used by other modules:

local lucky, Multilingual = pcall( require, "Module:Multilingual" )
if type( Multilingual ) == "table" then
    Multilingual = Multilingual.Multilingual()
else
    -- failure; Multilingual is the error message
    return "<span class='error'>" .. Multilingual .. "</span>"
end

Subsequently there are available:

Multilingual.fair( ask )
  • ask – string, or table according to getLang()
Multilingual.findCode( ask )
Multilingual.format( apply, alien, alter, active, alert, frame, assembly, adjacent )
  • apply – string with language list or single item
  • alien – language of the answer
    • nil false "*" – native
    • "!" – current project
    • any valid code
  • alter – capitalization
    • "c" – capitalize
    • "d" – downcase everything
    • "f" – capitalize first item only, downcase anything else
  • active – link items, if true
  • alert – string with category title in case of error
  • frame – if available
  • assembly – string with split pattern, if list expected
  • adjacent – string with list separator, else assembly
  • ahead – string for optional prepending first element, if any
Multilingual.getBase( ask )
Multilingual.getLang( ask )
Split language code into components
Returns: table
.base – Basic language (2–3 lowercase letters)
.region – Country (2 uppercase letters)
.script – Scripting (4 letters, capitalized)
.year – year (4 digits)
.extension – Extension (1 lowercase letter)
.other – More
.legaltrue if valid
.n – Number of components
Multilingual.getName( ask, alien )
  • alien – language of the answer
    • nil false "*" – native
    • "!" – current project
    • Any ISO code.
Multilingual.isLang( ask )
Multilingual.isLangWiki( ask )
Multilingual.kannDeutsch( ask )
Multilingual.userLang( accept, frame )
  • accept – string with space separated list of available ISO 639 codes
  • frame – if available
Multilingual.failsafe( atleast )
  • atleast
    optional
    nil or required version
  • Returns: string or false

If succeeding, the Multilingual.get*() return a string, the Multilingual.is*() true; on failure false.

Usage

edit

General library; no limitations.

Dependencies

edit
Cookies help us deliver our services. By using our services, you agree to our use of cookies.