2007/6/25, Jeroen Ruigrok van der Werven <[EMAIL PROTECTED]>:
> sv_SE *is* available as an option for Microsoft Internet Explorer 7. It also
> supports sv_FI. So which is right? Firefox? Opera? Internet Explorer? As far
> as I have been able to determine this is a bit of a shady area of webbrowsers
> and servers. The best way forward, in my opinion, is to keep the current
> language_TERRITORY scheme and provide an internal mapping table in Babel to
> map short-hand Accept-Language specifiers to the appropriate dominant locale,
> a bit like Horde currently does.
>
> If you are aware of any documentation or specification that's very explicit
> about these issues, please feel free to point it out. But I think the above
> makes quite a lot of sentence and should address all points. Can you agree?
I'm also be bothered by this issue. Firefox provides only 'ja' but trac i18n
only accepts ja_JP. I think it's strange and babel should fallback to accept
'ja' as 'ja_JP'.
It is good to provide locale data of ja_JP because it is explicit and has
detailed data.
But the country code of locale can be ommitted on requesting via Accept-Langage.
I'm using a patch for babel.core.negotiate_locale() localy to accept 'ja'.
{{{
Index: core.py
===================================================================
--- core.py (revision 173)
+++ core.py (working copy)
@@ -559,6 +560,8 @@
'de_DE'
>>> negotiate_locale(['de_DE', 'en_US'], ['en', 'de'])
'de'
+ >>> negotiate_locale(['de', 'en_US'], ['en', 'de_DE'])
+ 'de_DE'
Case is ignored by the algorithm, the result uses the case of the preferred
locale identifier:
@@ -574,13 +577,34 @@
was found
:rtype: `str`
"""
+ langmap = {}
+ for tag in [a.lower() for a in available if a]:
+ lang = tag.lower()
+ parts = lang.split(sep)
+ if 1 < len(parts):
+ lang = parts[0]
+ if lang in langmap:
+ langmap[lang].append(tag)
+ else:
+ langmap[lang] = [tag]
available = [a.lower() for a in available if a]
- for locale in preferred:
- if locale.lower() in available:
- return locale
- parts = locale.split(sep)
- if len(parts) > 1 and parts[0].lower() in available:
- return parts[0]
+ for tag in preferred:
+ # case of exact match
+ if tag.lower() in available:
+ return tag
+ # extract language code
+ parts = tag.lower().split(sep)
+ if len(parts) > 1:
+ lang = parts[0]
+ else:
+ lang = tag
+ # case of preferred='ja', availables has 'ja_JP' (or more),
+ lang = lang.lower()
+ if lang in langmap and len(langmap[lang]) == 1:
+ return langmap[lang][0]
+ # case of prefered='ja_JP', availables has 'ja'
+ if lang in available:
+ return lang
return None
def parse_locale(identifier, sep='_'):
}}}
--
Shun-ichi GOTO
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac
Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/trac-dev?hl=en
-~----------~----~----~----~------~----~------~--~---