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
=== modified file 'bzrlib/i18n.py'
--- bzrlib/i18n.py 2011-09-07 14:01:16 +0000
+++ bzrlib/i18n.py 2011-09-13 15:52:33 +0000
@@ -34,6 +34,7 @@
34 34
35 :returns: translated message as unicode.35 :returns: translated message as unicode.
36 """36 """
37 install()
37 return _translations.ugettext(message)38 return _translations.ugettext(message)
3839
3940
@@ -46,6 +47,7 @@
4647
47 :returns: translated message as unicode.48 :returns: translated message as unicode.
48 """49 """
50 install()
49 return _translations.ungettext(singular, plural, number)51 return _translations.ungettext(singular, plural, number)
5052
5153
@@ -66,6 +68,13 @@
66 return u'\n\n'.join(ugettext(p) if p else u'' for p in paragraphs)68 return u'\n\n'.join(ugettext(p) if p else u'' for p in paragraphs)
6769
6870
71def disable_i18n():
72 """Do not allow i18n to be enabled. Useful for third party users
73 of bzrlib."""
74 global installed
75 installed = lambda: True
76
77
69def installed():78def installed():
70 return not isinstance(_translations, _gettext.NullTranslations)79 return not isinstance(_translations, _gettext.NullTranslations)
7180
7281
=== modified file 'bzrlib/tests/test_i18n.py'
--- bzrlib/tests/test_i18n.py 2011-09-07 16:32:11 +0000
+++ bzrlib/tests/test_i18n.py 2011-09-13 15:52:33 +0000
@@ -109,6 +109,11 @@
109 self.overrideEnv('LANG', None)109 self.overrideEnv('LANG', None)
110 i18n.install()110 i18n.install()
111111
112 def test_disable_i18n(self):
113 i18n.disable_i18n()
114 i18n.install()
115 self.assertTrue(isinstance(i18n._translations, i18n._gettext.NullTranslations))
116
112class TestTranslate(tests.TestCaseWithTransport):117class TestTranslate(tests.TestCaseWithTransport):
113118
114 def setUp(self):119 def setUp(self):
115120
=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- doc/en/release-notes/bzr-2.5.txt 2011-09-12 18:40:02 +0000
+++ doc/en/release-notes/bzr-2.5.txt 2011-09-13 15:52:33 +0000
@@ -93,11 +93,9 @@
93 option. A value of 0 disables skipping. Named items passed to add are93 option. A value of 0 disables skipping. Named items passed to add are
94 never skipped. (Shannon Weyrick, #54624)94 never skipped. (Shannon Weyrick, #54624)
9595
96* bzr now ships with translations for command help. (Jonathan96* Translations are now enabled for command help, errors and globally
97 Riddell, INADA Naoki, #83941)97 for any message using gettext given on output. (Jonathan Riddell,
9898 INADA Naoki, #83941)
99* bzr now ships with translations for command errors. (Jonathan
100 Riddell, INADA Naoki)
10199
102Improvements100Improvements
103************101************