1
Description: Help files for dealing with language settings.
2
Author: Gunnar Hjalmarsson <ubuntu@gunnar.cc>
4
--- accountsservice.orig/configure.ac 2011-07-19 21:48:12 +0200
5
+++ accountsservice/configure.ac 2011-08-10 15:08:50 +0200
10
+data/langtools/Makefile
12
src/libaccountsservice/Makefile
13
src/libaccountsservice/accountsservice.pc
15
--- accountsservice.orig/data/langtools/language2locale 1970-01-01 01:00:00 +0100
16
+++ accountsservice/data/langtools/language2locale 2011-07-25 17:48:30 +0200
20
+# - takes the first choice language in the LANGUAGE priority list as argument
21
+# - outputs locale name corresponding to that language
26
+test -n "$lang" || exit 0
28
+langtoolsdir=/usr/share/language-tools
30
+langcode=${lang%%[_@]*}
32
+for loc in $( locale -a | grep -F .utf8 ); do
33
+ # skip locales for other languages
34
+ if [ $langcode = ${loc%%[._@]*} ]; then
35
+ loc=${loc%.*}${loc#*.utf8}
36
+ locales="$locales $loc"
41
+for loc in $locales; do
42
+ if [ $lang = $loc ]; then
43
+ locale_name=$( echo $loc | sed -r 's/([^@]+)/\1.UTF-8/' )
48
+if [ -z "$locale_name" -a $lang = ${lang%_[A-Z]*} ]; then
50
+ # try the "main" country code if any
53
+ if [ "${line%%[[:space:]]*}" = $langcode ]; then
54
+ main_country=${line##*[[:space:]]}
55
+ if [ $lang != ${lang#*@} ]; then
56
+ main_country=$main_country@${lang#*@}
60
+ done < $langtoolsdir/main-countries
61
+ if [ -n "$main_country" ]; then
62
+ for loc in $locales; do
63
+ if [ $main_country = $loc ]; then
64
+ locale_name=$( echo $loc | sed -r 's/([^@]+)/\1.UTF-8/' )
70
+ # try out fitting locale with any country code
71
+ if [ -z "$locale_name" -a $langcode != 'zh' ]; then
72
+ for loc in $locales; do
73
+ if [ "${loc%%[_@]*}" = $langcode ]; then
74
+ locale_name=$( echo $loc | sed -r 's/([^@]+)/\1.UTF-8/' )
84
--- accountsservice.orig/data/langtools/language-options 1970-01-01 01:00:00 +0100
85
+++ accountsservice/data/langtools/language-options 2011-07-25 17:49:25 +0200
91
+my $langtoolsdir = '/usr/share/language-tools';
93
+# get the locales available on the system
94
+my @avail_locales = map { chomp; s/\.utf8//; $_ } qx( locale -a | grep -F .utf8 );
96
+# add items without country code to facilitate lookups
97
+my %extended_localelist;
98
+for my $loc (@avail_locales) {
99
+ ( my $lang = $loc ) =~ s/_[A-Z]+//;
100
+ @extended_localelist{$loc, $lang} = (1, 1);
103
+# get the union of /usr/share/locale-langpack and /usr/share/locale
104
+my %translation_dirs;
105
+for my $dir ('/usr/share/locale-langpack', '/usr/share/locale') {
106
+ if ( opendir my ($dh), $dir ) {
107
+ $translation_dirs{$_} = 1 for readdir $dh;
111
+# get the intersection of available translation_dirs and the extended locale list
113
+for ( keys %extended_localelist ) {
114
+ $intersection{$_} = 1 if $translation_dirs{$_};
118
+if ( open my $fh, '<', "$langtoolsdir/main-countries" ) {
119
+ # If country code items in a language exist:
120
+ # - Remove the item without country code, since gettext won't find a
121
+ # translation under e.g. 'de_DE' if the first item in LANGUAGE is 'de'
122
+ # (see https://launchpad.net/bugs/700213). 'en' is kept, though, since
123
+ # it's always the last item in LANGUAGE per design.
124
+ # - Make sure that the main dialect of the language is represented among
125
+ # the country code items (see https://launchpad.net/bugs/710148).
128
+ next if /^\s*(?:#|$)/;
129
+ my ($k, $v) = split;
133
+ for ( keys %intersection ) {
134
+ next if /^en[^a-z]/;
135
+ ( my $not_country = $_ ) =~ s/_[A-Z]+//;
136
+ $count{$not_country} ++;
138
+ for my $langcode ( keys %count ) {
139
+ if ( $count{$langcode} > 1 ) {
140
+ delete $intersection{$langcode};
141
+ $intersection{ $main{$langcode} } = 1 if $main{$langcode};
145
+ # not access to the language-to-main-dialect map
146
+ # => stick with a minimum of list manipulation
147
+ delete $intersection{'zh'};
150
+# print the resulting list of language options
151
+print join("\n", keys %intersection) || 'en';
154
--- accountsservice.orig/data/langtools/language-validate 1970-01-01 01:00:00 +0100
155
+++ accountsservice/data/langtools/language-validate 2011-07-25 17:50:31 +0200
162
+test -n "$lang" || exit 0
164
+langtoolsdir=/usr/share/language-tools
167
+# remove possible encoding part
169
+if [ $lang != ${lang%.utf8*} ]; then
170
+ lang=${lang%.*}${lang#*.utf8}
171
+elif [ $lang != ${lang%.UTF-8*} ]; then
172
+ lang=${lang%.*}${lang#*.UTF-8}
176
+# make sure that the output is a valid language option
178
+options=$( $langtoolsdir/language-options )
181
+for opt in $options; do
182
+ if [ $opt = $lang ]; then
183
+ validated_language=$lang
188
+if [ -z "$validated_language" ]; then
189
+ langcode=${lang%%[_@]*}
191
+ # try the "main" country code if any
193
+ while read line; do
194
+ if [ "${line%%[[:space:]]*}" = $langcode ]; then
195
+ main_country=${line##*[[:space:]]}
196
+ if [ $lang != ${lang#*@} ]; then
197
+ main_country=$main_country@${lang#*@}
202
+ done < $langtoolsdir/main-countries
203
+ if [ -n "$main_country" ]; then
204
+ for opt in $options; do
205
+ if [ $main_country = $opt ]; then
206
+ validated_language=$main_country
212
+ # try out fitting language option without paying regard to
213
+ # country code or variant
214
+ if [ -z "$validated_language" ]; then
215
+ for opt in $options; do
216
+ if [ "${opt%%[_@]*}" = $langcode -a $langcode != 'zh' ]; then
217
+ validated_language=$opt
224
+if [ -z "$validated_language" ]; then
225
+ validated_language='en'
228
+echo $validated_language
231
--- accountsservice.orig/data/langtools/main-countries 1970-01-01 01:00:00 +0100
232
+++ accountsservice/data/langtools/main-countries 2011-05-17 13:19:55 +0200
234
+# If multiple country codes are present among the available locales for
235
+# a language, we may want to map the language code to the language's
236
+# main or origin country. The list below aims to serve that purpose.
263
--- accountsservice.orig/data/langtools/Makefile.am 1970-01-01 01:00:00 +0100
264
+++ accountsservice/data/langtools/Makefile.am 2011-08-10 15:26:00 +0200
266
+langtoolsdir = ${datadir}/language-tools
269
+ if test '!' -d $(DESTDIR)$(langtoolsdir); then \
270
+ $(mkinstalldirs) $(DESTDIR)$(langtoolsdir); \
271
+ chmod 755 $(DESTDIR)$(langtoolsdir); \
274
+ $(INSTALL_SCRIPT) language-options $(DESTDIR)$(langtoolsdir)/language-options
275
+ $(INSTALL_SCRIPT) language-validate $(DESTDIR)$(langtoolsdir)/language-validate
276
+ $(INSTALL_SCRIPT) language2locale $(DESTDIR)$(langtoolsdir)/language2locale
277
+ $(INSTALL_DATA) main-countries $(DESTDIR)$(langtoolsdir)/main-countries
278
+ $(INSTALL_SCRIPT) save-to-profile $(DESTDIR)$(langtoolsdir)/save-to-profile
279
+ $(INSTALL_SCRIPT) set-language-helper $(DESTDIR)$(langtoolsdir)/set-language-helper
280
+ $(INSTALL_SCRIPT) update-langlist $(DESTDIR)$(langtoolsdir)/update-langlist
283
--- accountsservice.orig/data/langtools/save-to-profile 1970-01-01 01:00:00 +0100
284
+++ accountsservice/data/langtools/save-to-profile 2011-08-11 13:53:10 +0200
288
+# attempts to update the language settings in the user's ~/.profile config file
294
+test -n "$user" || exit 0
296
+# look up the user's home directory first
298
+ [ "${line%%:*}" = $user ] && break
299
+done < '/etc/passwd'
300
+if [ -n "$line" ]; then
304
+ for homedir in $line; do
305
+ if [ $i -ne 6 ]; then
313
+if [ "$( echo $homedir )" = '' -o ! -d "$homedir" ]; then
317
+# create ~/.profile if it doesn't exist
318
+test -f "$homedir/.profile" || {
319
+ touch $homedir/.profile
320
+ chown $user:$user $homedir/.profile
325
+ if [ "$( grep "^[[:space:]]*export $var=" $homedir/.profile )" ]; then
326
+ sed -r -i "s/^[[:space:]]*(export $var=).*/\1\"$value\"/" $homedir/.profile
328
+ echo "export $var=\"$value\"" >> $homedir/.profile
331
+test -n "$language_list" && save_to_profile 'LANGUAGE' $language_list
332
+test -n "$locale_name" && {
333
+ save_to_profile 'LC_MESSAGES' $locale_name
334
+ save_to_profile 'LC_CTYPE' $locale_name
335
+ save_to_profile 'LC_COLLATE' $locale_name
341
--- accountsservice.orig/data/langtools/set-language-helper 1970-01-01 01:00:00 +0100
342
+++ accountsservice/data/langtools/set-language-helper 2011-08-07 13:19:08 +0200
350
+[ -n "$user" -a -n "$language" ] || exit 0
352
+langtoolsdir=/usr/share/language-tools
354
+if [ $language = "${language%:*}" ]; then
355
+ validated_language=$( $langtoolsdir/language-validate $language )
356
+ renewed_langlist=$( $langtoolsdir/update-langlist $validated_language $user )
358
+ # $language contains a priority list
359
+ validated_language=$( $langtoolsdir/language-validate ${language%%:*} )
360
+ renewed_langlist=$validated_language:${language#*:}
363
+locale_name=$( $langtoolsdir/language2locale $validated_language )
365
+( $langtoolsdir/save-to-profile $user $renewed_langlist $locale_name )
367
+echo $validated_language
370
--- accountsservice.orig/data/langtools/update-langlist 1970-01-01 01:00:00 +0100
371
+++ accountsservice/data/langtools/update-langlist 2011-08-11 13:53:29 +0200
375
+# update-langlist maintains the LANGUAGE priority list. It does so in
376
+# a simplified manner, unlike the principal UI for setting the user
377
+# language which provides full control.
383
+[ -n "$first_language" -a -n "$user" ] || exit 0
385
+get_old_langlist() {
386
+ while read line; do
387
+ [ "${line%%:*}" = $user ] && break
389
+ if [ -n "$line" ]; then
393
+ for homedir in $line; do
394
+ if [ $i -ne 6 ]; then
403
+ if [ -r "$homedir/.profile" ]; then
404
+ old_langlist=$( grep "^[[:space:]]*export LANGUAGE=" \
405
+ $homedir/.profile | cut -d '"' -f 2 )
411
+if [ ${first_language%%[_@]*} != 'en' ]; then
416
+if [ -n "$old_langlist" ] && ! $english; then
417
+ if expr $old_langlist : ".*:$first_language:" > /dev/null ; then
418
+ renewed_langlist=$( echo $old_langlist | sed -r "s/(.+:)($first_language:)/\2\1/" )
419
+ elif [ ${old_langlist%%:*} = $first_language ]; then
421
+ renewed_langlist=$old_langlist
423
+ renewed_langlist=$first_language:$old_langlist
426
+ # build fresh list with 'en' as the last element
427
+ # no other languages needed if English was selected
428
+ renewed_langlist=$first_language
429
+ [ $first_language != 'en' ] && renewed_langlist=$renewed_langlist:en
432
+echo $renewed_langlist
435
--- accountsservice.orig/data/Makefile.am 2011-07-19 21:48:12 +0200
436
+++ accountsservice/data/Makefile.am 2011-08-10 15:10:27 +0200
440
dbusifdir = $(datadir)/dbus-1/interfaces