Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 82c00c9

Browse files
authoredFeb 5, 2020
Move the localization_utils camelCase function to LocaleInfo (flutter#50152)
1 parent c3e0f2d commit 82c00c9

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed
 

‎dev/tools/localization/bin/gen_localizations.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ String generateArbBasedLocalizationSubclasses({
151151
output.writeln(generateClassDeclaration(
152152
scriptBaseLocale,
153153
generatedClassPrefix,
154-
'$generatedClassPrefix${camelCase(languageLocale)}',
154+
'$generatedClassPrefix${languageLocale.camelCase()}',
155155
));
156156
output.writeln(generateConstructor(scriptBaseLocale));
157157
final Map<String, String> scriptResources = localeToResources[scriptBaseLocale];
@@ -175,7 +175,7 @@ String generateArbBasedLocalizationSubclasses({
175175
output.writeln(generateClassDeclaration(
176176
locale,
177177
generatedClassPrefix,
178-
'$generatedClassPrefix${camelCase(scriptBaseLocale)}',
178+
'$generatedClassPrefix${scriptBaseLocale.camelCase()}',
179179
));
180180
output.writeln(generateConstructor(locale));
181181
final Map<String, String> localeResources = localeToResources[locale];
@@ -201,7 +201,7 @@ String generateArbBasedLocalizationSubclasses({
201201
output.writeln(generateClassDeclaration(
202202
locale,
203203
generatedClassPrefix,
204-
'$generatedClassPrefix${camelCase(languageLocale)}',
204+
'$generatedClassPrefix${languageLocale.camelCase()}',
205205
));
206206
output.writeln(generateConstructor(locale));
207207
for (final String key in localeResources.keys) {
@@ -267,7 +267,7 @@ $factoryDeclaration
267267
if (languageToLocales[language].length == 1) {
268268
output.writeln('''
269269
case '$language':
270-
return $generatedClassPrefix${camelCase(languageToLocales[language][0])}($factoryArguments);''');
270+
return $generatedClassPrefix${(languageToLocales[language][0]).camelCase()}($factoryArguments);''');
271271
} else if (!languageToScriptCodes.containsKey(language)) { // Does not distinguish between scripts. Switch on countryCode directly.
272272
output.writeln('''
273273
case '$language': {
@@ -279,11 +279,11 @@ $factoryDeclaration
279279
final String countryCode = locale.countryCode;
280280
output.writeln('''
281281
case '$countryCode':
282-
return $generatedClassPrefix${camelCase(locale)}($factoryArguments);''');
282+
return $generatedClassPrefix${locale.camelCase()}($factoryArguments);''');
283283
}
284284
output.writeln('''
285285
}
286-
return $generatedClassPrefix${camelCase(LocaleInfo.fromString(language))}($factoryArguments);
286+
return $generatedClassPrefix${LocaleInfo.fromString(language).camelCase()}($factoryArguments);
287287
}''');
288288
} else { // Language has scriptCode, add additional switch logic.
289289
bool hasCountryCode = false;
@@ -309,7 +309,7 @@ $factoryDeclaration
309309
final String countryCode = locale.countryCode;
310310
output.writeln('''
311311
case '$countryCode':
312-
return $generatedClassPrefix${camelCase(locale)}($factoryArguments);''');
312+
return $generatedClassPrefix${locale.camelCase()}($factoryArguments);''');
313313
}
314314
}
315315
// Return a fallback locale that matches scriptCode, but not countryCode.
@@ -321,7 +321,7 @@ $factoryDeclaration
321321
}''');
322322
}
323323
output.writeln('''
324-
return $generatedClassPrefix${camelCase(scriptLocale)}($factoryArguments);
324+
return $generatedClassPrefix${scriptLocale.camelCase()}($factoryArguments);
325325
}''');
326326
} else {
327327
// Not Explicitly defined, fallback to first locale with the same language and
@@ -334,7 +334,7 @@ $factoryDeclaration
334334
}''');
335335
}
336336
output.writeln('''
337-
return $generatedClassPrefix${camelCase(scriptLocale)}($factoryArguments);
337+
return $generatedClassPrefix${scriptLocale.camelCase()}($factoryArguments);
338338
}''');
339339
break;
340340
}
@@ -354,13 +354,13 @@ $factoryDeclaration
354354
final String countryCode = locale.countryCode;
355355
output.writeln('''
356356
case '$countryCode':
357-
return $generatedClassPrefix${camelCase(locale)}($factoryArguments);''');
357+
return $generatedClassPrefix${locale.camelCase()}($factoryArguments);''');
358358
}
359359
output.writeln('''
360360
}''');
361361
}
362362
output.writeln('''
363-
return $generatedClassPrefix${camelCase(LocaleInfo.fromString(language))}($factoryArguments);
363+
return $generatedClassPrefix${LocaleInfo.fromString(language).camelCase()}($factoryArguments);
364364
}''');
365365
}
366366
}

‎dev/tools/localization/gen_cupertino_localizations.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ConstructorGenerator generateCupertinoConstructor = (LocaleInfo locale) {
3838
/// Create an instance of the translation bundle for ${describeLocale(localeName)}.
3939
///
4040
/// For details on the meaning of the arguments, see [GlobalCupertinoLocalizations].
41-
const CupertinoLocalization${camelCase(locale)}({
41+
const CupertinoLocalization${locale.camelCase()}({
4242
String localeName = '$localeName',
4343
@required intl.DateFormat fullYearFormat,
4444
@required intl.DateFormat dayFormat,

‎dev/tools/localization/gen_material_localizations.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ConstructorGenerator generateMaterialConstructor = (LocaleInfo locale) {
3838
/// Create an instance of the translation bundle for ${describeLocale(localeName)}.
3939
///
4040
/// For details on the meaning of the arguments, see [GlobalMaterialLocalizations].
41-
const MaterialLocalization${camelCase(locale)}({
41+
const MaterialLocalization${locale.camelCase()}({
4242
String localeName = '$localeName',
4343
@required intl.DateFormat fullYearFormat,
4444
@required intl.DateFormat mediumDateFormat,

‎dev/tools/localization/localizations_utils.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ class LocaleInfo implements Comparable<LocaleInfo> {
112112
final int length; // The number of fields. Ranges from 1-3.
113113
final String originalString; // Original un-parsed locale string.
114114

115+
String camelCase() {
116+
return originalString
117+
.split('_')
118+
.map<String>((String part) => part.substring(0, 1).toUpperCase() + part.substring(1).toLowerCase())
119+
.join('');
120+
}
121+
115122
@override
116123
bool operator ==(Object other) {
117124
return other is LocaleInfo
@@ -220,13 +227,6 @@ void checkCwdIsRepoRoot(String commandName) {
220227
}
221228
}
222229

223-
String camelCase(LocaleInfo locale) {
224-
return locale.originalString
225-
.split('_')
226-
.map<String>((String part) => part.substring(0, 1).toUpperCase() + part.substring(1).toLowerCase())
227-
.join('');
228-
}
229-
230230
GeneratorOptions parseArgs(List<String> rawArgs) {
231231
final argslib.ArgParser argParser = argslib.ArgParser()
232232
..addFlag(
@@ -364,7 +364,7 @@ String generateClassDeclaration(
364364
String classNamePrefix,
365365
String superClass,
366366
) {
367-
final String camelCaseName = camelCase(locale);
367+
final String camelCaseName = locale.camelCase();
368368
return '''
369369
370370
/// The translations for ${describeLocale(locale.originalString)} (`${locale.originalString}`).

0 commit comments

Comments
 (0)
Please sign in to comment.