1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/base/l10n/l10n_util.h"
12 #include "base/command_line.h"
13 #include "base/compiler_specific.h"
14 #include "base/file_util.h"
15 #include "base/i18n/file_util_icu.h"
16 #include "base/i18n/rtl.h"
17 #include "base/i18n/string_compare.h"
18 #include "base/lazy_instance.h"
19 #include "base/memory/scoped_ptr.h"
20 #include "base/path_service.h"
21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/string_split.h"
23 #include "base/strings/string_util.h"
24 #include "base/strings/stringprintf.h"
25 #include "base/strings/sys_string_conversions.h"
26 #include "base/strings/utf_string_conversions.h"
27 #include "build/build_config.h"
28 #include "third_party/icu/source/common/unicode/rbbi.h"
29 #include "third_party/icu/source/common/unicode/uloc.h"
30 #include "ui/base/l10n/l10n_util_collator.h"
31 #include "ui/base/l10n/l10n_util_plurals.h"
32 #include "ui/base/resource/resource_bundle.h"
33 #include "ui/base/ui_base_paths.h"
35 #if defined(OS_ANDROID)
36 #include "ui/base/l10n/l10n_util_android.h"
39 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
44 #include "ui/base/l10n/l10n_util_win.h"
49 static const char* const kAcceptLanguageList[] = {
66 "de-AT", // German (Austria)
67 "de-CH", // German (Switzerland)
68 "de-DE", // German (Germany)
71 "en-AU", // English (Australia)
72 "en-CA", // English (Canada)
73 "en-GB", // English (UK)
74 "en-NZ", // English (New Zealand)
75 "en-US", // English (US)
76 "en-ZA", // English (South Africa)
78 // TODO(jungshik) : Do we want to list all es-Foo for Latin-American
79 // Spanish speaking countries?
81 "es-419", // Spanish (Latin America)
89 "fr-CA", // French (Canada)
90 "fr-CH", // French (Switzerland)
91 "fr-FR", // French (France)
109 "it-CH", // Italian (Switzerland)
110 "it-IT", // Italian (Italy)
132 "nb", // Norwegian (Bokmal)
135 "nn", // Norwegian (Nynorsk)
144 "pt-BR", // Portuguese (Brazil)
145 "pt-PT", // Portuguese (Portugal)
151 "sh", // Serbo-Croatian
182 "zh-CN", // Chinese (Simplified)
183 "zh-TW", // Chinese (Traditional)
187 // Returns true if |locale_name| has an alias in the ICU data file.
188 bool IsDuplicateName(const std::string& locale_name) {
189 static const char* const kDuplicateNames[] = {
200 // Skip all 'es_RR'. Currently, we use 'es' for es-ES (Spanish in Spain).
201 // 'es-419' (Spanish in Latin America) is not available in ICU so that it
202 // has to be added manually in GetAvailableLocales().
203 if (LowerCaseEqualsASCII(locale_name.substr(0, 3), "es_"))
205 for (size_t i = 0; i < arraysize(kDuplicateNames); ++i) {
206 if (base::strcasecmp(kDuplicateNames[i], locale_name.c_str()) == 0)
212 // We added 30+ minimally populated locales with only a few entries
213 // (exemplar character set, script, writing direction and its own
214 // lanaguage name). These locales have to be distinguished from the
215 // fully populated locales to which Chrome is localized.
216 bool IsLocalePartiallyPopulated(const std::string& locale_name) {
217 // For partially populated locales, even the translation for "English"
218 // is not available. A more robust/elegant way to check is to add a special
219 // field (say, 'isPartial' to our version of ICU locale files) and
220 // check its value, but this hack seems to work well.
221 return !l10n_util::IsLocaleNameTranslated("en", locale_name);
224 #if !defined(OS_MACOSX)
225 bool IsLocaleAvailable(const std::string& locale) {
226 // If locale has any illegal characters in it, we don't want to try to
227 // load it because it may be pointing outside the locale data file directory.
228 if (!file_util::IsFilenameLegal(ASCIIToUTF16(locale)))
231 // IsLocalePartiallyPopulated() can be called here for an early return w/o
232 // checking the resource availability below. It'd help when Chrome is run
233 // under a system locale Chrome is not localized to (e.g.Farsi on Linux),
234 // but it'd slow down the start up time a little bit for locales Chrome is
235 // localized to. So, we don't call it here.
236 if (!l10n_util::IsLocaleSupportedByOS(locale))
239 // If the ResourceBundle is not yet initialized, return false to avoid the
240 // CHECK failure in ResourceBundle::GetSharedInstance().
241 if (!ResourceBundle::HasSharedInstance())
244 // TODO(hshi): make ResourceBundle::LocaleDataPakExists() a static function
245 // so that this can be invoked without initializing the global instance.
246 // See crbug.com/230432: CHECK failure in GetUserDataDir().
247 return ResourceBundle::GetSharedInstance().LocaleDataPakExists(locale);
251 // On Linux, the text layout engine Pango determines paragraph directionality
252 // by looking at the first strongly-directional character in the text. This
253 // means text such as "Google Chrome foo bar..." will be layed out LTR even
254 // if "foo bar" is RTL. So this function prepends the necessary RLM in such
256 void AdjustParagraphDirectionality(string16* paragraph) {
257 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
258 if (base::i18n::IsRTL() &&
259 base::i18n::StringContainsStrongRTLChars(*paragraph)) {
260 paragraph->insert(0, 1, static_cast<char16>(base::i18n::kRightToLeftMark));
266 std::string GetCanonicalLocale(const std::string& locale) {
267 return base::i18n::GetCanonicalLocale(locale.c_str());
271 struct AvailableLocalesTraits
272 : base::DefaultLazyInstanceTraits<std::vector<std::string> > {
273 static std::vector<std::string>* New(void* instance) {
274 std::vector<std::string>* locales =
275 base::DefaultLazyInstanceTraits<std::vector<std::string> >::New(
277 int num_locales = uloc_countAvailable();
278 for (int i = 0; i < num_locales; ++i) {
279 std::string locale_name = uloc_getAvailable(i);
280 // Filter out the names that have aliases.
281 if (IsDuplicateName(locale_name))
283 // Filter out locales for which we have only partially populated data
284 // and to which Chrome is not localized.
285 if (IsLocalePartiallyPopulated(locale_name))
287 if (!l10n_util::IsLocaleSupportedByOS(locale_name))
289 // Normalize underscores to hyphens because that's what our locale files
291 std::replace(locale_name.begin(), locale_name.end(), '_', '-');
293 // Map the Chinese locale names over to zh-CN and zh-TW.
294 if (LowerCaseEqualsASCII(locale_name, "zh-hans")) {
295 locale_name = "zh-CN";
296 } else if (LowerCaseEqualsASCII(locale_name, "zh-hant")) {
297 locale_name = "zh-TW";
299 locales->push_back(locale_name);
302 // Manually add 'es-419' to the list. See the comment in IsDuplicateName().
303 locales->push_back("es-419");
308 base::LazyInstance<std::vector<std::string>, AvailableLocalesTraits>
309 g_available_locales = LAZY_INSTANCE_INITIALIZER;
313 namespace l10n_util {
315 bool CheckAndResolveLocale(const std::string& locale,
316 std::string* resolved_locale) {
317 #if defined(OS_MACOSX)
321 if (IsLocaleAvailable(locale)) {
322 *resolved_locale = locale;
326 // If there's a variant, skip over it so we can try without the region
327 // code. For example, ca_ES@valencia should cause us to try ca@valencia
329 std::string::size_type variant_pos = locale.find('@');
330 if (variant_pos != std::string::npos)
333 // If the locale matches language but not country, use that instead.
334 // TODO(jungshik) : Nothing is done about languages that Chrome
335 // does not support but available on Windows. We fall
336 // back to en-US in GetApplicationLocale so that it's a not critical,
337 // but we can do better.
338 std::string::size_type hyphen_pos = locale.find('-');
339 std::string lang(locale, 0, hyphen_pos);
340 if (hyphen_pos != std::string::npos && hyphen_pos > 0) {
341 std::string region(locale, hyphen_pos + 1);
342 std::string tmp_locale(lang);
343 // Map es-RR other than es-ES to es-419 (Chrome's Latin American
345 if (LowerCaseEqualsASCII(lang, "es") &&
346 !LowerCaseEqualsASCII(region, "es")) {
347 tmp_locale.append("-419");
348 } else if (LowerCaseEqualsASCII(lang, "zh")) {
349 // Map zh-HK and zh-MO to zh-TW. Otherwise, zh-FOO is mapped to zh-CN.
350 if (LowerCaseEqualsASCII(region, "hk") ||
351 LowerCaseEqualsASCII(region, "mo")) { // Macao
352 tmp_locale.append("-TW");
354 tmp_locale.append("-CN");
356 } else if (LowerCaseEqualsASCII(lang, "en")) {
357 // Map Australian, Canadian, New Zealand and South African English
358 // to British English for now.
359 // TODO(jungshik): en-CA may have to change sides once
360 // we have OS locale separate from app locale (Chrome's UI language).
361 if (LowerCaseEqualsASCII(region, "au") ||
362 LowerCaseEqualsASCII(region, "ca") ||
363 LowerCaseEqualsASCII(region, "nz") ||
364 LowerCaseEqualsASCII(region, "za")) {
365 tmp_locale.append("-GB");
367 tmp_locale.append("-US");
370 if (IsLocaleAvailable(tmp_locale)) {
371 resolved_locale->swap(tmp_locale);
376 // Google updater uses no, tl, iw and en for our nb, fil, he, and en-US.
387 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(alias_map); ++i) {
388 if (LowerCaseEqualsASCII(lang, alias_map[i].source)) {
389 std::string tmp_locale(alias_map[i].dest);
390 if (IsLocaleAvailable(tmp_locale)) {
391 resolved_locale->swap(tmp_locale);
401 std::string GetApplicationLocale(const std::string& pref_locale) {
402 #if defined(OS_MACOSX)
404 // Use any override (Cocoa for the browser), otherwise use the preference
405 // passed to the function.
406 std::string app_locale = l10n_util::GetLocaleOverride();
407 if (app_locale.empty())
408 app_locale = pref_locale;
410 // The above should handle all of the cases Chrome normally hits, but for some
411 // unit tests, we need something to fall back too.
412 if (app_locale.empty())
413 app_locale = "en-US";
415 // Windows/Linux call SetICUDefaultLocale after determining the actual locale
416 // with CheckAndResolveLocal to make ICU APIs work in that locale.
417 // Mac doesn't use a locale directory tree of resources (it uses Mac style
418 // resources), so mirror the Windows/Linux behavior of calling
419 // SetICUDefaultLocale.
420 base::i18n::SetICUDefaultLocale(app_locale);
425 std::string resolved_locale;
426 std::vector<std::string> candidates;
428 // We only use --lang and the app pref on Windows. On Linux, we only
429 // look at the LC_*/LANG environment variables. We do, however, pass --lang
430 // to renderer and plugin processes so they know what language the parent
431 // process decided to use.
435 // First, try the preference value.
436 if (!pref_locale.empty())
437 candidates.push_back(GetCanonicalLocale(pref_locale));
439 // Next, try the overridden locale.
440 const std::vector<std::string>& languages = l10n_util::GetLocaleOverrides();
441 if (!languages.empty()) {
442 candidates.reserve(candidates.size() + languages.size());
443 std::transform(languages.begin(), languages.end(),
444 std::back_inserter(candidates), &GetCanonicalLocale);
446 // If no override was set, defer to ICU
447 candidates.push_back(base::i18n::GetConfiguredLocale());
450 #elif defined(OS_CHROMEOS) || (defined(USE_AURA) && !defined(OS_LINUX))
452 // On ChromeOS, use the application locale preference.
453 if (!pref_locale.empty())
454 candidates.push_back(pref_locale);
456 #elif defined(OS_ANDROID)
458 // On Android, query java.util.Locale for the default locale.
459 candidates.push_back(GetDefaultLocale());
461 #elif defined(OS_POSIX)
462 // If we're on a different Linux system, we have glib.
464 // GLib implements correct environment variable parsing with
465 // the precedence order: LANGUAGE, LC_ALL, LC_MESSAGES and LANG.
466 // We used to use our custom parsing code along with ICU for this purpose.
467 // If we have a port that does not depend on GTK, we have to
468 // restore our custom code for that port.
469 const char* const* languages = g_get_language_names();
470 DCHECK(languages); // A valid pointer is guaranteed.
471 DCHECK(*languages); // At least one entry, "C", is guaranteed.
473 for (; *languages != NULL; ++languages) {
474 candidates.push_back(base::i18n::GetCanonicalLocale(*languages));
478 #error Unsupported platform, see build/build_config.h
481 std::vector<std::string>::const_iterator i = candidates.begin();
482 for (; i != candidates.end(); ++i) {
483 if (CheckAndResolveLocale(*i, &resolved_locale)) {
484 base::i18n::SetICUDefaultLocale(resolved_locale);
485 return resolved_locale;
489 // Fallback on en-US.
490 const std::string fallback_locale("en-US");
491 if (IsLocaleAvailable(fallback_locale)) {
492 base::i18n::SetICUDefaultLocale(fallback_locale);
493 return fallback_locale;
496 return std::string();
501 bool IsLocaleNameTranslated(const char* locale,
502 const std::string& display_locale) {
503 string16 display_name =
504 l10n_util::GetDisplayNameForLocale(locale, display_locale, false);
505 // Because ICU sets the error code to U_USING_DEFAULT_WARNING whether or not
506 // uloc_getDisplayName returns the actual translation or the default
507 // value (locale code), we have to rely on this hack to tell whether
508 // the translation is available or not. If ICU doesn't have a translated
509 // name for this locale, GetDisplayNameForLocale will just return the
511 return !IsStringASCII(display_name) || UTF16ToASCII(display_name) != locale;
514 string16 GetDisplayNameForLocale(const std::string& locale,
515 const std::string& display_locale,
517 std::string locale_code = locale;
518 // Internally, we use the language code of zh-CN and zh-TW, but we want the
519 // display names to be Chinese (Simplified) and Chinese (Traditional) instead
520 // of Chinese (China) and Chinese (Taiwan). To do that, we pass zh-Hans
521 // and zh-Hant to ICU. Even with this mapping, we'd get
522 // 'Chinese (Simplified Han)' and 'Chinese (Traditional Han)' in English and
523 // even longer results in other languages. Arguably, they're better than
524 // the current results : Chinese (China) / Chinese (Taiwan).
525 // TODO(jungshik): Do one of the following:
526 // 1. Special-case Chinese by getting the custom-translation for them
527 // 2. Recycle IDS_ENCODING_{SIMP,TRAD}_CHINESE.
528 // 3. Get translations for two directly from the ICU resouce bundle
529 // because they're not accessible with other any API.
530 // 4. Patch ICU to special-case zh-Hans/zh-Hant for us.
531 // #1 and #2 wouldn't work if display_locale != current UI locale although
532 // we can think of additional hack to work around the problem.
533 // #3 can be potentially expensive.
534 if (locale_code == "zh-CN")
535 locale_code = "zh-Hans";
536 else if (locale_code == "zh-TW")
537 locale_code = "zh-Hant";
539 string16 display_name;
540 #if defined(OS_ANDROID)
541 // Use Java API to get locale display name so that we can remove most of
542 // the lang data from icu data to reduce binary size, except for zh-Hans and
543 // zh-Hant because the current Android Java API doesn't support scripts.
544 // TODO(wangxianzhu): remove the special handling of zh-Hans and zh-Hant once
545 // Android Java API supports scripts.
546 if (!StartsWithASCII(locale_code, "zh-Han", true)) {
547 display_name = GetDisplayNameForLocale(locale_code, display_locale);
551 UErrorCode error = U_ZERO_ERROR;
552 const int kBufferSize = 1024;
554 int actual_size = uloc_getDisplayName(
555 locale_code.c_str(), display_locale.c_str(),
556 WriteInto(&display_name, kBufferSize), kBufferSize - 1, &error);
557 DCHECK(U_SUCCESS(error));
558 display_name.resize(actual_size);
561 // Add directional markup so parentheses are properly placed.
562 if (is_for_ui && base::i18n::IsRTL())
563 base::i18n::AdjustStringForLocaleDirection(&display_name);
567 string16 GetDisplayNameForCountry(const std::string& country_code,
568 const std::string& display_locale) {
569 return GetDisplayNameForLocale("_" + country_code, display_locale, false);
572 std::string NormalizeLocale(const std::string& locale) {
573 std::string normalized_locale(locale);
574 std::replace(normalized_locale.begin(), normalized_locale.end(), '-', '_');
576 return normalized_locale;
579 void GetParentLocales(const std::string& current_locale,
580 std::vector<std::string>* parent_locales) {
581 std::string locale(NormalizeLocale(current_locale));
583 const int kNameCapacity = 256;
584 char parent[kNameCapacity];
585 base::strlcpy(parent, locale.c_str(), kNameCapacity);
586 parent_locales->push_back(parent);
587 UErrorCode err = U_ZERO_ERROR;
588 while (uloc_getParent(parent, parent, kNameCapacity, &err) > 0) {
591 parent_locales->push_back(parent);
595 bool IsValidLocaleSyntax(const std::string& locale) {
596 // Check that the length is plausible.
597 if (locale.size() < 2 || locale.size() >= ULOC_FULLNAME_CAPACITY)
600 // Strip off the part after an '@' sign, which might contain keywords,
601 // as in en_IE@currency=IEP or fr@collation=phonebook;calendar=islamic-civil.
602 // We don't validate that part much, just check that there's at least one
603 // equals sign in a plausible place. Normalize the prefix so that hyphens
604 // are changed to underscores.
605 std::string prefix = NormalizeLocale(locale);
606 size_t split_point = locale.find("@");
607 if (split_point != std::string::npos) {
608 std::string keywords = locale.substr(split_point + 1);
609 prefix = locale.substr(0, split_point);
611 size_t equals_loc = keywords.find("=");
612 if (equals_loc == std::string::npos ||
613 equals_loc < 1 || equals_loc > keywords.size() - 2)
617 // Check that all characters before the at-sign are alphanumeric or
619 for (size_t i = 0; i < prefix.size(); i++) {
621 if (!IsAsciiAlpha(ch) && !IsAsciiDigit(ch) && ch != '_')
625 // Check that the initial token (before the first hyphen/underscore)
626 // is 1 - 3 alphabetical characters (a language tag).
627 for (size_t i = 0; i < prefix.size(); i++) {
634 if (!IsAsciiAlpha(ch))
638 // Check that the all tokens after the initial token are 1 - 8 characters.
639 // (Tokenize/StringTokenizer don't work here, they collapse multiple
640 // delimiters into one.)
643 for (size_t i = 0; i < prefix.size(); i++) {
644 if (prefix[i] != '_') {
649 if (token_index > 0 && (token_len < 1 || token_len > 8)) {
655 if (token_index == 0 && (token_len < 1 || token_len > 3)) {
657 } else if (token_len < 1 || token_len > 8) {
664 std::string GetStringUTF8(int message_id) {
665 return UTF16ToUTF8(GetStringUTF16(message_id));
668 string16 GetStringUTF16(int message_id) {
669 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
670 string16 str = rb.GetLocalizedString(message_id);
671 AdjustParagraphDirectionality(&str);
676 string16 GetStringFUTF16(int message_id,
677 const std::vector<string16>& replacements,
678 std::vector<size_t>* offsets) {
679 // TODO(tc): We could save a string copy if we got the raw string as
680 // a StringPiece and were able to call ReplaceStringPlaceholders with
681 // a StringPiece format string and string16 substitution strings. In
682 // practice, the strings should be relatively short.
683 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
684 const string16& format_string = rb.GetLocalizedString(message_id);
687 // Make sure every replacement string is being used, so we don't just
688 // silently fail to insert one. If |offsets| is non-NULL, then don't do this
689 // check as the code may simply want to find the placeholders rather than
690 // actually replacing them.
692 std::string utf8_string = UTF16ToUTF8(format_string);
694 // $9 is the highest allowed placeholder.
695 for (size_t i = 0; i < 9; ++i) {
696 bool placeholder_should_exist = replacements.size() > i;
698 std::string placeholder =
699 base::StringPrintf("$%d", static_cast<int>(i + 1));
700 size_t pos = utf8_string.find(placeholder.c_str());
701 if (placeholder_should_exist) {
702 DCHECK_NE(std::string::npos, pos) <<
703 " Didn't find a " << placeholder << " placeholder in " <<
706 DCHECK_EQ(std::string::npos, pos) <<
707 " Unexpectedly found a " << placeholder << " placeholder in " <<
714 string16 formatted = ReplaceStringPlaceholders(format_string, replacements,
716 AdjustParagraphDirectionality(&formatted);
721 std::string GetStringFUTF8(int message_id,
723 return UTF16ToUTF8(GetStringFUTF16(message_id, a));
726 std::string GetStringFUTF8(int message_id,
729 return UTF16ToUTF8(GetStringFUTF16(message_id, a, b));
732 std::string GetStringFUTF8(int message_id,
736 return UTF16ToUTF8(GetStringFUTF16(message_id, a, b, c));
739 std::string GetStringFUTF8(int message_id,
744 return UTF16ToUTF8(GetStringFUTF16(message_id, a, b, c, d));
747 string16 GetStringFUTF16(int message_id,
749 std::vector<string16> replacements;
750 replacements.push_back(a);
751 return GetStringFUTF16(message_id, replacements, NULL);
754 string16 GetStringFUTF16(int message_id,
757 return GetStringFUTF16(message_id, a, b, NULL);
760 string16 GetStringFUTF16(int message_id,
764 std::vector<string16> replacements;
765 replacements.push_back(a);
766 replacements.push_back(b);
767 replacements.push_back(c);
768 return GetStringFUTF16(message_id, replacements, NULL);
771 string16 GetStringFUTF16(int message_id,
776 std::vector<string16> replacements;
777 replacements.push_back(a);
778 replacements.push_back(b);
779 replacements.push_back(c);
780 replacements.push_back(d);
781 return GetStringFUTF16(message_id, replacements, NULL);
784 string16 GetStringFUTF16(int message_id,
790 std::vector<string16> replacements;
791 replacements.push_back(a);
792 replacements.push_back(b);
793 replacements.push_back(c);
794 replacements.push_back(d);
795 replacements.push_back(e);
796 return GetStringFUTF16(message_id, replacements, NULL);
799 string16 GetStringFUTF16(int message_id, const string16& a, size_t* offset) {
801 std::vector<size_t> offsets;
802 std::vector<string16> replacements;
803 replacements.push_back(a);
804 string16 result = GetStringFUTF16(message_id, replacements, &offsets);
805 DCHECK(offsets.size() == 1);
806 *offset = offsets[0];
810 string16 GetStringFUTF16(int message_id,
813 std::vector<size_t>* offsets) {
814 std::vector<string16> replacements;
815 replacements.push_back(a);
816 replacements.push_back(b);
817 return GetStringFUTF16(message_id, replacements, offsets);
820 string16 GetStringFUTF16Int(int message_id, int a) {
821 return GetStringFUTF16(message_id, UTF8ToUTF16(base::IntToString(a)));
824 string16 GetStringFUTF16Int(int message_id, int64 a) {
825 return GetStringFUTF16(message_id, UTF8ToUTF16(base::Int64ToString(a)));
828 // Specialization of operator() method for string16 version.
830 bool StringComparator<string16>::operator()(const string16& lhs,
831 const string16& rhs) {
832 // If we can not get collator instance for specified locale, just do simple
836 return base::i18n::CompareString16WithCollator(collator_, lhs, rhs) ==
840 string16 GetPluralStringFUTF16(const std::vector<int>& message_ids,
842 scoped_ptr<icu::PluralFormat> format = BuildPluralFormat(message_ids);
845 UErrorCode err = U_ZERO_ERROR;
846 icu::UnicodeString result_files_string = format->format(number, err);
847 int capacity = result_files_string.length() + 1;
848 DCHECK_GT(capacity, 1);
850 result_files_string.extract(
851 static_cast<UChar*>(WriteInto(&result, capacity)), capacity, err);
852 DCHECK(U_SUCCESS(err));
856 std::string GetPluralStringFUTF8(const std::vector<int>& message_ids,
858 return base::UTF16ToUTF8(GetPluralStringFUTF16(message_ids, number));
861 void SortStrings16(const std::string& locale,
862 std::vector<string16>* strings) {
863 SortVectorWithStringKey(locale, strings, false);
866 const std::vector<std::string>& GetAvailableLocales() {
867 return g_available_locales.Get();
870 void GetAcceptLanguagesForLocale(const std::string& display_locale,
871 std::vector<std::string>* locale_codes) {
872 for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) {
873 if (!l10n_util::IsLocaleNameTranslated(kAcceptLanguageList[i],
875 // TODO(jungshik) : Put them at the of the list with language codes
876 // enclosed by brackets instead of skipping.
878 locale_codes->push_back(kAcceptLanguageList[i]);
882 int GetLocalizedContentsWidthInPixels(int pixel_resource_id) {
884 base::StringToInt(l10n_util::GetStringUTF8(pixel_resource_id), &width);
889 } // namespace l10n_util