Hello everybody,
I'm progressing, slowly but surely,
on this Lua internationalization project. So far, on the relexicalisation
branch, I implemented the load of a file containing
Esperanto alias definitions like `se = 'if'`. This is really a
prototype, as
- the file name is hardcoded,
- it uses a global variables to
pass the alias array and its length around
- the file is read with a loosy fscanf
"parsing"
But still, it works, the file is
loaded at runtime, and the defined aliases for reserved keywords
are well alliased.
Now the next steps are
- load the file as a lua
interpreted code
- expose a runtime function which
enable to load the table
My initial idea was that the Lua
script containing the aliases should return a key/value table,
and that the exposed function would take a path to such a file.
On the other hand, the code could simply look for some variable
like `__i18n.reserved_keyword_aliases` in the current
environement. Users might then affect it with table defined in
their code or loaded as any other Lua code.
Feedback would be welcome on this.
Also I plane to let users load
several alias tables. To avoid ambiguity, their should be
precedence mechanism. One way to do it would be to make `__i18n.reserved_keyword_aliases` itself
an array, that is:
__i18n.reserved_keyword_aliases[0]["si"] = " if" --
conjunction used to introduce a condition or choice in some
languages
si true then print('si!') end -- print 'si!'
__i18n.reserved_keyword_aliases[1]["si"] = " :" --
reflexive pronoun in some languages
si true then print('si!') end -- print 'si!' -- error, "si"
now return ":", as the previous affectation have a greater
precedence
a.e=function(i) print(i) end; a si e() -- print something
like table: 0x556800b889d0
__i18n.reserved_keyword_aliases[1]["si"] = nil -- forget that,
now "si" will alias "if" again
-- Also a table grouping aliases by language code could an
other way to group that, with a special key for precedence
__i18n.reserved_keyword_aliases["zh"]["if"] = "如果"
__i18n.reserved_keyword_aliases["zh"]["precedence"] = 0
But that would create ability to introduce equal precedence
groups.
Any feedback is welcome.
Le 29/11/2016 à 14:12, mathieu stumpf guntz a écrit :
Great, thank you. That also
should able to ease the internationalization by making direct
locale numbers some syntactic sugar for their quoted
counterpart. Does this functionality also take into account
things like Indian
and Eastern Arabic
numerals?
Le 29/11/2016 à 12:45, Luiz Henrique
de Figueiredo a écrit :
You need to set the locale inside Lua:
% lua
Lua 5.3.3 Copyright (C) 1994-2016 Lua.org, PUC-Rio
> os.setlocale"fr_FR"
fr_FR
> "3,14" + 1
4,14
os.setlocale("") is a better solution because it reads the locale from
the environment:
env LC_NUMERIC="fr_FR.UTF-8" lua
Lua 5.3.3 Copyright (C) 1994-2016 Lua.org, PUC-Rio
> os.setlocale("")
en_US.ISO8859-1/en_US.ISO8859-1/en_US.ISO8859-1/fr_FR.UTF-8/en_US.ISO8859-1/en_US.ISO8859-1
> "3,14" + 1
4,14