Ticket #8117 (closed enhancement: fixed)
Opened 3 years ago
Last modified 17 months ago
Default language setting in trac.ini
| Reported by: | alexey.rudy@… | Owned by: | cboos |
|---|---|---|---|
| Priority: | low | Milestone: | 0.12.1 |
| Component: | web frontend | Version: | 0.12dev |
| Severity: | normal | Keywords: | i18n language settings review |
| Cc: | alexey.rudy@…, nzoltan | ||
| Release Notes: | |||
| API 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
Change History
Changed 3 years ago by alexey.rudy@…
- Attachment patch_from_r7937.diff added
comment:1 follow-up: ↓ 2 Changed 3 years ago by 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.
comment:2 in reply to: ↑ 1 Changed 3 years ago by alexey.rudy@…
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 :))
Changed 3 years ago by alexey.rudy@…
- Attachment patch_from_r7937.2.diff added
patch for setting defaulf language in trac.ini, version 2
comment:3 Changed 2 years ago by cboos
- Priority changed from normal to 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 Changed 20 months ago by nzoltan
- Cc nzoltan added
I also would like to see this feature, this would be very useful.
comment:6 Changed 20 months ago by cboos
- Milestone changed from 0.12.1 to 0.13
- Owner set to cboos
- Status changed from new to 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.
comment:7 follow-up: ↓ 9 Changed 17 months ago by cboos
- Milestone changed from 0.13 to 0.12.1
I'd like to make an exception for this feature, and get it in 0.12.1 nevertheless.
Updated patch follows.
Changed 17 months ago by cboos
- Attachment patch_from_r7937.2.2.diff added
comment:8 Changed 17 months ago by cboos
- Keywords i18n added
comment:9 in reply to: ↑ 7 ; follow-up: ↓ 10 Changed 17 months ago by 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? :)
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 in reply to: ↑ 9 Changed 17 months ago by cboos
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 locale en_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.
Changed 17 months ago by cboos
- 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')
Changed 17 months ago by cboos
- 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 in reply to: ↑ 11 Changed 17 months ago by osimons
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 in reply to: ↑ 11 Changed 17 months ago by rblank
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 Changed 17 months ago by cboos
- Resolution set to fixed
- Status changed from assigned to closed
Reworked patches applied in [10052:10053], should work as expected, but testing always welcome.
comment:15 follow-up: ↓ 16 Changed 17 months ago by cboos
- Resolution fixed deleted
- Status changed from closed to 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.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
comment:16 in reply to: ↑ 15 ; follow-up: ↓ 17 Changed 17 months ago by rblank
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 in reply to: ↑ 16 Changed 17 months ago by cboos
- Resolution set to fixed
- Status changed from reopened to closed



patch for setting defaulf language in trac.ini