#8117 closed enhancement (fixed)
Default language setting in trac.ini
Reported by: | Owned by: | Christian Boos | |
---|---|---|---|
Priority: | low | Milestone: | 0.12.1 |
Component: | web frontend | Version: | 0.12dev |
Severity: | normal | Keywords: | i18n language settings review |
Cc: | alexey.rudy@…, nzoltan | Branch: | |
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
I haven't found the way to enforce default language. Now language selection based on Accept-Language
header from browser, but sometimes that's not convinient.
I suggest to add extra setting to trac.ini:
[trac] lang = ru
This setting will have higher priority than headers data. Patch is attached: patch_from_r7937.diff
Attachments (5)
Change History (25)
by , 16 years ago
Attachment: | patch_from_r7937.diff added |
---|
follow-up: 2 comment:1 by , 16 years ago
Any reason why you can't simply select the language you want from the users preferences? That will also take precedence over the Accept-Language headers.
comment:2 by , 16 years ago
Replying to cboos:
Any reason why you can't simply select the language you want from the users preferences? That will also take precedence over the Accept-Language headers.
Yes, I can :) But I want all other users to see the site in particular language by default. They are just users and they don't need to do extra actions.
For example - when I do public wiki in Russian not for hardcore programmers :) That looks strange when site content is in Russian and the interface is in English. And I need to explain everyone that they need to change their language in preferences. It's better to switch always to Russian in such case.
My first suggested implementation is wrong - the setting in trac.ini will override session settings too. It would be right to override only browser headres data. Sorry :))
by , 16 years ago
Attachment: | patch_from_r7937.2.diff added |
---|
patch for setting defaulf language in trac.ini, version 2
comment:3 by , 15 years ago
Priority: | normal → low |
---|
Ok, but the change should be rewritten so that the lookup in config could be done only if there's nothing stored in the session.
comment:5 by , 14 years ago
Cc: | added |
---|
I also would like to see this feature, this would be very useful.
comment:6 by , 14 years ago
Milestone: | 0.12.1 → 0.13 |
---|---|
Owner: | set to |
Status: | new → assigned |
No new enhancements for 0.12.x. This one shouldn't be hard to get in shape for trunk (comment:3), so moving to 0.13 directly.
follow-up: 9 comment:7 by , 14 years ago
Milestone: | 0.13 → 0.12.1 |
---|
I'd like to make an exception for this feature, and get it in 0.12.1 nevertheless.
Updated patch follows.
by , 14 years ago
Attachment: | patch_from_r7937.2.2.diff added |
---|
comment:8 by , 14 years ago
Keywords: | i18n added |
---|
follow-up: 10 comment:9 by , 14 years ago
Replying to cboos:
I'd like to make an exception for this feature, and get it in 0.12.1 nevertheless.
He he, changed your mind? :)
Any chance of using the same setting to set the language used by trac-admin
? Currently, with my custom locale en_CH
, trac-admin
outputs text in German for some mysterious reason, even though German is mentioned nowhere in the locale. Begin able to set it to "en" and having trac-admin
talk to me in English would be awesome.
comment:10 by , 14 years ago
Replying to rblank:
Replying to cboos:
I'd like to make an exception for this feature, and get it in 0.12.1 nevertheless.
He he, changed your mind? :)
Personal reason ;-) But I'd really like that it remains an exception…
Any chance of using the same setting to set the language used by
trac-admin
? Currently, with my custom localeen_CH
,trac-admin
outputs text in German for some mysterious reason, even though German is mentioned nowhere in the locale.
That's because of Babel, the following:
>>> import babel >>> babel.Locale.default()
must give you 'de'.
Being able to set it to "en" and having
trac-admin
talk to me in English would be awesome.
Yup, see 8117-trac-admin-default_language.patch.
by , 14 years ago
Attachment: | 8117-trac-default_language.patch added |
---|
reworked patch_from_r7937.2.2.diff in order to properly support values with undescores (e.g. 'zh_CN')
by , 14 years ago
Attachment: | 8117-trac-admin-default_language.patch added |
---|
trac-admin uses the default_language configured for the environment, if any; patch on top of 8117-trac-default_language.patch
comment:12 by , 14 years ago
Replying to cboos:
Ok to apply?
Haven't actually tried the patches, but they read well… I'd like to see this committed.
comment:13 by , 14 years ago
Replying to cboos:
Ok to apply?
I haven't had a chance to test it yet either, but it reads well here, too. So yes, please go ahead.
comment:14 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Reworked patches applied in [10052:10053], should work as expected, but testing always welcome.
follow-up: 16 comment:15 by , 14 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Well, when documenting the feature, r10053 feels a bit wrong, as we don't have a way to enforce a user preference anymore (e.g. LANG=en trac-admin ...
or LANG=fr trac-admin ...
).
Curiously, the above didn't work either before r10053, and this is because the precedence order in babel.Locale.default()
is 'LANGUAGE', 'LC_ALL', 'LC_CTYPE', 'LANG'
([Babel:source:tags/0.9.5/babel/core.py@#L630 babel.core]).
This is somehow in accordance with http://www.gnu.org/software/gettext/manual/gettext.html#Users, however that documentation also refers to LANG
as the normal environment variable for specifying a locale.
Babel has anyway other problems with the default
, as it expects things like fr_FR
and won't work with a simple LANG=fr
.
Therefore I'd propose the following addition:
-
trac/admin/console.py
168 168 self.__env = env = Environment(self.envname) 169 169 # fixup language according to env settings 170 170 if has_babel: 171 preferred = env.config.get('trac', 'default_language', '') 172 if preferred: 173 translation.activate(get_negotiated_locale([preferred])) 171 lang = os.environ.get('LANG') 172 default = env.config.get('trac', 'default_language', '') 173 negotiated = get_negotiated_locale([lang, default]) 174 if negotiated: 175 translation.activate(negotiated) 174 176 175 177 ## 176 178 ## Utility methods
follow-up: 17 comment:16 by , 14 years ago
Replying to cboos:
Therefore I'd propose the following addition:
There's still a little glitch here, as the locale is only set when opening the environment. However, the welcome banner is already printed at that point, so I get a banner in German and the rest in English. Of course, we cannot get the value of [trac] default_language
before opening the environment, but we can at least use LANG
.
How about the following addition:
-
trac/admin/console.py
diff --git a/trac/admin/console.py b/trac/admin/console.py
a b 524 526 if has_babel: 525 527 import babel 526 528 try: 527 locale = babel.Locale.default() 529 locale = get_negotiated_locale([os.environ.get('LANG')]) \ 530 or babel.Locale.default() 528 531 except babel.UnknownLocaleError: 529 532 pass 530 533 translation.activate(locale)
comment:17 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
comment:18 by , 8 years ago
In r10052, was it intended to have get_negotiate_locale
have a different signature when Babel is present as compared to the non-Babel fallback?
This change would make the signatures the same:
-
trac/util/translation.py
diff --git a/trac/util/translation.py b/trac/util/translation.py index bb49e259a..0574333f7 100644
a b except ImportError: # fall back on 0.11 behavior, i18n functions are no-ops 402 402 def get_available_locales(): 403 403 return [] 404 404 405 def get_negotiated_locale(preferred =None, default=None):405 def get_negotiated_locale(preferred_locales): 406 406 return None
patch for setting defaulf language in trac.ini