<feed xmlns='http://www.w3.org/2005/Atom'>
<title>luci/modules/luci-base/src/contrib, branch master</title>
<subtitle>Lua Configuration Interface (mirror)</subtitle>
<id>https://git-03.infra.openwrt.org/project/luci/atom?h=master</id>
<link rel='self' href='https://git-03.infra.openwrt.org/project/luci/atom?h=master'/>
<link rel='alternate' type='text/html' href='https://git-03.infra.openwrt.org/project/luci/'/>
<updated>2020-01-25T22:21:35Z</updated>
<entry>
<title>luci-base: add support for plural translations and contexts in Lua api</title>
<updated>2020-01-25T22:21:35Z</updated>
<author>
<name>Jo-Philipp Wich</name>
</author>
<published>2020-01-23T20:53:26Z</published>
<link rel='alternate' type='text/html' href='https://git-03.infra.openwrt.org/project/luci/commit/?id=9939fc5a26d07da4756497bb6a7dc51dcf379e98'/>
<id>urn:sha1:9939fc5a26d07da4756497bb6a7dc51dcf379e98</id>
<content type='text'>
 - Introduce a new luci.template.parser.ntranslate() function which
   takes a count, a singular and a plural translation string as well
   as an optional context argument and returns the appropriate,
   language specific plural translation.

 - Introduce an optional translation context argument in the existing
   luci.template.parser.translate() function

 - Support translation contexts in LuCI template directives.
   Translation messages are split on the first unescaped pipe
   character and the reamining string after the pipe is treated
   as context.

Examples:

 - `string.format(p.ntranslate(n, "1 apple", "%d apples"), n)` will
   return an appropriate plural translation for the given amount.

 - `translate("Load", "The system load")` will return an appropiate
   translation for `Load`, using `The system load` as disambiguation
   context (a `msgctxt` directive in *.po files).

 - Likewise `&lt;%:Load|The system load%&gt;` will translate the word
   `Load` while using the remainder of the string as context.

 - To use pipes in translations strings literally, they must be
   escaped: `&lt;%:Use the "\|" character%&gt;` will translate the literal
   string `Use the "|" character`.

Signed-off-by: Jo-Philipp Wich &lt;jo@mein.io&gt;
</content>
</entry>
</feed>
