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
kl.ergs
de>PerfektesChaos
+
Line 25: Line 25:
:* <code>split</code> – split pattern, if list expected; e.g. <code>split=,</code> – otherwise <code>1</code> is regarded as single item
:* <code>split</code> – split pattern, if list expected; e.g. <code>split=,</code> – otherwise <code>1</code> is regarded as single item
:* <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
; getBase  {{Anker|getBase}}
; getBase  {{Anker|getBase}}
: Retrieve base language from possibly combined ISO language code.
: Retrieve base language from possibly combined ISO language code.
Line 82: Line 83:
:* ''assembly'' – string with split pattern, if list expected
:* ''assembly'' – string with split pattern, if list expected
:* ''adjacent'' – string with list separator, else ''assembly''
:* ''adjacent'' – string with list separator, else ''assembly''
:* ''ahead'' – string for optional prepending first element, if any
; Multilingual.[[#getBase|getBase]]( ask )  {{Anker|getBase()}}
; Multilingual.[[#getBase|getBase]]( ask )  {{Anker|getBase()}}
; Multilingual.[[#getName|getName]]( ask, alien )  {{Anker|getName()}}
; Multilingual.[[#getName|getName]]( ask, alien )  {{Anker|getName()}}

Revision as of 08:59, 17 October 2014

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

Template:Anker Functions for templates

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.

findCode Template:Anker
Retrieve code of language name in local (current project) language.
A code itself will be identified, too.
format Template:Anker
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
  • 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 Template:Anker
Retrieve base language from possibly combined ISO language code.
getName Template:Anker
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 Template:Anker
Could this be an ISO language code?
  • nothing – if not
isLangWiki Template:Anker
Could this be a Wiki language version?
  • nothing – if not
kannDeutsch Template:Anker
Might someone with this language code understand German?
  • nothing – if not
userLang Template:Anker
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.

Examples (test page)

A test page illustrates practical use.

Template:Anker Functions for Lua modules (API)

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.findCode( ask ) Template:Anker
Multilingual.format( apply, alien, alter, active, alert, frame, assembly, adjacent ) Template:Anker
  • 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 ) Template:Anker
Multilingual.getName( ask, alien ) Template:Anker
  • alien – language of the answer
    • nil false "*" – native
    • "!" – current project
    • Any ISO code.
Multilingual.isLang( ask ) Template:Anker
Multilingual.isLangWiki( ask ) Template:Anker
Multilingual.kannDeutsch( ask ) Template:Anker
Multilingual.userLang( accept, frame ) Template:Anker
  • accept – string with space separated list of available ISO 639 codes
  • frame – if available

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

Usage

General library; no limitations.

Dependencies

None.

  • [[../../WLink|WLink]]
  • /config – optional project specific adaption

Multilingual/en

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