Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Multilingual/doc
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
'''<code>Multilingual</code>''' β Module with functions in context of languages, language codes, language names. == 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. 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. :* <code>1</code> β language list or single item :* <code>slang</code> β language of the answer, if not native :** <code>*</code> β native ''(default)'' :** <code>!</code> β current project :** any valid code :* <code>shift</code> β capitalization :** <code>c</code> β capitalize all :** <code>d</code> β downcase everything :** <code>f</code> β capitalize first item only :** <code>m</code> β downcase every first word in item only :* <code>link=1</code> β link items :* <code>scream</code> β category title in case of error :* <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>start</code> β 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? :* <code>2</code> β language of the answer :** <code>*</code> β in that language itself ''(default)'' :** <code>!</code> β 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. :* <code>1</code> β 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 <code>en-US</code> or <code>en-GB</code> and that is not mentioned explicitly in list, base language (here <code>en</code>) will be tried. :** If nothing matches and no list is provided, the project language (here <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) === A [[Wikipedia:Lua/Modul/Multilingual/Test|test page]] illustrates practical use. == Functions for Lua modules (API) == All functions described above can be used by other modules: <syntaxhighlight lang="lua"> 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 </syntaxhighlight> 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 :** <code>nil false "*"</code> β native :** <code>"!"</code> β current project :** any valid code :* ''alter'' β capitalization :** <code>"c"</code> β capitalize :** <code>"d"</code> β downcase everything :** <code>"f"</code> β capitalize first item only, downcase anything else :* ''active'' β link items, if <code>true</code> :* ''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'' :: <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 :** <code>nil false "*"</code> β native :** <code>"!"</code> β 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<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>. == Usage == General library; no limitations. == Dependencies == * [[Module:WLink|WLink]] * [[Module:Multilingual/config|/config]] β optional project specific adaption
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Multilingual
(
edit
)