------------------------------------------------------------------------ r11776 | jomae | 2013-04-10 15:12:49 +0200 (Wed, 10 Apr 2013) | 4 lines 1.0.2dev: search locale with territory in preferred languages for "first week day" before using `babel.core.LOCALE_ALIASES` A part of #10757. Index: trac/util/datefmt.py =================================================================== --- trac/util/datefmt.py (revision 11775) +++ trac/util/datefmt.py (revision 11776) @@ -32,7 +32,7 @@ return [] else: from babel import Locale - from babel.core import LOCALE_ALIASES + from babel.core import LOCALE_ALIASES, UnknownLocaleError from babel.dates import ( format_datetime as babel_format_datetime, format_date as babel_format_date, @@ -373,6 +373,19 @@ if locale == 'iso8601': return 1 # Monday if babel and locale: + if not locale.territory: + # search first locale which has the same `langauge` and territory + # in preferred languages + for l in req.languages: + l = l.replace('-', '_').lower() + if l.startswith(locale.language.lower() + '_'): + try: + l = Locale.parse(l) + if l.territory: + locale = l + break + except UnknownLocaleError: + pass if not locale.territory and locale.language in LOCALE_ALIASES: locale = Locale.parse(LOCALE_ALIASES[locale.language]) return (locale.first_week_day + 1) % 7 ------------------------------------------------------------------------