Bug 1450656 - Canonicalize ja-JP-mac to ja-JP-macos and use BCP47 version in Fluent. r?jfkthame
MozReview-Commit-ID: 8GjpB94Kfe4
--- a/intl/l10n/L10nRegistry.jsm
+++ b/intl/l10n/L10nRegistry.jsm
@@ -320,16 +320,21 @@ class FileSource {
//
// If the `indexed` property is set to `true` it will be treated as the
// resource not being available. Otherwise, the resource may be
// available and we do not have any information about it yet.
this.cache = {};
}
getPath(locale, path) {
+ // This is a special case for the only not BCP47-conformant locale
+ // code we have resources for.
+ if (locale === "ja-JP-macos") {
+ locale = "ja-JP-mac";
+ }
return (this.prePath + path).replace(/\{locale\}/g, locale);
}
hasFile(locale, path) {
if (!this.locales.includes(locale)) {
return false;
}
--- a/intl/l10n/Localization.jsm
+++ b/intl/l10n/Localization.jsm
@@ -96,17 +96,17 @@ class CachedIterable {
* available in L10nRegistry, with locales requested by the user to
* generate the iterator over MessageContexts.
*
* In the future, we may want to allow certain modules to override this
* with a different negotitation strategy to allow for the module to
* be localized into a different language - for example DevTools.
*/
function defaultGenerateMessages(resourceIds) {
- const appLocales = Services.locale.getAppLocalesAsLangTags();
+ const appLocales = Services.locale.getAppLocalesAsBCP47();
return L10nRegistry.generateContexts(appLocales, resourceIds);
}
/**
* The `Localization` class is a central high-level API for vanilla
* JavaScript use of Fluent.
* It combines language negotiation, MessageContext and I/O to
* provide a scriptable API to format translations.
--- a/intl/locale/LocaleService.cpp
+++ b/intl/locale/LocaleService.cpp
@@ -39,27 +39,35 @@ NS_IMPL_ISUPPORTS(LocaleService, mozILoc
nsISupportsWeakReference)
mozilla::StaticRefPtr<LocaleService> LocaleService::sInstance;
/**
* This function transforms a canonical Mozilla Language Tag, into it's
* BCP47 compilant form.
*
- * Example: "ja-JP-mac" -> "ja-JP-x-lvariant-mac"
+ * Example: "ja-JP-mac" -> "ja-JP-macos"
*
* The BCP47 form should be used for all calls to ICU/Intl APIs.
* The canonical form is used for all internal operations.
*/
static bool
SanitizeForBCP47(nsACString& aLocale, bool strict)
{
// Currently, the only locale code we use that's not BCP47-conformant is
- // "ja-JP-mac" on OS X, but let's try to be more general than just
- // hard-coding that here.
+ // "ja-JP-mac" on OS X, and ICU canonicalizes it into a mouthfull
+ // "ja-JP-x-lvariant-mac", so instead we're hardcoding a conversion
+ // of it to "ja-JP-macos".
+ if (aLocale.LowerCaseEqualsASCII("ja-jp-mac")) {
+ aLocale.AssignLiteral("ja-JP-macos");
+ return true;
+ }
+
+ // The rest of this function will use ICU canonicalization for any other
+ // tag that may come this way.
const int32_t LANG_TAG_CAPACITY = 128;
char langTag[LANG_TAG_CAPACITY];
nsAutoCString locale(aLocale);
locale.Trim(" ");
UErrorCode err = U_ZERO_ERROR;
// This is a fail-safe method that will set langTag to "und" if it cannot
// match any part of the input locale code.
int32_t len = uloc_toLanguageTag(locale.get(), langTag, LANG_TAG_CAPACITY,