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/files/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/strings/string_number_conversions.h"
21 #include "base/strings/string_split.h"
22 #include "base/strings/string_util.h"
23 #include "base/strings/stringprintf.h"
24 #include "base/strings/sys_string_conversions.h"
25 #include "base/strings/utf_string_conversions.h"
26 #include "build/build_config.h"
27 #include "third_party/icu/source/common/unicode/rbbi.h"
28 #include "third_party/icu/source/common/unicode/uloc.h"
29 #include "ui/base/l10n/l10n_util_collator.h"
30 #include "ui/base/l10n/l10n_util_plurals.h"
31 #include "ui/base/resource/resource_bundle.h"
32 #include "ui/base/ui_base_paths.h"
34 #if defined(OS_ANDROID)
35 #include "base/android/locale_utils.h"
36 #include "ui/base/l10n/l10n_util_android.h"
44 #include "ui/base/l10n/l10n_util_win.h"
49 static const char* const kAcceptLanguageList
[] = {
61 "ckb", // Kurdish (Arabci), Sorani
67 "de-AT", // German (Austria)
68 "de-CH", // German (Switzerland)
69 "de-DE", // German (Germany)
70 "de-LI", // German (Liechtenstein)
73 "en-AU", // English (Australia)
74 "en-CA", // English (Canada)
75 "en-GB", // English (UK)
76 "en-NZ", // English (New Zealand)
77 "en-US", // English (US)
78 "en-ZA", // English (South Africa)
80 // TODO(jungshik) : Do we want to list all es-Foo for Latin-American
81 // Spanish speaking countries?
83 "es-419", // Spanish (Latin America)
91 "fr-CA", // French (Canada)
92 "fr-CH", // French (Switzerland)
93 "fr-FR", // French (France)
111 "it-CH", // Italian (Switzerland)
112 "it-IT", // Italian (Italy)
134 "nb", // Norwegian (Bokmal)
137 "nn", // Norwegian (Nynorsk)
146 "pt-BR", // Portuguese (Brazil)
147 "pt-PT", // Portuguese (Portugal)
153 "sh", // Serbo-Croatian
184 "zh-CN", // Chinese (Simplified)
185 "zh-TW", // Chinese (Traditional)
189 // Returns true if |locale_name| has an alias in the ICU data file.
190 bool IsDuplicateName(const std::string
& locale_name
) {
191 static const char* const kDuplicateNames
[] = {
194 "pt", // pt-BR and pt-PT are used.
203 // Skip all the es_Foo other than es_419 for now.
204 if (StartsWithASCII(locale_name
, "es_", false))
205 return !EndsWith(locale_name
, "419", true);
207 for (size_t i
= 0; i
< arraysize(kDuplicateNames
); ++i
) {
208 if (base::strcasecmp(kDuplicateNames
[i
], locale_name
.c_str()) == 0)
214 // We added 30+ minimally populated locales with only a few entries
215 // (exemplar character set, script, writing direction and its own
216 // lanaguage name). These locales have to be distinguished from the
217 // fully populated locales to which Chrome is localized.
218 bool IsLocalePartiallyPopulated(const std::string
& locale_name
) {
219 // For partially populated locales, even the translation for "English"
220 // is not available. A more robust/elegant way to check is to add a special
221 // field (say, 'isPartial' to our version of ICU locale files) and
222 // check its value, but this hack seems to work well.
223 return !l10n_util::IsLocaleNameTranslated("en", locale_name
);
226 #if !defined(OS_MACOSX)
227 bool IsLocaleAvailable(const std::string
& locale
) {
228 // If locale has any illegal characters in it, we don't want to try to
229 // load it because it may be pointing outside the locale data file directory.
230 if (!base::i18n::IsFilenameLegal(base::ASCIIToUTF16(locale
)))
233 // IsLocalePartiallyPopulated() can be called here for an early return w/o
234 // checking the resource availability below. It'd help when Chrome is run
235 // under a system locale Chrome is not localized to (e.g.Farsi on Linux),
236 // but it'd slow down the start up time a little bit for locales Chrome is
237 // localized to. So, we don't call it here.
238 if (!l10n_util::IsLocaleSupportedByOS(locale
))
241 // If the ResourceBundle is not yet initialized, return false to avoid the
242 // CHECK failure in ResourceBundle::GetSharedInstance().
243 if (!ResourceBundle::HasSharedInstance())
246 // TODO(hshi): make ResourceBundle::LocaleDataPakExists() a static function
247 // so that this can be invoked without initializing the global instance.
248 // See crbug.com/230432: CHECK failure in GetUserDataDir().
249 return ResourceBundle::GetSharedInstance().LocaleDataPakExists(locale
);
253 // On Linux, the text layout engine Pango determines paragraph directionality
254 // by looking at the first strongly-directional character in the text. This
255 // means text such as "Google Chrome foo bar..." will be layed out LTR even
256 // if "foo bar" is RTL. So this function prepends the necessary RLM in such
258 void AdjustParagraphDirectionality(base::string16
* paragraph
) {
259 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
260 if (base::i18n::IsRTL() &&
261 base::i18n::StringContainsStrongRTLChars(*paragraph
)) {
262 paragraph
->insert(0, 1,
263 static_cast<base::char16
>(base::i18n::kRightToLeftMark
));
268 struct AvailableLocalesTraits
269 : base::DefaultLazyInstanceTraits
<std::vector
<std::string
> > {
270 static std::vector
<std::string
>* New(void* instance
) {
271 std::vector
<std::string
>* locales
=
272 base::DefaultLazyInstanceTraits
<std::vector
<std::string
> >::New(
274 int num_locales
= uloc_countAvailable();
275 for (int i
= 0; i
< num_locales
; ++i
) {
276 std::string locale_name
= uloc_getAvailable(i
);
277 // Filter out the names that have aliases.
278 if (IsDuplicateName(locale_name
))
280 // Filter out locales for which we have only partially populated data
281 // and to which Chrome is not localized.
282 if (IsLocalePartiallyPopulated(locale_name
))
284 if (!l10n_util::IsLocaleSupportedByOS(locale_name
))
286 // Normalize underscores to hyphens because that's what our locale files
288 std::replace(locale_name
.begin(), locale_name
.end(), '_', '-');
290 // Map the Chinese locale names over to zh-CN and zh-TW.
291 if (LowerCaseEqualsASCII(locale_name
, "zh-hans")) {
292 locale_name
= "zh-CN";
293 } else if (LowerCaseEqualsASCII(locale_name
, "zh-hant")) {
294 locale_name
= "zh-TW";
296 locales
->push_back(locale_name
);
303 base::LazyInstance
<std::vector
<std::string
>, AvailableLocalesTraits
>
304 g_available_locales
= LAZY_INSTANCE_INITIALIZER
;
308 namespace l10n_util
{
310 std::string
GetLanguage(const std::string
& locale
) {
311 const std::string::size_type hyphen_pos
= locale
.find('-');
312 return std::string(locale
, 0, hyphen_pos
);
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 const std::string
lang(GetLanguage(locale
));
339 if (lang
.size() < locale
.size()) {
340 std::string
region(locale
, lang
.size() + 1);
341 std::string
tmp_locale(lang
);
342 // Map es-RR other than es-ES to es-419 (Chrome's Latin American
344 if (LowerCaseEqualsASCII(lang
, "es") &&
345 !LowerCaseEqualsASCII(region
, "es")) {
346 tmp_locale
.append("-419");
347 } else if (LowerCaseEqualsASCII(lang
, "zh")) {
348 // Map zh-HK and zh-MO to zh-TW. Otherwise, zh-FOO is mapped to zh-CN.
349 if (LowerCaseEqualsASCII(region
, "hk") ||
350 LowerCaseEqualsASCII(region
, "mo")) { // Macao
351 tmp_locale
.append("-TW");
353 tmp_locale
.append("-CN");
355 } else if (LowerCaseEqualsASCII(lang
, "en")) {
356 // Map Australian, Canadian, New Zealand and South African English
357 // to British English for now.
358 // TODO(jungshik): en-CA may have to change sides once
359 // we have OS locale separate from app locale (Chrome's UI language).
360 if (LowerCaseEqualsASCII(region
, "au") ||
361 LowerCaseEqualsASCII(region
, "ca") ||
362 LowerCaseEqualsASCII(region
, "nz") ||
363 LowerCaseEqualsASCII(region
, "za")) {
364 tmp_locale
.append("-GB");
366 tmp_locale
.append("-US");
369 if (IsLocaleAvailable(tmp_locale
)) {
370 resolved_locale
->swap(tmp_locale
);
375 // Google updater uses no, tl, iw and en for our nb, fil, he, and en-US.
386 for (size_t i
= 0; i
< arraysize(alias_map
); ++i
) {
387 if (LowerCaseEqualsASCII(lang
, alias_map
[i
].source
)) {
388 std::string
tmp_locale(alias_map
[i
].dest
);
389 if (IsLocaleAvailable(tmp_locale
)) {
390 resolved_locale
->swap(tmp_locale
);
400 std::string
GetApplicationLocaleInternal(const std::string
& pref_locale
) {
401 #if defined(OS_MACOSX)
403 // Use any override (Cocoa for the browser), otherwise use the preference
404 // passed to the function.
405 std::string app_locale
= l10n_util::GetLocaleOverride();
406 if (app_locale
.empty())
407 app_locale
= pref_locale
;
409 // The above should handle all of the cases Chrome normally hits, but for some
410 // unit tests, we need something to fall back too.
411 if (app_locale
.empty())
412 app_locale
= "en-US";
418 std::string resolved_locale
;
419 std::vector
<std::string
> candidates
;
421 // We only use --lang and the app pref on Windows. On Linux, we only
422 // look at the LC_*/LANG environment variables. We do, however, pass --lang
423 // to renderer and plugin processes so they know what language the parent
424 // process decided to use.
428 // First, try the preference value.
429 if (!pref_locale
.empty())
430 candidates
.push_back(base::i18n::GetCanonicalLocale(pref_locale
));
432 // Next, try the overridden locale.
433 const std::vector
<std::string
>& languages
= l10n_util::GetLocaleOverrides();
434 if (!languages
.empty()) {
435 candidates
.reserve(candidates
.size() + languages
.size());
436 std::transform(languages
.begin(), languages
.end(),
437 std::back_inserter(candidates
),
438 &base::i18n::GetCanonicalLocale
);
440 // If no override was set, defer to ICU
441 candidates
.push_back(base::i18n::GetConfiguredLocale());
444 #elif defined(OS_ANDROID)
446 // On Android, query java.util.Locale for the default locale.
447 candidates
.push_back(base::android::GetDefaultLocale());
449 #elif defined(USE_GLIB) && !defined(OS_CHROMEOS)
451 // GLib implements correct environment variable parsing with
452 // the precedence order: LANGUAGE, LC_ALL, LC_MESSAGES and LANG.
453 // We used to use our custom parsing code along with ICU for this purpose.
454 // If we have a port that does not depend on GTK, we have to
455 // restore our custom code for that port.
456 const char* const* languages
= g_get_language_names();
457 DCHECK(languages
); // A valid pointer is guaranteed.
458 DCHECK(*languages
); // At least one entry, "C", is guaranteed.
460 for (; *languages
!= NULL
; ++languages
) {
461 candidates
.push_back(base::i18n::GetCanonicalLocale(*languages
));
466 // By default, use the application locale preference. This applies to ChromeOS
467 // and linux systems without glib.
468 if (!pref_locale
.empty())
469 candidates
.push_back(pref_locale
);
473 std::vector
<std::string
>::const_iterator i
= candidates
.begin();
474 for (; i
!= candidates
.end(); ++i
) {
475 if (CheckAndResolveLocale(*i
, &resolved_locale
)) {
476 return resolved_locale
;
480 // Fallback on en-US.
481 const std::string
fallback_locale("en-US");
482 if (IsLocaleAvailable(fallback_locale
)) {
483 return fallback_locale
;
486 return std::string();
491 std::string
GetApplicationLocale(const std::string
& pref_locale
,
492 bool set_icu_locale
) {
493 const std::string locale
= GetApplicationLocaleInternal(pref_locale
);
494 if (set_icu_locale
&& !locale
.empty())
495 base::i18n::SetICUDefaultLocale(locale
);
499 std::string
GetApplicationLocale(const std::string
& pref_locale
) {
500 return GetApplicationLocale(pref_locale
, true /* set_icu_locale */);
503 bool IsLocaleNameTranslated(const char* locale
,
504 const std::string
& display_locale
) {
505 base::string16 display_name
=
506 l10n_util::GetDisplayNameForLocale(locale
, display_locale
, false);
507 // Because ICU sets the error code to U_USING_DEFAULT_WARNING whether or not
508 // uloc_getDisplayName returns the actual translation or the default
509 // value (locale code), we have to rely on this hack to tell whether
510 // the translation is available or not. If ICU doesn't have a translated
511 // name for this locale, GetDisplayNameForLocale will just return the
513 return !base::IsStringASCII(display_name
) ||
514 base::UTF16ToASCII(display_name
) != locale
;
517 base::string16
GetDisplayNameForLocale(const std::string
& locale
,
518 const std::string
& display_locale
,
520 std::string locale_code
= locale
;
521 // Internally, we use the language code of zh-CN and zh-TW, but we want the
522 // display names to be Chinese (Simplified) and Chinese (Traditional) instead
523 // of Chinese (China) and Chinese (Taiwan).
524 // Translate uses "tl" (Tagalog) to mean "fil" (Filipino) until Google
525 // translate is changed to understand "fil". Make "tl" alias to "fil".
526 if (locale_code
== "zh-CN")
527 locale_code
= "zh-Hans";
528 else if (locale_code
== "zh-TW")
529 locale_code
= "zh-Hant";
530 else if (locale_code
== "tl")
532 else if (locale_code
== "mo")
533 locale_code
= "ro-MD";
535 base::string16 display_name
;
536 #if defined(OS_ANDROID)
537 // Use Java API to get locale display name so that we can remove most of
538 // the lang data from icu data to reduce binary size, except for zh-Hans and
539 // zh-Hant because the current Android Java API doesn't support scripts.
540 // TODO(wangxianzhu): remove the special handling of zh-Hans and zh-Hant once
541 // Android Java API supports scripts.
542 if (!StartsWithASCII(locale_code
, "zh-Han", true)) {
543 display_name
= GetDisplayNameForLocale(locale_code
, display_locale
);
547 UErrorCode error
= U_ZERO_ERROR
;
548 const int kBufferSize
= 1024;
550 int actual_size
= uloc_getDisplayName(
551 locale_code
.c_str(), display_locale
.c_str(),
552 WriteInto(&display_name
, kBufferSize
), kBufferSize
- 1, &error
);
553 DCHECK(U_SUCCESS(error
));
554 display_name
.resize(actual_size
);
557 // Add directional markup so parentheses are properly placed.
558 if (is_for_ui
&& base::i18n::IsRTL())
559 base::i18n::AdjustStringForLocaleDirection(&display_name
);
563 base::string16
GetDisplayNameForCountry(const std::string
& country_code
,
564 const std::string
& display_locale
) {
565 return GetDisplayNameForLocale("_" + country_code
, display_locale
, false);
568 std::string
NormalizeLocale(const std::string
& locale
) {
569 std::string
normalized_locale(locale
);
570 std::replace(normalized_locale
.begin(), normalized_locale
.end(), '-', '_');
572 return normalized_locale
;
575 void GetParentLocales(const std::string
& current_locale
,
576 std::vector
<std::string
>* parent_locales
) {
577 std::string
locale(NormalizeLocale(current_locale
));
579 const int kNameCapacity
= 256;
580 char parent
[kNameCapacity
];
581 base::strlcpy(parent
, locale
.c_str(), kNameCapacity
);
582 parent_locales
->push_back(parent
);
583 UErrorCode err
= U_ZERO_ERROR
;
584 while (uloc_getParent(parent
, parent
, kNameCapacity
, &err
) > 0) {
587 parent_locales
->push_back(parent
);
591 bool IsValidLocaleSyntax(const std::string
& locale
) {
592 // Check that the length is plausible.
593 if (locale
.size() < 2 || locale
.size() >= ULOC_FULLNAME_CAPACITY
)
596 // Strip off the part after an '@' sign, which might contain keywords,
597 // as in en_IE@currency=IEP or fr@collation=phonebook;calendar=islamic-civil.
598 // We don't validate that part much, just check that there's at least one
599 // equals sign in a plausible place. Normalize the prefix so that hyphens
600 // are changed to underscores.
601 std::string prefix
= NormalizeLocale(locale
);
602 size_t split_point
= locale
.find("@");
603 if (split_point
!= std::string::npos
) {
604 std::string keywords
= locale
.substr(split_point
+ 1);
605 prefix
= locale
.substr(0, split_point
);
607 size_t equals_loc
= keywords
.find("=");
608 if (equals_loc
== std::string::npos
||
609 equals_loc
< 1 || equals_loc
> keywords
.size() - 2)
613 // Check that all characters before the at-sign are alphanumeric or
615 for (size_t i
= 0; i
< prefix
.size(); i
++) {
617 if (!IsAsciiAlpha(ch
) && !IsAsciiDigit(ch
) && ch
!= '_')
621 // Check that the initial token (before the first hyphen/underscore)
622 // is 1 - 3 alphabetical characters (a language tag).
623 for (size_t i
= 0; i
< prefix
.size(); i
++) {
630 if (!IsAsciiAlpha(ch
))
634 // Check that the all tokens after the initial token are 1 - 8 characters.
635 // (Tokenize/StringTokenizer don't work here, they collapse multiple
636 // delimiters into one.)
639 for (size_t i
= 0; i
< prefix
.size(); i
++) {
640 if (prefix
[i
] != '_') {
645 if (token_index
> 0 && (token_len
< 1 || token_len
> 8)) {
651 if (token_index
== 0 && (token_len
< 1 || token_len
> 3)) {
653 } else if (token_len
< 1 || token_len
> 8) {
660 std::string
GetStringUTF8(int message_id
) {
661 return base::UTF16ToUTF8(GetStringUTF16(message_id
));
664 base::string16
GetStringUTF16(int message_id
) {
665 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
666 base::string16 str
= rb
.GetLocalizedString(message_id
);
667 AdjustParagraphDirectionality(&str
);
672 base::string16
GetStringFUTF16(int message_id
,
673 const std::vector
<base::string16
>& replacements
,
674 std::vector
<size_t>* offsets
) {
675 // TODO(tc): We could save a string copy if we got the raw string as
676 // a StringPiece and were able to call ReplaceStringPlaceholders with
677 // a StringPiece format string and base::string16 substitution strings. In
678 // practice, the strings should be relatively short.
679 ResourceBundle
& rb
= ResourceBundle::GetSharedInstance();
680 const base::string16
& format_string
= rb
.GetLocalizedString(message_id
);
683 // Make sure every replacement string is being used, so we don't just
684 // silently fail to insert one. If |offsets| is non-NULL, then don't do this
685 // check as the code may simply want to find the placeholders rather than
686 // actually replacing them.
688 std::string utf8_string
= base::UTF16ToUTF8(format_string
);
690 // $9 is the highest allowed placeholder.
691 for (size_t i
= 0; i
< 9; ++i
) {
692 bool placeholder_should_exist
= replacements
.size() > i
;
694 std::string placeholder
=
695 base::StringPrintf("$%d", static_cast<int>(i
+ 1));
696 size_t pos
= utf8_string
.find(placeholder
.c_str());
697 if (placeholder_should_exist
) {
698 DCHECK_NE(std::string::npos
, pos
) <<
699 " Didn't find a " << placeholder
<< " placeholder in " <<
702 DCHECK_EQ(std::string::npos
, pos
) <<
703 " Unexpectedly found a " << placeholder
<< " placeholder in " <<
710 base::string16 formatted
= ReplaceStringPlaceholders(
711 format_string
, replacements
, offsets
);
712 AdjustParagraphDirectionality(&formatted
);
717 std::string
GetStringFUTF8(int message_id
,
718 const base::string16
& a
) {
719 return base::UTF16ToUTF8(GetStringFUTF16(message_id
, a
));
722 std::string
GetStringFUTF8(int message_id
,
723 const base::string16
& a
,
724 const base::string16
& b
) {
725 return base::UTF16ToUTF8(GetStringFUTF16(message_id
, a
, b
));
728 std::string
GetStringFUTF8(int message_id
,
729 const base::string16
& a
,
730 const base::string16
& b
,
731 const base::string16
& c
) {
732 return base::UTF16ToUTF8(GetStringFUTF16(message_id
, a
, b
, c
));
735 std::string
GetStringFUTF8(int message_id
,
736 const base::string16
& a
,
737 const base::string16
& b
,
738 const base::string16
& c
,
739 const base::string16
& d
) {
740 return base::UTF16ToUTF8(GetStringFUTF16(message_id
, a
, b
, c
, d
));
743 base::string16
GetStringFUTF16(int message_id
,
744 const base::string16
& a
) {
745 std::vector
<base::string16
> replacements
;
746 replacements
.push_back(a
);
747 return GetStringFUTF16(message_id
, replacements
, NULL
);
750 base::string16
GetStringFUTF16(int message_id
,
751 const base::string16
& a
,
752 const base::string16
& b
) {
753 return GetStringFUTF16(message_id
, a
, b
, NULL
);
756 base::string16
GetStringFUTF16(int message_id
,
757 const base::string16
& a
,
758 const base::string16
& b
,
759 const base::string16
& c
) {
760 std::vector
<base::string16
> replacements
;
761 replacements
.push_back(a
);
762 replacements
.push_back(b
);
763 replacements
.push_back(c
);
764 return GetStringFUTF16(message_id
, replacements
, NULL
);
767 base::string16
GetStringFUTF16(int message_id
,
768 const base::string16
& a
,
769 const base::string16
& b
,
770 const base::string16
& c
,
771 const base::string16
& d
) {
772 std::vector
<base::string16
> replacements
;
773 replacements
.push_back(a
);
774 replacements
.push_back(b
);
775 replacements
.push_back(c
);
776 replacements
.push_back(d
);
777 return GetStringFUTF16(message_id
, replacements
, NULL
);
780 base::string16
GetStringFUTF16(int message_id
,
781 const base::string16
& a
,
782 const base::string16
& b
,
783 const base::string16
& c
,
784 const base::string16
& d
,
785 const base::string16
& e
) {
786 std::vector
<base::string16
> replacements
;
787 replacements
.push_back(a
);
788 replacements
.push_back(b
);
789 replacements
.push_back(c
);
790 replacements
.push_back(d
);
791 replacements
.push_back(e
);
792 return GetStringFUTF16(message_id
, replacements
, NULL
);
795 base::string16
GetStringFUTF16(int message_id
,
796 const base::string16
& a
,
799 std::vector
<size_t> offsets
;
800 std::vector
<base::string16
> replacements
;
801 replacements
.push_back(a
);
802 base::string16 result
= GetStringFUTF16(message_id
, replacements
, &offsets
);
803 DCHECK(offsets
.size() == 1);
804 *offset
= offsets
[0];
808 base::string16
GetStringFUTF16(int message_id
,
809 const base::string16
& a
,
810 const base::string16
& b
,
811 std::vector
<size_t>* offsets
) {
812 std::vector
<base::string16
> replacements
;
813 replacements
.push_back(a
);
814 replacements
.push_back(b
);
815 return GetStringFUTF16(message_id
, replacements
, offsets
);
818 base::string16
GetStringFUTF16Int(int message_id
, int a
) {
819 return GetStringFUTF16(message_id
, base::UTF8ToUTF16(base::IntToString(a
)));
822 base::string16
GetStringFUTF16Int(int message_id
, int64 a
) {
823 return GetStringFUTF16(message_id
, base::UTF8ToUTF16(base::Int64ToString(a
)));
826 base::string16
GetPluralStringFUTF16(const std::vector
<int>& message_ids
,
828 scoped_ptr
<icu::PluralFormat
> format
= BuildPluralFormat(message_ids
);
831 UErrorCode err
= U_ZERO_ERROR
;
832 icu::UnicodeString result_files_string
= format
->format(number
, err
);
833 int capacity
= result_files_string
.length() + 1;
834 DCHECK_GT(capacity
, 1);
835 base::string16 result
;
836 result_files_string
.extract(
837 static_cast<UChar
*>(WriteInto(&result
, capacity
)), capacity
, err
);
838 DCHECK(U_SUCCESS(err
));
842 std::string
GetPluralStringFUTF8(const std::vector
<int>& message_ids
,
844 return base::UTF16ToUTF8(GetPluralStringFUTF16(message_ids
, number
));
847 void SortStrings16(const std::string
& locale
,
848 std::vector
<base::string16
>* strings
) {
849 SortVectorWithStringKey(locale
, strings
, false);
852 const std::vector
<std::string
>& GetAvailableLocales() {
853 return g_available_locales
.Get();
856 void GetAcceptLanguagesForLocale(const std::string
& display_locale
,
857 std::vector
<std::string
>* locale_codes
) {
858 for (size_t i
= 0; i
< arraysize(kAcceptLanguageList
); ++i
) {
859 if (!l10n_util::IsLocaleNameTranslated(kAcceptLanguageList
[i
],
861 // TODO(jungshik) : Put them at the of the list with language codes
862 // enclosed by brackets instead of skipping.
864 locale_codes
->push_back(kAcceptLanguageList
[i
]);
868 int GetLocalizedContentsWidthInPixels(int pixel_resource_id
) {
870 base::StringToInt(l10n_util::GetStringUTF8(pixel_resource_id
), &width
);
875 const char* const* GetAcceptLanguageListForTesting() {
876 return kAcceptLanguageList
;
879 size_t GetAcceptLanguageListSizeForTesting() {
880 return arraysize(kAcceptLanguageList
);
883 } // namespace l10n_util