diff --git a/dev/tools/localization/bin/gen_localizations.dart b/dev/tools/localization/bin/gen_localizations.dart index a0e14c5fc3..a493284c85 100644 --- a/dev/tools/localization/bin/gen_localizations.dart +++ b/dev/tools/localization/bin/gen_localizations.dart @@ -151,7 +151,7 @@ String generateArbBasedLocalizationSubclasses({ output.writeln(generateClassDeclaration( scriptBaseLocale, generatedClassPrefix, - '$generatedClassPrefix${camelCase(languageLocale)}', + '$generatedClassPrefix${languageLocale.camelCase()}', )); output.writeln(generateConstructor(scriptBaseLocale)); final Map scriptResources = localeToResources[scriptBaseLocale]; @@ -175,7 +175,7 @@ String generateArbBasedLocalizationSubclasses({ output.writeln(generateClassDeclaration( locale, generatedClassPrefix, - '$generatedClassPrefix${camelCase(scriptBaseLocale)}', + '$generatedClassPrefix${scriptBaseLocale.camelCase()}', )); output.writeln(generateConstructor(locale)); final Map localeResources = localeToResources[locale]; @@ -201,7 +201,7 @@ String generateArbBasedLocalizationSubclasses({ output.writeln(generateClassDeclaration( locale, generatedClassPrefix, - '$generatedClassPrefix${camelCase(languageLocale)}', + '$generatedClassPrefix${languageLocale.camelCase()}', )); output.writeln(generateConstructor(locale)); for (final String key in localeResources.keys) { @@ -267,7 +267,7 @@ $factoryDeclaration if (languageToLocales[language].length == 1) { output.writeln(''' case '$language': - return $generatedClassPrefix${camelCase(languageToLocales[language][0])}($factoryArguments);'''); + return $generatedClassPrefix${(languageToLocales[language][0]).camelCase()}($factoryArguments);'''); } else if (!languageToScriptCodes.containsKey(language)) { // Does not distinguish between scripts. Switch on countryCode directly. output.writeln(''' case '$language': { @@ -279,11 +279,11 @@ $factoryDeclaration final String countryCode = locale.countryCode; output.writeln(''' case '$countryCode': - return $generatedClassPrefix${camelCase(locale)}($factoryArguments);'''); + return $generatedClassPrefix${locale.camelCase()}($factoryArguments);'''); } output.writeln(''' } - return $generatedClassPrefix${camelCase(LocaleInfo.fromString(language))}($factoryArguments); + return $generatedClassPrefix${LocaleInfo.fromString(language).camelCase()}($factoryArguments); }'''); } else { // Language has scriptCode, add additional switch logic. bool hasCountryCode = false; @@ -309,7 +309,7 @@ $factoryDeclaration final String countryCode = locale.countryCode; output.writeln(''' case '$countryCode': - return $generatedClassPrefix${camelCase(locale)}($factoryArguments);'''); + return $generatedClassPrefix${locale.camelCase()}($factoryArguments);'''); } } // Return a fallback locale that matches scriptCode, but not countryCode. @@ -321,7 +321,7 @@ $factoryDeclaration }'''); } output.writeln(''' - return $generatedClassPrefix${camelCase(scriptLocale)}($factoryArguments); + return $generatedClassPrefix${scriptLocale.camelCase()}($factoryArguments); }'''); } else { // Not Explicitly defined, fallback to first locale with the same language and @@ -334,7 +334,7 @@ $factoryDeclaration }'''); } output.writeln(''' - return $generatedClassPrefix${camelCase(scriptLocale)}($factoryArguments); + return $generatedClassPrefix${scriptLocale.camelCase()}($factoryArguments); }'''); break; } @@ -354,13 +354,13 @@ $factoryDeclaration final String countryCode = locale.countryCode; output.writeln(''' case '$countryCode': - return $generatedClassPrefix${camelCase(locale)}($factoryArguments);'''); + return $generatedClassPrefix${locale.camelCase()}($factoryArguments);'''); } output.writeln(''' }'''); } output.writeln(''' - return $generatedClassPrefix${camelCase(LocaleInfo.fromString(language))}($factoryArguments); + return $generatedClassPrefix${LocaleInfo.fromString(language).camelCase()}($factoryArguments); }'''); } } diff --git a/dev/tools/localization/gen_cupertino_localizations.dart b/dev/tools/localization/gen_cupertino_localizations.dart index adfba237a3..3a9d59ad0c 100644 --- a/dev/tools/localization/gen_cupertino_localizations.dart +++ b/dev/tools/localization/gen_cupertino_localizations.dart @@ -38,7 +38,7 @@ ConstructorGenerator generateCupertinoConstructor = (LocaleInfo locale) { /// Create an instance of the translation bundle for ${describeLocale(localeName)}. /// /// For details on the meaning of the arguments, see [GlobalCupertinoLocalizations]. - const CupertinoLocalization${camelCase(locale)}({ + const CupertinoLocalization${locale.camelCase()}({ String localeName = '$localeName', @required intl.DateFormat fullYearFormat, @required intl.DateFormat dayFormat, diff --git a/dev/tools/localization/gen_material_localizations.dart b/dev/tools/localization/gen_material_localizations.dart index a2a908fe27..def667d8f4 100644 --- a/dev/tools/localization/gen_material_localizations.dart +++ b/dev/tools/localization/gen_material_localizations.dart @@ -38,7 +38,7 @@ ConstructorGenerator generateMaterialConstructor = (LocaleInfo locale) { /// Create an instance of the translation bundle for ${describeLocale(localeName)}. /// /// For details on the meaning of the arguments, see [GlobalMaterialLocalizations]. - const MaterialLocalization${camelCase(locale)}({ + const MaterialLocalization${locale.camelCase()}({ String localeName = '$localeName', @required intl.DateFormat fullYearFormat, @required intl.DateFormat mediumDateFormat, diff --git a/dev/tools/localization/localizations_utils.dart b/dev/tools/localization/localizations_utils.dart index 79c294d9de..50d045bb3f 100644 --- a/dev/tools/localization/localizations_utils.dart +++ b/dev/tools/localization/localizations_utils.dart @@ -112,6 +112,13 @@ class LocaleInfo implements Comparable { final int length; // The number of fields. Ranges from 1-3. final String originalString; // Original un-parsed locale string. + String camelCase() { + return originalString + .split('_') + .map((String part) => part.substring(0, 1).toUpperCase() + part.substring(1).toLowerCase()) + .join(''); + } + @override bool operator ==(Object other) { return other is LocaleInfo @@ -220,13 +227,6 @@ void checkCwdIsRepoRoot(String commandName) { } } -String camelCase(LocaleInfo locale) { - return locale.originalString - .split('_') - .map((String part) => part.substring(0, 1).toUpperCase() + part.substring(1).toLowerCase()) - .join(''); -} - GeneratorOptions parseArgs(List rawArgs) { final argslib.ArgParser argParser = argslib.ArgParser() ..addFlag( @@ -364,7 +364,7 @@ String generateClassDeclaration( String classNamePrefix, String superClass, ) { - final String camelCaseName = camelCase(locale); + final String camelCaseName = locale.camelCase(); return ''' /// The translations for ${describeLocale(locale.originalString)} (`${locale.originalString}`).