切换搜索
搜索
切换菜单
notifications
切换个人菜单
查看“模块:Multilingual/doc”的源代码
来自决策链云智库
更多操作
←
模块:Multilingual/doc
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
'''<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
本页使用的模板:
模块:Multilingual
(
查看源代码
)
返回
模块:Multilingual/doc
。