l10ns
l10ns copied to clipboard
Add a way to list all requirable languages
Hi tinganho,
I use l10ns for a mobile app translated in five languages. I have to find the available language closest to the one of the phone. For now, I just compare the two first letters, falling back to en-US by default.
In order to do so, I would find very useful if we had a way to list all supported languages (the five ones for my case). I proposed this #144 to do that, and here is the issue you requested.
You should notice that I put the function listLanguages
beside requireLocalizations
which give us a getter, not a localized string.
On an API design side, I am not completely satisfied, but it could open the way to more utilitaries functions. If I had a configuration file to parse that would contains the available languages, I would not need this feature.
Still this is more suitable for an external library. It shouldn't be part of L10ns. I think there should be some library that does some language acceptance for your platform right now.
Ok, there is something I probably missed, so let me summarize:
I have my codebase using the getter l('SOME_KEY')
.
Then I perform l10ns update
to add all new keys.
With l10ns set ref -l lang value
, I match value
with the key for the given lang
.
Finally, l10ns compile
create all.js
(and all lang.js
).
All these operations are performed by multiple team members at different time and the result is stored on a git repository. This result is evolving all the time, so I have to decide at execution what is the best option on a given context (the phone language in that case).
The information I need is store on two locations:
- In the name of all
lang.js
files - In the code of
all.js
So I only see two options to do what I want:
- List all the
lang.js
files (unfeasible on browser) - Add a function in
all.js
aware of the l10ns configuration
Maybe a third possibility where I get all.js
in a string format and parse it, but this seems to be a little bit painful.
I don't really understand how an external library could help me on this.
Pardon me for insisting but I hate not understanding.
The way I do it is to duplicate all languages I have written in l10ns.json
on to some source files. Though it requires duplicate work.
It might make sense to compile it directly on the output file. I think I need some time to reflect on this first.