Gentoo Archives: gentoo-commits

From: "PaweA Hajdan (phajdan.jr)" <phajdan.jr@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in www-client/chromium/files: chromium-locale-glib-r0.patch chromium-locale-glib-r1.patch
Date: Thu, 04 Nov 2010 20:58:39
Message-Id: 20101104205833.B58B820054@flycatcher.gentoo.org
1 phajdan.jr 10/11/04 20:58:33
2
3 Added: chromium-locale-glib-r0.patch
4 chromium-locale-glib-r1.patch
5 Log:
6 Version bump for beta and stable channel releases. Fix bug #343971 by Sok Ann Yap <sokann@×××××.com>. Lower cups dependency to 1.3.x everywhere, it is just too much trouble to maintain. Remove old.
7 (Portage version: 2.1.8.3/cvs/Linux i686)
8
9 Revision Changes Path
10 1.1 www-client/chromium/files/chromium-locale-glib-r0.patch
11
12 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/www-client/chromium/files/chromium-locale-glib-r0.patch?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/www-client/chromium/files/chromium-locale-glib-r0.patch?rev=1.1&content-type=text/plain
14
15 Index: chromium-locale-glib-r0.patch
16 ===================================================================
17 Index: app/l10n_util.cc
18 ===================================================================
19 --- app/l10n_util.cc (revision 63359)
20 +++ app/l10n_util.cc (working copy)
21 @@ -4,6 +4,10 @@
22
23 #include "app/l10n_util.h"
24
25 +#if defined(TOOLKIT_USES_GTK)
26 +#include <glib/gutils.h>
27 +#endif
28 +
29 #include <cstdlib>
30
31 #include "app/app_paths.h"
32 @@ -384,43 +335,71 @@
33 namespace l10n_util {
34
35 std::string GetApplicationLocale(const std::string& pref_locale) {
36 -#if !defined(OS_MACOSX)
37 +#if defined(OS_MACOSX)
38 +
39 + // Use any override (Cocoa for the browser), otherwise use the preference
40 + // passed to the function.
41 + std::string app_locale = l10n_util::GetLocaleOverride();
42 + if (app_locale.empty())
43 + app_locale = pref_locale;
44 +
45 + // The above should handle all of the cases Chrome normally hits, but for some
46 + // unit tests, we need something to fall back too.
47 + if (app_locale.empty())
48 + app_locale = "en-US";
49 +
50 + // Windows/Linux call SetICUDefaultLocale after determining the actual locale
51 + // with CheckAndResolveLocal to make ICU APIs work in that locale.
52 + // Mac doesn't use a locale directory tree of resources (it uses Mac style
53 + // resources), so mirror the Windows/Linux behavior of calling
54 + // SetICUDefaultLocale.
55 + base::i18n::SetICUDefaultLocale(app_locale);
56 + return app_locale;
57 +
58 +#else
59 +
60 FilePath locale_path;
61 PathService::Get(app::DIR_LOCALES, &locale_path);
62 std::string resolved_locale;
63 std::vector<std::string> candidates;
64 - const std::string system_locale = GetSystemLocale();
65
66 // We only use --lang and the app pref on Windows. On Linux, we only
67 // look at the LC_*/LANG environment variables. We do, however, pass --lang
68 // to renderer and plugin processes so they know what language the parent
69 // process decided to use.
70 +
71 #if defined(OS_WIN)
72 +
73 // First, try the preference value.
74 if (!pref_locale.empty())
75 candidates.push_back(pref_locale);
76
77 // Next, try the system locale.
78 - candidates.push_back(system_locale);
79 + candidates.push_back(base::i18n::GetConfiguredLocale());
80
81 #elif defined(OS_CHROMEOS)
82 +
83 // On ChromeOS, use the application locale preference.
84 if (!pref_locale.empty())
85 candidates.push_back(pref_locale);
86
87 -#elif defined(OS_POSIX)
88 - // On POSIX, we also check LANGUAGE environment variable, which is supported
89 - // by gettext to specify a priority list of prefered languages.
90 - const char* env_language = ::getenv("LANGUAGE");
91 - if (env_language)
92 - SplitAndNormalizeLanguageList(env_language, &candidates);
93 +#elif defined(OS_POSIX) && defined(TOOLKIT_USES_GTK)
94
95 - // Only fallback to the system locale if LANGUAGE is not specified.
96 - // We emulate gettext's behavior here, which ignores LANG/LC_MESSAGES/LC_ALL
97 - // when LANGUAGE is specified. If no language specified in LANGUAGE is valid,
98 - // then just fallback to the locale based on LC_ALL/LANG.
99 - if (candidates.empty())
100 - candidates.push_back(system_locale);
101 + // GLib implements correct environment variable parsing with
102 + // the precedence order: LANGUAGE, LC_ALL, LC_MESSAGES and LANG.
103 + // We used to use our custom parsing code along with ICU for this purpose.
104 + // If we have a port that does not depend on GTK, we have to
105 + // restore our custom code for that port.
106 + const char* const* languages = g_get_language_names();
107 + DCHECK(languages); // A valid pointer is guaranteed.
108 + DCHECK(*languages); // At least one entry, "C", is guaranteed.
109 +
110 + for (; *languages != NULL; ++languages) {
111 + candidates.push_back(base::i18n::GetCanonicalLocale(*languages));
112 + }
113 +
114 +#else
115 +#error Unsupported platform, see build/build_config.h
116 #endif
117
118 std::vector<std::string>::const_iterator i = candidates.begin();
119 @@ -443,27 +422,7 @@
120
121 return std::string();
122
123 -#else // !defined(OS_MACOSX)
124 -
125 - // Use any override (Cocoa for the browser), otherwise use the preference
126 - // passed to the function.
127 - std::string app_locale = l10n_util::GetLocaleOverride();
128 - if (app_locale.empty())
129 - app_locale = pref_locale;
130 -
131 - // The above should handle all of the cases Chrome normally hits, but for some
132 - // unit tests, we need something to fall back too.
133 - if (app_locale.empty())
134 - app_locale = "en-US";
135 -
136 - // Windows/Linux call SetICUDefaultLocale after determining the actual locale
137 - // with CheckAndResolveLocal to make ICU APIs work in that locale.
138 - // Mac doesn't use a locale directory tree of resources (it uses Mac style
139 - // resources), so mirror the Windows/Linux behavior of calling
140 - // SetICUDefaultLocale.
141 - base::i18n::SetICUDefaultLocale(app_locale);
142 - return app_locale;
143 -#endif // !defined(OS_MACOSX)
144 +#endif
145 }
146
147 string16 GetDisplayNameForLocale(const std::string& locale,
148 Index: app/l10n_util_unittest.cc
149 ===================================================================
150 --- app/l10n_util_unittest.cc (revision 63359)
151 +++ app/l10n_util_unittest.cc (working copy)
152 @@ -100,7 +100,17 @@
153 // The meaning of that API, on the Mac, is "the locale used by Cocoa's main
154 // nib file", which clearly can't be stubbed by a test app that doesn't use
155 // Cocoa.
156 +
157 +void SetDefaultLocaleForTest(const std::string& tag, base::Environment* env) {
158 +#if defined(OS_POSIX) && !defined(OS_CHROMEOS)
159 + env->SetVar("LANGUAGE", tag);
160 +#else
161 + SetICUDefaultLocale(tag);
162 +#endif
163 +}
164 +
165 TEST_F(L10nUtilTest, GetAppLocale) {
166 + scoped_ptr<base::Environment> env;
167 // Use a temporary locale dir so we don't have to actually build the locale
168 // dlls for this test.
169 FilePath orig_locale_dir;
170 @@ -140,7 +150,7 @@
171 icu::Locale locale = icu::Locale::getDefault();
172
173 #if defined(OS_POSIX) && !defined(OS_CHROMEOS)
174 - scoped_ptr<base::Environment> env(base::Environment::Create());
175 + env.reset(base::Environment::Create());
176
177 // Test the support of LANGUAGE environment variable.
178 SetICUDefaultLocale("en-US");
179 @@ -163,15 +173,25 @@
180 env->SetVar("LANGUAGE", "/fr:zh_CN");
181 EXPECT_EQ("zh-CN", l10n_util::GetApplicationLocale(""));
182
183 - // Make sure the follow tests won't be affected by LANGUAGE environment
184 - // variable.
185 + // Test prioritization of the different environment variables.
186 + env->SetVar("LANGUAGE", "fr");
187 + env->SetVar("LC_ALL", "es");
188 + env->SetVar("LC_MESSAGES", "he");
189 + env->SetVar("LANG", "nb");
190 + EXPECT_EQ("fr", l10n_util::GetApplicationLocale(""));
191 env->UnSetVar("LANGUAGE");
192 + EXPECT_EQ("es", l10n_util::GetApplicationLocale(""));
193 + env->UnSetVar("LC_ALL");
194 + EXPECT_EQ("he", l10n_util::GetApplicationLocale(""));
195 + env->UnSetVar("LC_MESSAGES");
196 + EXPECT_EQ("nb", l10n_util::GetApplicationLocale(""));
197 + env->UnSetVar("LANG");
198 #endif // defined(OS_POSIX) && !defined(OS_CHROMEOS)
199
200 - SetICUDefaultLocale("en-US");
201 + SetDefaultLocaleForTest("en-US", env.get());
202 EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(""));
203
204 - SetICUDefaultLocale("xx");
205 + SetDefaultLocaleForTest("xx", env.get());
206 EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(""));
207
208 #if defined(OS_CHROMEOS)
209 @@ -184,31 +204,31 @@
210 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale("en-GB"));
211
212 #else // defined(OS_CHROMEOS)
213 - SetICUDefaultLocale("en-GB");
214 + SetDefaultLocaleForTest("en-GB", env.get());
215 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale(""));
216
217 - SetICUDefaultLocale("fr-CA");
218 + SetDefaultLocaleForTest("fr-CA", env.get());
219 EXPECT_EQ("fr", l10n_util::GetApplicationLocale(""));
220
221 - SetICUDefaultLocale("es-MX");
222 + SetDefaultLocaleForTest("es-MX", env.get());
223 EXPECT_EQ("es-419", l10n_util::GetApplicationLocale(""));
224
225 - SetICUDefaultLocale("es-AR");
226 + SetDefaultLocaleForTest("es-AR", env.get());
227 EXPECT_EQ("es-419", l10n_util::GetApplicationLocale(""));
228
229 - SetICUDefaultLocale("es-ES");
230 + SetDefaultLocaleForTest("es-ES", env.get());
231 EXPECT_EQ("es", l10n_util::GetApplicationLocale(""));
232
233 - SetICUDefaultLocale("es");
234 + SetDefaultLocaleForTest("es", env.get());
235 EXPECT_EQ("es", l10n_util::GetApplicationLocale(""));
236
237 - SetICUDefaultLocale("zh-HK");
238 + SetDefaultLocaleForTest("zh-HK", env.get());
239 EXPECT_EQ("zh-TW", l10n_util::GetApplicationLocale(""));
240
241 - SetICUDefaultLocale("zh-MK");
242 + SetDefaultLocaleForTest("zh-MK", env.get());
243 EXPECT_EQ("zh-TW", l10n_util::GetApplicationLocale(""));
244
245 - SetICUDefaultLocale("zh-SG");
246 + SetDefaultLocaleForTest("zh-SG", env.get());
247 EXPECT_EQ("zh-CN", l10n_util::GetApplicationLocale(""));
248 #endif // defined (OS_CHROMEOS)
249
250 Index: base/i18n/rtl.cc
251 ===================================================================
252 --- base/i18n/rtl.cc (revision 63359)
253 +++ base/i18n/rtl.cc (working copy)
254 @@ -18,26 +18,58 @@
255 #include <gtk/gtk.h>
256 #endif
257
258 +namespace {
259 +
260 +// Extract language and country, ignore keywords, concatenate using dash.
261 +std::string GetLocaleString(const icu::Locale& locale) {
262 + const char* language = locale.getLanguage();
263 + const char* country = locale.getCountry();
264 +
265 + std::string result =
266 + (language != NULL && *language != '\0') ? language : "und";
267 +
268 + if (country != NULL && *country != '\0') {
269 + result += '-';
270 + result += country;
271 + }
272 +
273 + return result;
274 +}
275 +
276 +} // namespace
277 +
278 namespace base {
279 namespace i18n {
280
281 // Represents the locale-specific ICU text direction.
282 static TextDirection g_icu_text_direction = UNKNOWN_DIRECTION;
283
284 +#if defined(OS_WIN)
285 void GetLanguageAndRegionFromOS(std::string* lang, std::string* region) {
286 // Later we may have to change this to be OS-dependent so that
287 // it's not affected by ICU's default locale. It's all right
288 // to do this way because SetICUDefaultLocale is internal
289 // to this file and we know that it's not yet called when this function
290 // is called.
291 - icu::Locale locale = icu::Locale::getDefault();
292 + const icu::Locale& locale = icu::Locale::getDefault();
293 const char* language = locale.getLanguage();
294 const char* country = locale.getCountry();
295 DCHECK(language);
296 *lang = language;
297 *region = country;
298 }
299 +#endif
300
301 +// Convert the ICU default locale to a string.
302 +std::string GetConfiguredLocale() {
303 + return GetLocaleString(icu::Locale::getDefault());
304 +}
305 +
306 +// Convert the ICU canonicalized locale to a string.
307 +std::string GetCanonicalLocale(const char* locale) {
308 + return GetLocaleString(icu::Locale::createCanonical(locale));
309 +}
310 +
311 // Convert Chrome locale name to ICU locale name
312 std::string ICULocaleName(const std::string& locale_string) {
313 // If not Spanish, just return it.
314 @@ -50,13 +82,14 @@
315 // locale. If it's es-RR other than es-ES, map to es-RR. Otherwise, map
316 // to es-MX (the most populous in Spanish-speaking Latin America).
317 if (LowerCaseEqualsASCII(locale_string, "es-419")) {
318 - std::string lang, region;
319 - GetLanguageAndRegionFromOS(&lang, &region);
320 - if (LowerCaseEqualsASCII(lang, "es") &&
321 - !LowerCaseEqualsASCII(region, "es")) {
322 - lang.append("-");
323 - lang.append(region);
324 - return lang;
325 + const icu::Locale& locale = icu::Locale::getDefault();
326 + std::string language = locale.getLanguage();
327 + const char* country = locale.getCountry();
328 + if (LowerCaseEqualsASCII(language, "es") &&
329 + !LowerCaseEqualsASCII(country, "es")) {
330 + language += '-';
331 + language += country;
332 + return language;
333 }
334 return "es-MX";
335 }
336 Index: base/i18n/rtl.h
337 ===================================================================
338 --- base/i18n/rtl.h (revision 63359)
339 +++ base/i18n/rtl.h (working copy)
340 @@ -29,9 +29,19 @@
341 LEFT_TO_RIGHT,
342 };
343
344 -// Get language and region from the OS.
345 +#if defined(OS_WIN)
346 +// Get language and region from the OS. Used by Chrome Frame.
347 void GetLanguageAndRegionFromOS(std::string* lang, std::string* region);
348 +#endif
349
350 +// Get the locale that the currently running process has been configured to use.
351 +// The return value is of the form language[-country] (e.g., en-US) where the
352 +// language is the 2 or 3 letter code from ISO-639.
353 +std::string GetConfiguredLocale();
354 +
355 +// Canonicalize a string (eg. a POSIX locale string) to a Chrome locale name.
356 +std::string GetCanonicalLocale(const char* locale);
357 +
358 // Sets the default locale of ICU.
359 // Once the application locale of Chrome in GetApplicationLocale is determined,
360 // the default locale of ICU need to be changed to match the application locale
361 @@ -136,7 +146,7 @@
362 // string is wrapped with LRE (Left-To-Right Embedding) and PDF (Pop
363 // Directional Formatting) marks and returned. In LTR locale, the string itself
364 // is returned.
365 -string16 GetDisplayStringInLTRDirectionality(const string16& text)
366 +string16 GetDisplayStringInLTRDirectionality(const string16& text)
367 WARN_UNUSED_RESULT;
368
369 // Strip the beginning (U+202A..U+202B, U+202D..U+202E) and/or ending (U+202C)
370 --- app/l10n_util.cc.orig 2010-11-04 13:19:45.000000000 +0100
371 +++ app/l10n_util.cc 2010-11-04 13:20:46.000000000 +0100
372 @@ -313,59 +313,6 @@
373 return false;
374 }
375
376 -// Get the locale of the operating system. The return value is of the form
377 -// language[-country] (e.g., en-US) where the language is the 2 letter code from
378 -// ISO-639.
379 -std::string GetSystemLocale() {
380 - std::string language, region;
381 - base::i18n::GetLanguageAndRegionFromOS(&language, &region);
382 - std::string ret;
383 - if (!language.empty())
384 - ret.append(language);
385 - if (!region.empty()) {
386 - ret.append("-");
387 - ret.append(region);
388 - }
389 - return ret;
390 -}
391 -
392 -#if defined(OS_POSIX) && !defined(OS_MACOSX)
393 -// Split and normalize the language list specified by LANGUAGE environment.
394 -// LANGUAGE environment specifies a priority list of user prefered locales for
395 -// application UI messages. Locales are separated by ':' character. The format
396 -// of a locale is: language[_territory[.codeset]][@modifier]
397 -//
398 -// This function splits the language list and normalizes each locale into
399 -// language[-territory] format, eg. fr, zh-CN, etc.
400 -void SplitAndNormalizeLanguageList(const std::string& env_language,
401 - std::vector<std::string>* result) {
402 - std::vector<std::string> langs;
403 - SplitString(env_language, ':', &langs);
404 - std::vector<std::string>::iterator i = langs.begin();
405 - for (; i != langs.end(); ++i) {
406 - size_t end_pos = i->find_first_of(".@");
407 - // Erase encoding and modifier part.
408 - if (end_pos != std::string::npos)
409 - i->erase(end_pos);
410 -
411 - if (!i->empty()) {
412 - std::string locale;
413 - size_t sep = i->find_first_of("_-");
414 - if (sep != std::string::npos) {
415 - // language part is always in lower case.
416 - locale = StringToLowerASCII(i->substr(0, sep));
417 - locale.append("-");
418 - // territory part is always in upper case.
419 - locale.append(StringToUpperASCII(i->substr(sep + 1)));
420 - } else {
421 - locale = StringToLowerASCII(*i);
422 - }
423 - result->push_back(locale);
424 - }
425 - }
426 -}
427 -#endif
428 -
429 // On Linux, the text layout engine Pango determines paragraph directionality
430 // by looking at the first strongly-directional character in the text. This
431 // means text such as "Google Chrome foo bar..." will be layed out LTR even
432
433
434
435 1.1 www-client/chromium/files/chromium-locale-glib-r1.patch
436
437 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/www-client/chromium/files/chromium-locale-glib-r1.patch?rev=1.1&view=markup
438 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/www-client/chromium/files/chromium-locale-glib-r1.patch?rev=1.1&content-type=text/plain
439
440 Index: chromium-locale-glib-r1.patch
441 ===================================================================
442 Index: app/l10n_util.cc
443 ===================================================================
444 --- app/l10n_util.cc (revision 63359)
445 +++ app/l10n_util.cc (working copy)
446 @@ -4,6 +4,10 @@
447
448 #include "app/l10n_util.h"
449
450 +#if defined(TOOLKIT_USES_GTK)
451 +#include <glib/gutils.h>
452 +#endif
453 +
454 #include <cstdlib>
455
456 #include "app/app_paths.h"
457 @@ -384,43 +335,71 @@
458 namespace l10n_util {
459
460 std::string GetApplicationLocale(const std::string& pref_locale) {
461 -#if !defined(OS_MACOSX)
462 +#if defined(OS_MACOSX)
463 +
464 + // Use any override (Cocoa for the browser), otherwise use the preference
465 + // passed to the function.
466 + std::string app_locale = l10n_util::GetLocaleOverride();
467 + if (app_locale.empty())
468 + app_locale = pref_locale;
469 +
470 + // The above should handle all of the cases Chrome normally hits, but for some
471 + // unit tests, we need something to fall back too.
472 + if (app_locale.empty())
473 + app_locale = "en-US";
474 +
475 + // Windows/Linux call SetICUDefaultLocale after determining the actual locale
476 + // with CheckAndResolveLocal to make ICU APIs work in that locale.
477 + // Mac doesn't use a locale directory tree of resources (it uses Mac style
478 + // resources), so mirror the Windows/Linux behavior of calling
479 + // SetICUDefaultLocale.
480 + base::i18n::SetICUDefaultLocale(app_locale);
481 + return app_locale;
482 +
483 +#else
484 +
485 FilePath locale_path;
486 PathService::Get(app::DIR_LOCALES, &locale_path);
487 std::string resolved_locale;
488 std::vector<std::string> candidates;
489 - const std::string system_locale = GetSystemLocale();
490
491 // We only use --lang and the app pref on Windows. On Linux, we only
492 // look at the LC_*/LANG environment variables. We do, however, pass --lang
493 // to renderer and plugin processes so they know what language the parent
494 // process decided to use.
495 +
496 #if defined(OS_WIN)
497 +
498 // First, try the preference value.
499 if (!pref_locale.empty())
500 candidates.push_back(pref_locale);
501
502 // Next, try the system locale.
503 - candidates.push_back(system_locale);
504 + candidates.push_back(base::i18n::GetConfiguredLocale());
505
506 #elif defined(OS_CHROMEOS)
507 +
508 // On ChromeOS, use the application locale preference.
509 if (!pref_locale.empty())
510 candidates.push_back(pref_locale);
511
512 -#elif defined(OS_POSIX)
513 - // On POSIX, we also check LANGUAGE environment variable, which is supported
514 - // by gettext to specify a priority list of prefered languages.
515 - const char* env_language = ::getenv("LANGUAGE");
516 - if (env_language)
517 - SplitAndNormalizeLanguageList(env_language, &candidates);
518 +#elif defined(OS_POSIX) && defined(TOOLKIT_USES_GTK)
519
520 - // Only fallback to the system locale if LANGUAGE is not specified.
521 - // We emulate gettext's behavior here, which ignores LANG/LC_MESSAGES/LC_ALL
522 - // when LANGUAGE is specified. If no language specified in LANGUAGE is valid,
523 - // then just fallback to the locale based on LC_ALL/LANG.
524 - if (candidates.empty())
525 - candidates.push_back(system_locale);
526 + // GLib implements correct environment variable parsing with
527 + // the precedence order: LANGUAGE, LC_ALL, LC_MESSAGES and LANG.
528 + // We used to use our custom parsing code along with ICU for this purpose.
529 + // If we have a port that does not depend on GTK, we have to
530 + // restore our custom code for that port.
531 + const char* const* languages = g_get_language_names();
532 + DCHECK(languages); // A valid pointer is guaranteed.
533 + DCHECK(*languages); // At least one entry, "C", is guaranteed.
534 +
535 + for (; *languages != NULL; ++languages) {
536 + candidates.push_back(base::i18n::GetCanonicalLocale(*languages));
537 + }
538 +
539 +#else
540 +#error Unsupported platform, see build/build_config.h
541 #endif
542
543 std::vector<std::string>::const_iterator i = candidates.begin();
544 @@ -443,27 +422,7 @@
545
546 return std::string();
547
548 -#else // !defined(OS_MACOSX)
549 -
550 - // Use any override (Cocoa for the browser), otherwise use the preference
551 - // passed to the function.
552 - std::string app_locale = l10n_util::GetLocaleOverride();
553 - if (app_locale.empty())
554 - app_locale = pref_locale;
555 -
556 - // The above should handle all of the cases Chrome normally hits, but for some
557 - // unit tests, we need something to fall back too.
558 - if (app_locale.empty())
559 - app_locale = "en-US";
560 -
561 - // Windows/Linux call SetICUDefaultLocale after determining the actual locale
562 - // with CheckAndResolveLocal to make ICU APIs work in that locale.
563 - // Mac doesn't use a locale directory tree of resources (it uses Mac style
564 - // resources), so mirror the Windows/Linux behavior of calling
565 - // SetICUDefaultLocale.
566 - base::i18n::SetICUDefaultLocale(app_locale);
567 - return app_locale;
568 -#endif // !defined(OS_MACOSX)
569 +#endif
570 }
571
572 string16 GetDisplayNameForLocale(const std::string& locale,
573 Index: app/l10n_util_unittest.cc
574 ===================================================================
575 --- app/l10n_util_unittest.cc (revision 63359)
576 +++ app/l10n_util_unittest.cc (working copy)
577 @@ -100,7 +100,17 @@
578 // The meaning of that API, on the Mac, is "the locale used by Cocoa's main
579 // nib file", which clearly can't be stubbed by a test app that doesn't use
580 // Cocoa.
581 +
582 +void SetDefaultLocaleForTest(const std::string& tag, base::Environment* env) {
583 +#if defined(OS_POSIX) && !defined(OS_CHROMEOS)
584 + env->SetVar("LANGUAGE", tag);
585 +#else
586 + SetICUDefaultLocale(tag);
587 +#endif
588 +}
589 +
590 TEST_F(L10nUtilTest, GetAppLocale) {
591 + scoped_ptr<base::Environment> env;
592 // Use a temporary locale dir so we don't have to actually build the locale
593 // dlls for this test.
594 FilePath orig_locale_dir;
595 @@ -140,7 +150,7 @@
596 icu::Locale locale = icu::Locale::getDefault();
597
598 #if defined(OS_POSIX) && !defined(OS_CHROMEOS)
599 - scoped_ptr<base::Environment> env(base::Environment::Create());
600 + env.reset(base::Environment::Create());
601
602 // Test the support of LANGUAGE environment variable.
603 SetICUDefaultLocale("en-US");
604 @@ -163,15 +173,25 @@
605 env->SetVar("LANGUAGE", "/fr:zh_CN");
606 EXPECT_EQ("zh-CN", l10n_util::GetApplicationLocale(""));
607
608 - // Make sure the follow tests won't be affected by LANGUAGE environment
609 - // variable.
610 + // Test prioritization of the different environment variables.
611 + env->SetVar("LANGUAGE", "fr");
612 + env->SetVar("LC_ALL", "es");
613 + env->SetVar("LC_MESSAGES", "he");
614 + env->SetVar("LANG", "nb");
615 + EXPECT_EQ("fr", l10n_util::GetApplicationLocale(""));
616 env->UnSetVar("LANGUAGE");
617 + EXPECT_EQ("es", l10n_util::GetApplicationLocale(""));
618 + env->UnSetVar("LC_ALL");
619 + EXPECT_EQ("he", l10n_util::GetApplicationLocale(""));
620 + env->UnSetVar("LC_MESSAGES");
621 + EXPECT_EQ("nb", l10n_util::GetApplicationLocale(""));
622 + env->UnSetVar("LANG");
623 #endif // defined(OS_POSIX) && !defined(OS_CHROMEOS)
624
625 - SetICUDefaultLocale("en-US");
626 + SetDefaultLocaleForTest("en-US", env.get());
627 EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(""));
628
629 - SetICUDefaultLocale("xx");
630 + SetDefaultLocaleForTest("xx", env.get());
631 EXPECT_EQ("en-US", l10n_util::GetApplicationLocale(""));
632
633 #if defined(OS_CHROMEOS)
634 @@ -184,31 +204,31 @@
635 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale("en-GB"));
636
637 #else // defined(OS_CHROMEOS)
638 - SetICUDefaultLocale("en-GB");
639 + SetDefaultLocaleForTest("en-GB", env.get());
640 EXPECT_EQ("en-GB", l10n_util::GetApplicationLocale(""));
641
642 - SetICUDefaultLocale("fr-CA");
643 + SetDefaultLocaleForTest("fr-CA", env.get());
644 EXPECT_EQ("fr", l10n_util::GetApplicationLocale(""));
645
646 - SetICUDefaultLocale("es-MX");
647 + SetDefaultLocaleForTest("es-MX", env.get());
648 EXPECT_EQ("es-419", l10n_util::GetApplicationLocale(""));
649
650 - SetICUDefaultLocale("es-AR");
651 + SetDefaultLocaleForTest("es-AR", env.get());
652 EXPECT_EQ("es-419", l10n_util::GetApplicationLocale(""));
653
654 - SetICUDefaultLocale("es-ES");
655 + SetDefaultLocaleForTest("es-ES", env.get());
656 EXPECT_EQ("es", l10n_util::GetApplicationLocale(""));
657
658 - SetICUDefaultLocale("es");
659 + SetDefaultLocaleForTest("es", env.get());
660 EXPECT_EQ("es", l10n_util::GetApplicationLocale(""));
661
662 - SetICUDefaultLocale("zh-HK");
663 + SetDefaultLocaleForTest("zh-HK", env.get());
664 EXPECT_EQ("zh-TW", l10n_util::GetApplicationLocale(""));
665
666 - SetICUDefaultLocale("zh-MK");
667 + SetDefaultLocaleForTest("zh-MK", env.get());
668 EXPECT_EQ("zh-TW", l10n_util::GetApplicationLocale(""));
669
670 - SetICUDefaultLocale("zh-SG");
671 + SetDefaultLocaleForTest("zh-SG", env.get());
672 EXPECT_EQ("zh-CN", l10n_util::GetApplicationLocale(""));
673 #endif // defined (OS_CHROMEOS)
674
675 Index: base/i18n/rtl.cc
676 ===================================================================
677 --- base/i18n/rtl.cc (revision 63359)
678 +++ base/i18n/rtl.cc (working copy)
679 @@ -18,26 +18,58 @@
680 #include <gtk/gtk.h>
681 #endif
682
683 +namespace {
684 +
685 +// Extract language and country, ignore keywords, concatenate using dash.
686 +std::string GetLocaleString(const icu::Locale& locale) {
687 + const char* language = locale.getLanguage();
688 + const char* country = locale.getCountry();
689 +
690 + std::string result =
691 + (language != NULL && *language != '\0') ? language : "und";
692 +
693 + if (country != NULL && *country != '\0') {
694 + result += '-';
695 + result += country;
696 + }
697 +
698 + return result;
699 +}
700 +
701 +} // namespace
702 +
703 namespace base {
704 namespace i18n {
705
706 // Represents the locale-specific ICU text direction.
707 static TextDirection g_icu_text_direction = UNKNOWN_DIRECTION;
708
709 +#if defined(OS_WIN)
710 void GetLanguageAndRegionFromOS(std::string* lang, std::string* region) {
711 // Later we may have to change this to be OS-dependent so that
712 // it's not affected by ICU's default locale. It's all right
713 // to do this way because SetICUDefaultLocale is internal
714 // to this file and we know that it's not yet called when this function
715 // is called.
716 - icu::Locale locale = icu::Locale::getDefault();
717 + const icu::Locale& locale = icu::Locale::getDefault();
718 const char* language = locale.getLanguage();
719 const char* country = locale.getCountry();
720 DCHECK(language);
721 *lang = language;
722 *region = country;
723 }
724 +#endif
725
726 +// Convert the ICU default locale to a string.
727 +std::string GetConfiguredLocale() {
728 + return GetLocaleString(icu::Locale::getDefault());
729 +}
730 +
731 +// Convert the ICU canonicalized locale to a string.
732 +std::string GetCanonicalLocale(const char* locale) {
733 + return GetLocaleString(icu::Locale::createCanonical(locale));
734 +}
735 +
736 // Convert Chrome locale name to ICU locale name
737 std::string ICULocaleName(const std::string& locale_string) {
738 // If not Spanish, just return it.
739 @@ -50,13 +82,14 @@
740 // locale. If it's es-RR other than es-ES, map to es-RR. Otherwise, map
741 // to es-MX (the most populous in Spanish-speaking Latin America).
742 if (LowerCaseEqualsASCII(locale_string, "es-419")) {
743 - std::string lang, region;
744 - GetLanguageAndRegionFromOS(&lang, &region);
745 - if (LowerCaseEqualsASCII(lang, "es") &&
746 - !LowerCaseEqualsASCII(region, "es")) {
747 - lang.append("-");
748 - lang.append(region);
749 - return lang;
750 + const icu::Locale& locale = icu::Locale::getDefault();
751 + std::string language = locale.getLanguage();
752 + const char* country = locale.getCountry();
753 + if (LowerCaseEqualsASCII(language, "es") &&
754 + !LowerCaseEqualsASCII(country, "es")) {
755 + language += '-';
756 + language += country;
757 + return language;
758 }
759 return "es-MX";
760 }
761 Index: base/i18n/rtl.h
762 ===================================================================
763 --- base/i18n/rtl.h (revision 63359)
764 +++ base/i18n/rtl.h (working copy)
765 @@ -29,9 +29,19 @@
766 LEFT_TO_RIGHT,
767 };
768
769 -// Get language and region from the OS.
770 +#if defined(OS_WIN)
771 +// Get language and region from the OS. Used by Chrome Frame.
772 void GetLanguageAndRegionFromOS(std::string* lang, std::string* region);
773 +#endif
774
775 +// Get the locale that the currently running process has been configured to use.
776 +// The return value is of the form language[-country] (e.g., en-US) where the
777 +// language is the 2 or 3 letter code from ISO-639.
778 +std::string GetConfiguredLocale();
779 +
780 +// Canonicalize a string (eg. a POSIX locale string) to a Chrome locale name.
781 +std::string GetCanonicalLocale(const char* locale);
782 +
783 // Sets the default locale of ICU.
784 // Once the application locale of Chrome in GetApplicationLocale is determined,
785 // the default locale of ICU need to be changed to match the application locale
786 @@ -136,7 +146,7 @@
787 // string is wrapped with LRE (Left-To-Right Embedding) and PDF (Pop
788 // Directional Formatting) marks and returned. In LTR locale, the string itself
789 // is returned.
790 -string16 GetDisplayStringInLTRDirectionality(const string16& text)
791 +string16 GetDisplayStringInLTRDirectionality(const string16& text)
792 WARN_UNUSED_RESULT;
793
794 // Strip the beginning (U+202A..U+202B, U+202D..U+202E) and/or ending (U+202C)
795 --- app/l10n_util.cc.orig 2010-11-04 19:18:08.000000000 +0100
796 +++ app/l10n_util.cc 2010-11-04 19:18:41.000000000 +0100
797 @@ -314,59 +314,6 @@
798
799 return false;
800 }
801 -
802 -// Get the locale of the operating system. The return value is of the form
803 -// language[-country] (e.g., en-US) where the language is the 2 letter code from
804 -// ISO-639.
805 -std::string GetSystemLocale() {
806 - std::string language, region;
807 - base::i18n::GetLanguageAndRegionFromOS(&language, &region);
808 - std::string ret;
809 - if (!language.empty())
810 - ret.append(language);
811 - if (!region.empty()) {
812 - ret.append("-");
813 - ret.append(region);
814 - }
815 - return ret;
816 -}
817 -#endif
818 -
819 -#if defined(OS_POSIX) && !defined(OS_MACOSX)
820 -// Split and normalize the language list specified by LANGUAGE environment.
821 -// LANGUAGE environment specifies a priority list of user prefered locales for
822 -// application UI messages. Locales are separated by ':' character. The format
823 -// of a locale is: language[_territory[.codeset]][@modifier]
824 -//
825 -// This function splits the language list and normalizes each locale into
826 -// language[-territory] format, eg. fr, zh-CN, etc.
827 -void SplitAndNormalizeLanguageList(const std::string& env_language,
828 - std::vector<std::string>* result) {
829 - std::vector<std::string> langs;
830 - SplitString(env_language, ':', &langs);
831 - std::vector<std::string>::iterator i = langs.begin();
832 - for (; i != langs.end(); ++i) {
833 - size_t end_pos = i->find_first_of(".@");
834 - // Erase encoding and modifier part.
835 - if (end_pos != std::string::npos)
836 - i->erase(end_pos);
837 -
838 - if (!i->empty()) {
839 - std::string locale;
840 - size_t sep = i->find_first_of("_-");
841 - if (sep != std::string::npos) {
842 - // language part is always in lower case.
843 - locale = StringToLowerASCII(i->substr(0, sep));
844 - locale.append("-");
845 - // territory part is always in upper case.
846 - locale.append(StringToUpperASCII(i->substr(sep + 1)));
847 - } else {
848 - locale = StringToLowerASCII(*i);
849 - }
850 - result->push_back(locale);
851 - }
852 - }
853 -}
854 #endif
855
856 // On Linux, the text layout engine Pango determines paragraph directionality