Use no locale as synonym for nb (#53880)

This commit is contained in:
Shi-Hao Hong
2020-04-03 11:56:02 -07:00
committed by GitHub
parent e012752634
commit 365528aad6
10 changed files with 723 additions and 314 deletions

View File

@@ -172,6 +172,14 @@ Set<String> _supportedLocales() {
if (FileSystemEntity.isFileSync(filePath) && filenameRE.hasMatch(filePath))
supportedLocales.add(filenameRE.firstMatch(filePath)[1]);
}
// See https://github.com/flutter/flutter/issues/53036 for context on why
// 'no' is being used as a synonym for 'nb'. It only uses this synonym
// if 'nb' is not detected as a valid arb file.
if (supportedLocales.contains('no') && !supportedLocales.contains('nb')) {
supportedLocales.add('nb');
}
return supportedLocales;
}

View File

@@ -76,6 +76,11 @@ String generateArbBasedLocalizationSubclasses({
assert(supportedLanguagesConstant.isNotEmpty);
assert(supportedLanguagesDocMacro.isNotEmpty);
// See https://github.com/flutter/flutter/issues/53036 for context on why
// 'no' is being used as a synonym for 'nb'. It only uses this synonym
// if 'nb' is not detected as a valid arb file.
bool isNbSynonymOfNo = false;
final StringBuffer output = StringBuffer();
output.writeln(generateHeader('dart dev/tools/localization/bin/gen_localizations.dart --overwrite'));
@@ -101,6 +106,12 @@ String generateArbBasedLocalizationSubclasses({
allResourceIdentifiers.addAll(localeToResources[locale].keys.toList()..sort());
}
if (languageToLocales['no'] != null && languageToLocales['nb'] == null) {
languageToLocales['nb'] ??= <LocaleInfo>[];
languageToLocales['nb'].add(LocaleInfo.fromString('nb'));
isNbSynonymOfNo = true;
}
// We generate one class per supported language (e.g.
// `MaterialLocalizationEn`). These implement everything that is needed by the
// superclass (e.g. GlobalMaterialLocalizations).
@@ -117,7 +128,7 @@ String generateArbBasedLocalizationSubclasses({
// If scriptCodes for a language are defined, we expect a scriptCode to be
// defined for locales that contain a countryCode. The superclass becomes
// the script sublcass (e.g. `MaterialLocalizationZhHant`) and the generated
// the script subclass (e.g. `MaterialLocalizationZhHant`) and the generated
// subclass will also contain the script code (e.g. `MaterialLocalizationZhHantTW`).
// When scriptCodes are not defined for languages that use scriptCodes to distinguish
@@ -130,6 +141,22 @@ String generateArbBasedLocalizationSubclasses({
final LocaleInfo canonicalLocale = LocaleInfo.fromString('en');
for (final String languageName in languageCodes) {
final LocaleInfo languageLocale = LocaleInfo.fromString(languageName);
// See https://github.com/flutter/flutter/issues/53036 for context on why
// 'no' is being used as a synonym for 'nb'. It only uses this synonym
// if 'nb' is not detected as a valid arb file.
if (languageName == 'nb' && isNbSynonymOfNo) {
output.writeln(generateClassDeclaration(
languageLocale,
generatedClassPrefix,
'${generatedClassPrefix}No'),
);
output.writeln(generateConstructor(languageLocale));
output.writeln('}');
supportedLocales.writeln('/// * `$languageName` - ${describeLocale(languageName)}, which, in this library, is a synonym of `no`');
continue;
}
output.writeln(generateClassDeclaration(languageLocale, generatedClassPrefix, baseClass));
output.writeln(generateConstructor(languageLocale));
@@ -212,6 +239,7 @@ String generateArbBasedLocalizationSubclasses({
output.writeln('}');
}
}
final String scriptCodeMessage = scriptCodeCount == 0 ? '' : ' and $scriptCodeCount script' + (scriptCodeCount == 1 ? '' : 's');
if (countryCodeCount == 0) {
if (scriptCodeCount == 0)