ubuntu-accomplishments-contributors team mailing list archive
-
ubuntu-accomplishments-contributors team
-
Mailing list archive
-
Message #00130
Re: Internationalization and localization of the web editor
On 04/04/12 00:59, Jono Bacon wrote:
> On 3 April 2012 14:41, Bruno Girin <brunogirin@xxxxxxxxx> wrote:
>> On 03/04/12 06:53, Janos Gyerik wrote:
>>>> * Is there a way in Python in which we can detect which ISO code is
>>>> the default language for the user's machine?
>>> Maybe the LANG env variable? For the web editor, browsers have
>>> preferred language setting and accepted languages setting, don't
>>> remember the names but I'm sure we can easily find it when we get
>>> there.
>> locale.getdefaultlocale()
>> http://docs.python.org/library/locale.html
> Perfect, thanks!
>
>>> So the 2-letter won't cut it, because as Bruno pointed out Asturian
>>> doesn't have one, and we also need country variants like en_gb. So
>>> maybe 3-letter code + country variant, like:
>>> eng_gb
>>> eng_us
>>> hun_hu
>>> ast_es
>>> ?
>> Well, the problem is that the system locale will use the 2 letter code
>> if it can and mapping from 2 letter to 3 letter code is not always
>> straightforward. So the simplest way to deal with it would probably be
>> to use the first item of the tuple returned by locale.getdefaultlocale.
>> It doesn't matter if some codes are 2 letters and others are 3 letters.
>>
>> Another thing we should probably support is the concept of fallback,
>> i.e. to be able to fallback to the base language locale if the variant
>> is not found. So, for example, if the locale is en_au, check for en_au
>> first and if not found check for en. Otherwise, you will have to work
>> out all the country variants every time you add a new language, which
>> can be rather messy (think Spanish or English!)
>>
>> Applying those two principles, you could have something like this:
>>
>> en
>> en_gb
>> es
>> es_mx
>> ast
>>
>> This makes the code a wee bit more complicated but it saves a massive
>> amount of maintenance in the long term! And it would make the web editor
>> and python code consistent.
> Agreed. So I am thinking in the accomplishment set it I will create an
> 'en' sub-folder and this can be the default sub-folder. As an example,
> if I have en_US installed but there is no en_US sub-folder, it will
> then load 'en' instead. We could do this by checking if in en_US if
> there is a _US and if not we just default to the 'en' sub-folder.
>
> I can even do this at an accomplishment level. As an example if en_US
> has all the accomplishments other than first-bug.accomplishment, we
> can load first-bug.accomplishment from the fall-back of 'en'.
Indeed. The simplest way is to break down the locale string into a list
of sub-strings using underscores or dashes as separators. Then each time
you look for a given resource (or accomplishment in this case), start
with the full locale and if you don't find the resource for that locale,
drop the last element and repeat until you get to a locale composed of a
single sub-string. That way, you can easily support nth level variant.
What is also useful to do is to transform everything to lower-case to
make sure it's case insensitive.
Cheers,
Bruno
References