Merge lp:~mterry/ubiquity/sort-lang into lp:ubiquity

Proposed by Michael Terry
Status: Merged
Merge reported by: Michael Terry
Merged at revision: not available
Proposed branch: lp:~mterry/ubiquity/sort-lang
Merge into: lp:ubiquity
Diff against target: None lines
To merge this branch: bzr merge lp:~mterry/ubiquity/sort-lang
Reviewer Review Type Date Requested Status
Ubuntu Installer Team Pending
Review via email: mp+8901@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Michael Terry (mterry) wrote :

Sort language list according to 'C' locale if pyicu is available. Colin and I chatted about this on IRC, and we figured that although this isn't going to be right for any given language, it's the best we can do, since we don't know the user's language yet!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2009-07-16 13:18:57 +0000
3+++ debian/changelog 2009-07-16 17:39:38 +0000
4@@ -8,7 +8,10 @@
5 [ Evan Dandrea ]
6 * Add support for ubiquity-slideshow.
7
8- -- Colin Watson <cjwatson@ubuntu.com> Wed, 15 Jul 2009 15:37:49 +0100
9+ [ Michael Terry ]
10+ * Sort language list with pyicu, if available
11+
12+ -- Michael Terry <michael.terry@canonical.com> Thu, 16 Jul 2009 13:03:32 -0400
13
14 ubiquity (1.99.0) karmic; urgency=low
15
16
17=== modified file 'debian/control'
18--- debian/control 2009-07-15 14:06:31 +0000
19+++ debian/control 2009-07-16 17:39:38 +0000
20@@ -12,6 +12,7 @@
21 Architecture: any
22 Depends: ${shlibs:Depends}, ${misc:Depends}, ${python:Depends}, debconf (>= 1.4.72ubuntu5), ubiquity-frontend-${mangled-version}, ubiquity-artwork-${mangled-version}, laptop-detect, lsb-release, ubiquity-casper, python-apt (>= 0.6.16.2ubuntu4), ${console-setup-depends}, iso-codes, passwd, adduser, os-prober, rdate, ${partman-depends}, ecryptfs-utils
23 Recommends: ${bootloader-recommends}
24+Suggests: python-pyicu
25 Conflicts: ubuntu-express, espresso, espresso-utils, espresso-locale, espresso-keyboard-setup, espresso-kbd-chooser, espresso-timezone, user-setup (<< 0.05ubuntu6), partman, espresso-grub, espresso-yaboot
26 Replaces: ubuntu-express, espresso, espresso-utils, espresso-locale, espresso-keyboard-setup, espresso-kbd-chooser, espresso-timezone, user-setup (<< 0.05ubuntu6), partman, espresso-grub, espresso-yaboot, ubiquity-frontend-gtk (<< 0.99.82)
27 XB-Python-Version: ${python:Versions}
28
29=== modified file 'ubiquity/components/language.py'
30--- ubiquity/components/language.py 2009-06-24 13:57:01 +0000
31+++ ubiquity/components/language.py 2009-07-16 17:39:38 +0000
32@@ -26,6 +26,11 @@
33 from ubiquity import im_switch
34 from ubiquity import misc
35
36+try:
37+ import PyICU
38+except:
39+ PyICU = None
40+
41 class Language(FilteredCommand):
42 def prepare(self, unfiltered=False):
43 self.language_question = None
44@@ -71,14 +76,29 @@
45 i += 1
46 languagelist.close()
47
48- def compare_choice(x, y):
49- result = cmp(language_display_map[x][1],
50- language_display_map[y][1])
51- if result != 0:
52- return result
53- return cmp(x, y)
54-
55- sorted_choices = sorted(language_display_map, compare_choice)
56+ try:
57+ # Note that we always collate with the 'C' locale. This is far
58+ # from ideal. But proper collation always requires a specific
59+ # language for its collation rules (languages frequently have
60+ # custom sorting). This at least gives us common sorting rules,
61+ # like stripping accents.
62+ collator = PyICU and PyICU.Collator.createInstance(PyICU.Locale('C'))
63+ except:
64+ collator = None
65+
66+ def compare_choice(x):
67+ if language_display_map[x][1] == 'C':
68+ return None # place C first
69+ if collator:
70+ try:
71+ return collator.getCollationKey(x).getByteArray()
72+ except:
73+ pass
74+ # Else sort by unicode code point, which isn't ideal either,
75+ # but also has the virtue of sorting like-glyphs together
76+ return x
77+
78+ sorted_choices = sorted(language_display_map, key=compare_choice)
79 self.frontend.set_language_choices(sorted_choices,
80 language_display_map)
81 self.frontend.set_language(current_language)

Subscribers

People subscribed via source and target branches

to status/vote changes: