Bug 1606744 - Add a default region subtag to the system locale code if GlobalizationPreferences returns a bare language code, to avoid problems with DirectWrite localized font-name API. r=emk

Differential Revision: https://phabricator.services.mozilla.com/D58632

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jonathan Kew 2020-01-03 17:52:27 +00:00
Родитель cd519c4f3d
Коммит 72877316d6
1 изменённых файлов: 15 добавлений и 0 удалений

Просмотреть файл

@ -6,6 +6,7 @@
#include "OSPreferences.h"
#include "mozilla/intl/LocaleService.h"
#include "mozilla/intl/MozLocale.h"
#include "mozilla/WindowsVersion.h"
#include "nsReadableUtils.h"
@ -60,6 +61,20 @@ bool OSPreferences::ReadSystemLocales(nsTArray<nsCString>& aLocaleList) {
const wchar_t* text = lang.GetRawBuffer(&length);
NS_LossyConvertUTF16toASCII loc(text, length);
if (CanonicalizeLanguageTag(loc)) {
if (!loc.Contains('-')) {
// DirectWrite font-name code doesn't like to be given a bare
// language code with no region subtag, but the
// GlobalizationPreferences API may give us one (e.g. "ja").
// So if there's no hyphen in the string at this point, we use
// Locale::AddLikelySubtags to get a suitable region code to
// go with it.
Locale locale(loc);
if (locale.AddLikelySubtags() &&
!locale.GetRegion().IsEmpty()) {
loc.Append('-');
loc.Append(locale.GetRegion());
}
}
aLocaleList.AppendElement(loc);
}
}