Jo-Philipp Wich 9939fc5a26 luci-base: add support for plural translations and contexts in Lua api
- 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 `<%:Load|The system load%>` 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: `<%:Use the "\|" character%>` will translate the literal
   string `Use the "|" character`.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-01-25 23:21:35 +01:00

33 lines
878 B
Makefile

%.o: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(FPIC) -DNDEBUG -c -o $@ $<
contrib/lemon: contrib/lemon.c contrib/lempar.c
cc -o contrib/lemon $<
plural_formula.c: plural_formula.y contrib/lemon
./contrib/lemon -q $<
template_lmo.c: plural_formula.c
clean:
rm -f contrib/lemon po2lmo parser.so version.lua plural_formula.c plural_formula.h *.o
jsmin: jsmin.o
$(CC) $(LDFLAGS) -o $@ $^
po2lmo: po2lmo.o template_lmo.o plural_formula.o
$(CC) $(LDFLAGS) -o $@ $^
parser.so: template_parser.o template_utils.o template_lmo.o template_lualib.o plural_formula.o
$(CC) $(LDFLAGS) -shared -o $@ $^
version.lua:
./mkversion.sh $@ $(LUCI_VERSION) "$(LUCI_GITBRANCH)"
compile: parser.so version.lua
install: compile
mkdir -p $(DESTDIR)/usr/lib/lua/luci/template
cp parser.so $(DESTDIR)/usr/lib/lua/luci/template/parser.so
cp version.lua $(DESTDIR)/usr/lib/lua/luci/version.lua