danwent / Perspectives

Perspectives Firefox Extension
http://perspectives-project.org
66 stars 19 forks source link

Change localization system #146

Closed ghost closed 8 years ago

ghost commented 10 years ago

(Original discussion here: https://github.com/lambdor/Perspectives/commit/885b6e74efd008baebb87a165b9a0427248cb26e#commitcomment-7989663 )

Btw I think the current localization approach is rather clumsy and error prone with all those if( strbundle == null) { strbundle = document.getElementById }. How about we just make a big key/value-pair object for each localization and load the right one somewhere at the beginning. It's not as if we would deal with megabytes of data. This would also allow for auto-completions in the IDE. What do you think?

As for changing the localization system - yes that sounds great! I would be interested to know how other extensions do it - I'll try to find time to research.

I did some research for one of our projects at work that uses over 3000 strings. There are some sophisticated libraries out there which handle things like formatting of numbers and plural forms of words (some language even have multiple plural forms). Eventually we decided to create one big .csv file for the translators, convert the .csv to .json files for each language and just import the corresponding language file. Missing strings are filled in from the english translation and we simply access the strings via lc.my_string. It works very well so far with just one or two hacks. Perspectives uses far less strings and no number formatting so I think we should be fine with a plain JSON object too. Or just leave it as is :)

Changing the localization loads sounds fine if you want to do that, but let's leave it for a future pull request ;) Feel free to create a ticket.

daveschaefer commented 8 years ago

I refactored the localization system so we now store all strings in a single .properties file, load it on demand, and did away with all of the null checks. Any caller can now just use getString() to retrieve any string. This sounds more in line with what you describe here.

Shout if you had other thoughts that we are still missing.