1
This patch was taken from gnome-control-center 52_region_language.patch,
2
where relevent language code used to live in 3.6
4
Description: Adapts the region capplet and the language chooser in the user accounts capplet
5
Forwarded: https://bugzilla.gnome.org/695939, https://bugzilla.gnome.org/695940
6
Author: Gunnar Hjalmarsson <gunnarhj@ubuntu.com>
7
Last-Update: 2013-04-10
9
* Ubuntu isn't shipped with all languages installed and all locales generated.
10
Instead the users install the needed language pack(s), and the corresponding
11
locales are generated.
13
* Locales stored with codeset '.UTF-8' instead of '.utf8'.
15
* The 'common_name' field taken into account when parsing the iso-codes XML files
19
libgnome-desktop/gnome-languages.c | 75 +++++++++++++++++++++++++++++---------
20
1 file changed, 57 insertions(+), 18 deletions(-)
22
diff --git a/libgnome-desktop/gnome-languages.c b/libgnome-desktop/gnome-languages.c
23
index 18e3705..eaa6622 100644
24
--- a/libgnome-desktop/gnome-languages.c
25
+++ b/libgnome-desktop/gnome-languages.c
26
@@ -97,6 +97,7 @@ normalize_codeset (const char *codeset)
29
normalized_codeset = g_strdup (codeset);
30
+ return normalized_codeset;
32
if (codeset != NULL) {
33
for (p = codeset, q = normalized_codeset;
34
@@ -242,6 +243,7 @@ construct_language_name (const char *language,
38
+ const char *adj_codeset;
41
g_assert (language[0] != 0);
42
@@ -249,12 +251,17 @@ construct_language_name (const char *language,
43
g_assert (codeset == NULL || codeset[0] != 0);
44
g_assert (modifier == NULL || modifier[0] != 0);
46
+ if (g_strcmp0 (codeset, "utf8") == 0) {
47
+ adj_codeset = "UTF-8";
49
+ adj_codeset = codeset;
51
name = g_strdup_printf ("%s%s%s%s%s%s%s",
53
territory != NULL? "_" : "",
54
territory != NULL? territory : "",
55
codeset != NULL? "." : "",
56
- codeset != NULL? codeset : "",
57
+ codeset != NULL? adj_codeset : "",
58
modifier != NULL? "@" : "",
59
modifier != NULL? modifier : "");
61
@@ -315,7 +322,6 @@ language_name_is_valid (const char *language_name)
63
int lc_type_id = LC_MESSAGES;
66
old_locale = g_strdup (setlocale (lc_type_id, NULL));
67
is_valid = setlocale (lc_type_id, language_name) != NULL;
68
setlocale (lc_type_id, old_locale);
69
@@ -347,8 +353,7 @@ language_name_get_codeset_details (const char *language_name,
71
if (is_utf8 != NULL) {
72
codeset = normalize_codeset (codeset);
74
- *is_utf8 = strcmp (codeset, "utf8") == 0;
75
+ *is_utf8 = strcmp (codeset, "UTF-8") == 0;
79
@@ -419,8 +424,7 @@ add_locale (const char *language_name,
81
name = g_strdup (language_name);
82
} else if (utf8_only) {
83
- name = g_strdup_printf ("%s.utf8", language_name);
85
+ name = g_strdup_printf ("%s.UTF-8", language_name);
86
language_name_get_codeset_details (name, NULL, &is_utf8);
89
@@ -631,6 +635,30 @@ collect_locales_from_directory (void)
94
+collect_locales_from_ubuntu (void)
96
+ /* Add installed languages */
97
+ gboolean found_locales = FALSE;
99
+ gchar *avail_languages;
100
+ GError *error = NULL;
101
+ if (g_spawn_command_line_sync ("/usr/share/language-tools/language-options",
102
+ &avail_languages, NULL, NULL, &error)) {
103
+ name = strtok (avail_languages, "\n");
104
+ while (name != NULL) {
105
+ if (add_locale (name, TRUE))
106
+ found_locales = TRUE;
107
+ name = strtok (NULL, "\n");
109
+ g_free (avail_languages);
111
+ g_warning ("Couldn't get available locales: %s", error->message);
112
+ g_error_free (error);
114
+ return found_locales;
118
count_languages_and_territories (void)
120
@@ -667,23 +695,16 @@ count_languages_and_territories (void)
122
collect_locales (void)
124
- gboolean found_archive_locales = FALSE;
125
- gboolean found_dir_locales = FALSE;
126
+ gboolean found_locales;
127
GError *error = NULL;
129
if (gnome_available_locales_map == NULL) {
130
gnome_available_locales_map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) gnome_locale_free);
133
+ found_locales = collect_locales_from_ubuntu ();
135
- if (!collect_locales_from_archive (&found_archive_locales, &error)) {
136
- g_warning ("Failed to load locales from archive: %s", error->message);
137
- g_clear_error (&error);
140
- found_dir_locales = collect_locales_from_directory ();
142
- if (!(found_archive_locales || found_dir_locales)) {
143
+ if (!found_locales) {
144
#ifndef WITH_INCOMPLETE_LOCALES
145
g_warning ("Could not read list of available locales from libc, "
146
"guessing possible locales from available translations, "
147
@@ -877,6 +898,7 @@ languages_parse_start_tag (GMarkupParseContext *ctx,
148
const char *ccode_longT;
150
const char *ccode_id;
151
+ const char *lang_common_name;
152
const char *lang_name;
154
if (! (g_str_equal (element_name, "iso_639_entry") || g_str_equal (element_name, "iso_639_3_entry"))
155
@@ -888,6 +910,7 @@ languages_parse_start_tag (GMarkupParseContext *ctx,
159
+ lang_common_name = NULL;
162
while (*attr_names && *attr_values) {
163
@@ -924,6 +947,11 @@ languages_parse_start_tag (GMarkupParseContext *ctx,
165
ccode_id = *attr_values;
167
+ } else if (g_str_equal (*attr_names, "common_name")) {
168
+ /* skip if empty */
169
+ if (**attr_values) {
170
+ lang_common_name = *attr_values;
172
} else if (g_str_equal (*attr_names, "name")) {
173
lang_name = *attr_values;
175
@@ -932,6 +960,10 @@ languages_parse_start_tag (GMarkupParseContext *ctx,
179
+ if (lang_common_name != NULL) {
180
+ lang_name = lang_common_name;
183
if (lang_name == NULL) {
186
@@ -1174,6 +1206,7 @@ gnome_get_language_from_locale (const char *locale,
187
char *langinfo_codeset;
188
char *translated_language;
189
char *translated_territory;
191
gboolean is_utf8 = TRUE;
193
g_return_val_if_fail (locale != NULL, NULL);
194
@@ -1191,12 +1224,13 @@ gnome_get_language_from_locale (const char *locale,
195
language_code = NULL;
196
territory_code = NULL;
200
gnome_parse_locale (locale,
207
if (language_code == NULL) {
209
@@ -1222,7 +1256,7 @@ gnome_get_language_from_locale (const char *locale,
210
translated_territory);
213
- language_name_get_codeset_details (locale, &langinfo_codeset, &is_utf8);
214
+ //language_name_get_codeset_details (locale, &langinfo_codeset, &is_utf8);
216
if (codeset_code == NULL && langinfo_codeset != NULL) {
217
codeset_code = g_strdup (langinfo_codeset);
218
@@ -1234,6 +1268,10 @@ gnome_get_language_from_locale (const char *locale,
222
+ if (modifier != NULL) {
223
+ g_string_append_printf (full_language, " - %s", modifier);
227
g_free (language_code);
228
g_free (territory_code);
229
@@ -1241,6 +1279,7 @@ gnome_get_language_from_locale (const char *locale,
230
g_free (langinfo_codeset);
231
g_free (translated_language);
232
g_free (translated_territory);
235
if (full_language->len == 0) {
236
g_string_free (full_language, TRUE);