Merge lp:~osomon/elisa/turkish into lp:elisa

Proposed by Olivier Tilloy
Status: Needs review
Proposed branch: lp:~osomon/elisa/turkish
Merge into: lp:elisa
Diff against target: 155 lines (+79/-6)
5 files modified
elisa-core/elisa/core/launcher.py (+6/-0)
elisa-core/elisa/core/tests/test_utils_text.py (+42/-0)
elisa-core/elisa/core/utils/text.py (+23/-1)
elisa-plugins/elisa/plugins/pigment/widgets/theme.py (+2/-1)
elisa-plugins/elisa/plugins/pigment/widgets/widget.py (+6/-4)
To merge this branch: bzr merge lp:~osomon/elisa/turkish
Reviewer Review Type Date Requested Status
Elisa Developers Pending
Review via email: mp+25900@code.launchpad.net

Description of the change

This branch fixes most of the issues encountered when running with a Turkish locale (and possibly other "exotic" locales), most notably bug #584161.

The problem is that the Turkish language (and hence the Turkish locale) has different capitalization
rules regarding "i" ("ı" <-> "I" and "i" <-> "İ").

The fix is twofold (two separate commits in the branch):

1) Work around a well-known bug in Python itself, by importing the decimal module before the locale is set.

2) Define and use two helpers to do locale-independent ASCII translations. Those new helpers are unit-tested.

To post a comment you must log in.

Unmerged revisions

1617. By Olivier Tilloy

Define and user two helpers to do ASCII upper/lower case conversions,
independently from the current locale.

1616. By Olivier Tilloy

Import decimal early, before locale.setlocale is called.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'elisa-core/elisa/core/launcher.py'
2--- elisa-core/elisa/core/launcher.py 2009-11-09 15:44:51 +0000
3+++ elisa-core/elisa/core/launcher.py 2010-05-24 15:25:45 +0000
4@@ -112,6 +112,12 @@
5 sys.path.extend(python_paths)
6
7 def main_before_voodoo(self):
8+ # Workaround python's broken handling of some locales (like Turkish):
9+ # importing the decimal module after locale.setlocale fails, so we
10+ # make sure it is imported earlier
11+ # (see https://bugs.launchpad.net/moovida/+bug/584161).
12+ import decimal
13+
14 import elisa
15 import elisa.core
16 import elisa.core.launcher
17
18=== added file 'elisa-core/elisa/core/tests/test_utils_text.py'
19--- elisa-core/elisa/core/tests/test_utils_text.py 1970-01-01 00:00:00 +0000
20+++ elisa-core/elisa/core/tests/test_utils_text.py 2010-05-24 15:25:45 +0000
21@@ -0,0 +1,42 @@
22+# Elisa Media Center
23+# Copyright (C) 2010 Olivier Tilloy <olivier@tilloy.net>
24+#
25+# This file is licensed under the GPL version 3.
26+#
27+# This program is free software: you can redistribute it and/or modify
28+# it under the terms of the GNU General Public License as published by
29+# the Free Software Foundation, either version 3 of the License, or
30+# (at your option) any later version.
31+#
32+# This program is distributed in the hope that it will be useful,
33+# but WITHOUT ANY WARRANTY; without even the implied warranty of
34+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35+# GNU General Public License for more details.
36+#
37+# You should have received a copy of the GNU General Public License
38+# along with this program. If not, see <http://www.gnu.org/licenses/>.
39+
40+import locale
41+
42+from twisted.trial.unittest import TestCase
43+from elisa.core.utils import text
44+
45+
46+class TestTextUtils(TestCase):
47+
48+ locales = ('', 'C', 'fr_FR.utf-8', 'tr_TR.utf-8', 'ar_SA.utf-8',
49+ 'zh_TW.utf-8')
50+
51+ lower = 'this is not a test!'
52+ upper = 'THIS IS NOT A TEST!'
53+
54+ def test_ascii_translations(self):
55+ for loc in self.locales:
56+ try:
57+ locale.setlocale(locale.LC_ALL, loc)
58+ except locale.Error:
59+ continue
60+ else:
61+ self.assertEquals(text.ascii_lower(self.upper), self.lower)
62+ self.assertEquals(text.ascii_upper(self.lower), self.upper)
63+
64
65=== modified file 'elisa-core/elisa/core/utils/text.py'
66--- elisa-core/elisa/core/utils/text.py 2009-05-11 14:06:59 +0000
67+++ elisa-core/elisa/core/utils/text.py 2010-05-24 15:25:45 +0000
68@@ -20,6 +20,13 @@
69 Text utilities.
70 """
71
72+import string
73+
74+
75+ASCII_LOWER = string.maketrans(string.ascii_uppercase, string.ascii_lowercase)
76+ASCII_UPPER = string.maketrans(string.ascii_lowercase, string.ascii_uppercase)
77+
78+
79 def name_to_shortcut(name):
80 """
81 DOCME
82@@ -29,4 +36,19 @@
83 if first.isalpha():
84 return first.upper()
85
86- return '#'
87\ No newline at end of file
88+ return '#'
89+
90+
91+def ascii_lower(s):
92+ """
93+ Translate an ASCII string to lower case in a locale-independent manner.
94+ """
95+ return s.translate(ASCII_LOWER)
96+
97+
98+def ascii_upper(s):
99+ """
100+ Translate an ASCII string to upper case in a locale-independent manner.
101+ """
102+ return s.translate(ASCII_UPPER)
103+
104
105=== modified file 'elisa-plugins/elisa/plugins/pigment/widgets/theme.py'
106--- elisa-plugins/elisa/plugins/pigment/widgets/theme.py 2009-06-09 07:43:31 +0000
107+++ elisa-plugins/elisa/plugins/pigment/widgets/theme.py 2010-05-24 15:25:45 +0000
108@@ -17,6 +17,7 @@
109 import gobject
110 from cPickle import dump, load, UnpicklingError
111 from elisa.core.utils import locale_helper
112+from elisa.core.utils.text import ascii_upper
113 from elisa.core import media_uri
114 from elisa.plugins.pigment.widgets import const
115 from elisa.plugins.pigment.widgets.style import Style
116@@ -381,7 +382,7 @@
117
118 if ':' in rule.selectorText:
119 widget, state = map(str, rule.selectorText.split(':'))
120- state = getattr(const, state.upper())
121+ state = getattr(const, ascii_upper(str(state)))
122 else:
123 widget, state = str(rule.selectorText), None
124
125
126=== modified file 'elisa-plugins/elisa/plugins/pigment/widgets/widget.py'
127--- elisa-plugins/elisa/plugins/pigment/widgets/widget.py 2009-11-17 22:44:25 +0000
128+++ elisa-plugins/elisa/plugins/pigment/widgets/widget.py 2010-05-24 15:25:45 +0000
129@@ -16,6 +16,7 @@
130
131 from elisa.core import log
132 from elisa.core.input_event import EventValue
133+from elisa.core.utils.text import ascii_upper
134
135 import elisa.plugins.pigment.graph
136 from elisa.plugins.pigment.graph.group import Group
137@@ -388,14 +389,15 @@
138
139 module = 'elisa.plugins.pigment.graph'
140 if isinstance(widget, Image) and attribute in image_properties:
141- value = '%s.IMAGE_%s' % (module, value.upper())
142+ value = '%s.IMAGE_%s' % (module, ascii_upper(str(value)))
143 elif isinstance(widget, Text) and attribute in text_properties:
144 if attribute == 'alignment':
145- value = '%s.TEXT_ALIGN_%s' % (module, value.upper())
146+ value = '%s.TEXT_ALIGN_%s' % (module, ascii_upper(str(value)))
147 elif attribute == 'shadow_position':
148- value = '%s.TEXT_%s' % (module, value.upper())
149+ value = '%s.TEXT_%s' % (module, ascii_upper(str(value)))
150 else:
151- value = '%s.TEXT_%s_%s' % (module, attribute.upper(), value.upper())
152+ value = '%s.TEXT_%s_%s' % (module, ascii_upper(str(attribute)),
153+ ascii_upper(str(value)))
154 else:
155 return value
156

Subscribers

People subscribed via source and target branches