Merge lp:~jr/bzr/i18n-enable-translations-everywhere into lp:bzr

Proposed by Jonathan Riddell on 2011-09-12
Status: Merged
Approved by: Jelmer Vernooij on 2011-09-13
Approved revision: 6135
Merged at revision: 6136
Proposed branch: lp:~jr/bzr/i18n-enable-translations-everywhere
Merge into: lp:bzr
Diff against target: 68 lines (+17/-5)
3 files modified
bzrlib/i18n.py (+9/-0)
bzrlib/tests/test_i18n.py (+5/-0)
doc/en/release-notes/bzr-2.5.txt (+3/-5)
To merge this branch: bzr merge lp:~jr/bzr/i18n-enable-translations-everywhere
Reviewer Review Type Date Requested Status
Jelmer Vernooij (community) 2011-09-12 Approve on 2011-09-13
Review via email: mp+75040@code.launchpad.net

Commit message

enable translations globally

Description of the change

Let's just go for this i18n thing

To post a comment you must log in.
Jelmer Vernooij (jelmer) wrote :

Yeah, let's do it.

Rather than installing gettext every time we call out to have something translated, wouldn't it make more sense to call .install from the bzr binary or bzrlib.initialize? That way external users also can control whether or not they would like internationalization.

review: Needs Information (code)
Jonathan Riddell (jr) wrote :

Thanks for your support :)

This doesn't install gettext every time because install() returns immediately if it is already installed(). I think running install() within i18n.gettext() is preferable because it only does the gettext setup if it is needed, some commands won't need it so that would be a waste of process time.

Running "time bzr status" on an empty directly with gettext installed every times takes the real execution time from typically slightly below 0.1s to slightly above 0.1s so I think it's worth avoiding if possible.

6133. By Jonathan Riddell on 2011-09-13

add disableI18n() function so bzrlib users can chose not to use i18n

6134. By Jonathan Riddell on 2011-09-13

rename to disable_i18n() to follow convention

6135. By Jonathan Riddell on 2011-09-13

add test for i18n.disable_i18n()

Jelmer Vernooij (jelmer) :
review: Approve
Jelmer Vernooij (jelmer) wrote :

I think generally we try to keep the first line of the docstring a single sentence that describes what it does.

Can you perhaps add two newlines before "Useful for ..." ?

6136. By Jonathan Riddell on 2011-09-13

update release note

Jonathan Riddell (jr) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/i18n.py'
2--- bzrlib/i18n.py 2011-09-07 14:01:16 +0000
3+++ bzrlib/i18n.py 2011-09-13 15:52:33 +0000
4@@ -34,6 +34,7 @@
5
6 :returns: translated message as unicode.
7 """
8+ install()
9 return _translations.ugettext(message)
10
11
12@@ -46,6 +47,7 @@
13
14 :returns: translated message as unicode.
15 """
16+ install()
17 return _translations.ungettext(singular, plural, number)
18
19
20@@ -66,6 +68,13 @@
21 return u'\n\n'.join(ugettext(p) if p else u'' for p in paragraphs)
22
23
24+def disable_i18n():
25+ """Do not allow i18n to be enabled. Useful for third party users
26+ of bzrlib."""
27+ global installed
28+ installed = lambda: True
29+
30+
31 def installed():
32 return not isinstance(_translations, _gettext.NullTranslations)
33
34
35=== modified file 'bzrlib/tests/test_i18n.py'
36--- bzrlib/tests/test_i18n.py 2011-09-07 16:32:11 +0000
37+++ bzrlib/tests/test_i18n.py 2011-09-13 15:52:33 +0000
38@@ -109,6 +109,11 @@
39 self.overrideEnv('LANG', None)
40 i18n.install()
41
42+ def test_disable_i18n(self):
43+ i18n.disable_i18n()
44+ i18n.install()
45+ self.assertTrue(isinstance(i18n._translations, i18n._gettext.NullTranslations))
46+
47 class TestTranslate(tests.TestCaseWithTransport):
48
49 def setUp(self):
50
51=== modified file 'doc/en/release-notes/bzr-2.5.txt'
52--- doc/en/release-notes/bzr-2.5.txt 2011-09-12 18:40:02 +0000
53+++ doc/en/release-notes/bzr-2.5.txt 2011-09-13 15:52:33 +0000
54@@ -93,11 +93,9 @@
55 option. A value of 0 disables skipping. Named items passed to add are
56 never skipped. (Shannon Weyrick, #54624)
57
58-* bzr now ships with translations for command help. (Jonathan
59- Riddell, INADA Naoki, #83941)
60-
61-* bzr now ships with translations for command errors. (Jonathan
62- Riddell, INADA Naoki)
63+* Translations are now enabled for command help, errors and globally
64+ for any message using gettext given on output. (Jonathan Riddell,
65+ INADA Naoki, #83941)
66
67 Improvements
68 ************