Module:I18n/range
Appearance
From Meta, a Wikimedia project coordination wiki
Module documentation
You might want to create a documentation page for this Scribunto module.
Editors can experiment in this module’s sandbox (create | mirror) and testcases (create) pages.
Please add categories to the /doc subpage. Subpages of this module.
Editors can experiment in this module’s sandbox (create | mirror) and testcases (create) pages.
Please add categories to the /doc subpage. Subpages of this module.
p={} -- Constants -- keep them identical to /data ones START=1-- 5ドル-10 END=2-- 5-10$ BEFORE_BOTH=3-- 5ドル-10ドル AFTER_BOTH=4-- 5$-10$ AFTER_FIRST=5-- 5$-10 BEFORE_FIRST=START BEFORE_SECOND=6-- 5-10ドル AFTER_SECOND=END --[[ Creates a range formatted according to language data provided by /data subpage. Arguments: - from: (number) lower element of the range - to: (number) higher element of the range - unit: (string) unit for these numbers - cur: (bool) whether unit is a currency - lang: (string) language code in which to get formatting data (defaults to {{PAGELANGUAGE}}) ]] p.main=function(frame) args=frame.args rendering="" langCode=args["lang"]orframe:preprocess("{{PAGELANGUAGE}}") lang=mw.language.new(langCode) from=lang:formatNum(tonumber(args["from"]or"")) to=lang:formatNum(tonumber(args["to"]or"")) unit=args["unit"]or"" isCurrency=args["cur"]andargs["cur"]~=""orfalse i18nData=mw.loadData("Module:I18n/range/data") localData=i18nData[langCode]or{} defaultData=i18nData["en"] rangeSeparator=localData["range_sep"]ordefaultData["range_sep"] ifisCurrencythen unitSeparator=localData["cur_sep"]ordefaultData["cur_sep"] unitLocation=localData["cur_loc"]ordefaultData["cur_loc"] else unitSeparator=localData["unit_sep"]ordefaultData["unit_sep"] unitLocation=localData["unit_loc"]ordefaultData["unit_loc"] end ifunit==""then unitSeparator="" end ifunitLocation==STARTthen rendering=unit..unitSeparator..from..rangeSeparator..to elseifunitLocation==ENDthen rendering=from..rangeSeparator..to..unitSeparator..unit elseifunitLocation==BEFORE_BOTHthen rendering=unit..unitSeparator..from..rangeSeparator..unit..unitSeparator..to elseifunitLocation==AFTER_BOTHthen rendering=from..unitSeparator..unit..rangeSeparator..to..unitSeparator..unit elseifunitLocation==AFTER_FIRSTthen rendering=from..unitSeparator..unit..rangeSeparator..to elseifunitLocation==BEFORE_SECONDthen rendering=from..rangeSeparator..unit..unitSeparator..to end returnrendering end returnp