Unverified Commit 215f6372 authored by Tae Hyung Kim's avatar Tae Hyung Kim Committed by GitHub

Refactor Message class to hold all translations (#115506)

* init

* more fixing

* finish

* fix lint

* address pr comments

* redo checks
parent 4a5dd9c9
...@@ -1618,7 +1618,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e ...@@ -1618,7 +1618,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
'message', 'message',
contains(''' contains('''
Make sure that the specified placeholder is defined in your arb file. Make sure that the specified placeholder is defined in your arb file.
Hello {name} [app_en.arb:helloWorld] Hello {name}
^'''), ^'''),
)), )),
); );
...@@ -1940,13 +1940,10 @@ Hello {name} ...@@ -1940,13 +1940,10 @@ Hello {name}
throwsA(isA<L10nException>().having( throwsA(isA<L10nException>().having(
(L10nException e) => e.message, (L10nException e) => e.message,
'message', 'message',
// TODO(thkim1011): Uncomment after work on refactoring the Message class. contains('''
// See https://github.com/flutter/flutter/issues/112709. Make sure that the specified plural placeholder is defined in your arb file.
// contains(''' [app_en.arb:helloWorlds] {count,plural, =0{Hello}=1{Hello World}=2{Hello two worlds}few{Hello {count} worlds}many{Hello all {count} worlds}other{Hello other {count} worlds}}
// Make sure that the specified plural placeholder is defined in your arb file. ^'''),
// {count,plural, =0{Hello}=1{Hello World}=2{Hello two worlds}few{Hello {count} worlds}many{Hello all {count} worlds}other{Hello other {count} worlds}}
// ^'''),
contains('Cannot find the count placeholder in plural message "helloWorlds".'),
)), )),
); );
}); });
...@@ -1983,13 +1980,10 @@ Hello {name} ...@@ -1983,13 +1980,10 @@ Hello {name}
throwsA(isA<L10nException>().having( throwsA(isA<L10nException>().having(
(L10nException e) => e.message, (L10nException e) => e.message,
'message', 'message',
// TODO(thkim1011): Uncomment after work on refactoring the Message class. contains('''
// See https://github.com/flutter/flutter/issues/112709. Make sure that the specified plural placeholder is defined in your arb file.
// contains(''' [app_en.arb:helloWorlds] {count,plural, =0{Hello}=1{Hello World}=2{Hello two worlds}few{Hello {count} worlds}many{Hello all {count} worlds}other{Hello other {count} worlds}}
// Make sure that the specified plural placeholder is defined in your arb file. ^'''),
// {count,plural, =0{Hello}=1{Hello World}=2{Hello two worlds}few{Hello {count} worlds}many{Hello all {count} worlds}other{Hello other {count} worlds}}
// ^'''),
contains('Cannot find the count placeholder in plural message "helloWorlds".'),
)), )),
); );
}); });
...@@ -2022,13 +2016,10 @@ Hello {name} ...@@ -2022,13 +2016,10 @@ Hello {name}
throwsA(isA<L10nException>().having( throwsA(isA<L10nException>().having(
(L10nException e) => e.message, (L10nException e) => e.message,
'message', 'message',
// TODO(thkim1011): Uncomment after work on refactoring the Message class. contains('''
// See https://github.com/flutter/flutter/issues/112709. Make sure that the specified plural placeholder is defined in your arb file.
// contains(''' [app_en.arb:helloWorlds] {count,plural, =0{Hello}=1{Hello World}=2{Hello two worlds}few{Hello {count} worlds}many{Hello all {count} worlds}other{Hello other {count} worlds}}
// Make sure that the specified plural placeholder is defined in your arb file. ^'''),
// {count,plural, =0{Hello}=1{Hello World}=2{Hello two worlds}few{Hello {count} worlds}many{Hello all {count} worlds}other{Hello other {count} worlds}}
// ^'''),
contains('Resource attribute "@helloWorlds" was not found. Please ensure that plural resources have a corresponding @resource.'),
)), )),
); );
}); });
...@@ -2107,7 +2098,7 @@ Hello {name} ...@@ -2107,7 +2098,7 @@ Hello {name}
'message', 'message',
contains(''' contains('''
Make sure that the specified select placeholder is defined in your arb file. Make sure that the specified select placeholder is defined in your arb file.
{gender, select, female {She} male {He} other {they} } [app_en.arb:genderSelect] {gender, select, female {She} male {He} other {they} }
^'''), ^'''),
)), )),
); );
...@@ -2147,7 +2138,7 @@ Make sure that the specified select placeholder is defined in your arb file. ...@@ -2147,7 +2138,7 @@ Make sure that the specified select placeholder is defined in your arb file.
'message', 'message',
contains(''' contains('''
Make sure that the specified select placeholder is defined in your arb file. Make sure that the specified select placeholder is defined in your arb file.
{gender, select, female {She} male {He} other {they} } [app_en.arb:genderSelect] {gender, select, female {She} male {He} other {they} }
^'''), ^'''),
)), )),
); );
...@@ -2181,13 +2172,10 @@ Make sure that the specified select placeholder is defined in your arb file. ...@@ -2181,13 +2172,10 @@ Make sure that the specified select placeholder is defined in your arb file.
throwsA(isA<L10nException>().having( throwsA(isA<L10nException>().having(
(L10nException e) => e.message, (L10nException e) => e.message,
'message', 'message',
// TODO(thkim1011): Uncomment after work on refactoring the Message class. contains('''
// See https://github.com/flutter/flutter/issues/112709. Make sure that the specified select placeholder is defined in your arb file.
// contains(''' [app_en.arb:genderSelect] {gender, select, female {She} male {He} other {they} }
// Make sure that the specified select placeholder is defined in your arb file. ^'''),
// {gender, select, female {She} male {He} other {they} }
// ^'''),
contains('Resource attribute "@genderSelect" was not found. Please ensure that select resources have a corresponding @resource.'),
)), )),
); );
}); });
...@@ -2996,50 +2984,6 @@ AppLocalizations lookupAppLocalizations(Locale locale) { ...@@ -2996,50 +2984,6 @@ AppLocalizations lookupAppLocalizations(Locale locale) {
''')); '''));
}); });
// Regression test for https://github.com/flutter/flutter/pull/93228
testWithoutContext('should use num type for plural', () {
const String arbFile = '''
{
"tryToPollute": "{count, plural, =0{零} =1{一} other{其他}}",
"@tryToPollute": {
"placeholders": {
"count": {
"type": "int"
}
}
},
"withoutType": "{count, plural, =0{零} =1{一} other{其他}}",
"@withoutType": {
"placeholders": {
"count": {}
}
}
}''';
final Directory l10nDirectory = fs.currentDirectory.childDirectory('lib').childDirectory('l10n')
..createSync(recursive: true);
l10nDirectory.childFile(defaultTemplateArbFileName)
.writeAsStringSync(arbFile);
LocalizationsGenerator(
fileSystem: fs,
inputPathString: defaultL10nPathString,
outputPathString: defaultL10nPathString,
templateArbFileName: defaultTemplateArbFileName,
outputFileString: defaultOutputFileString,
classNameString: defaultClassNameString,
logger: logger,
)
..loadResources()
..writeOutputFiles();
final String localizationsFile = fs.file(
fs.path.join(syntheticL10nPackagePath, 'output-localization-file_en.dart'),
).readAsStringSync();
expect(localizationsFile, containsIgnoringWhitespace(r'String tryToPollute(num count) {'));
expect(localizationsFile, containsIgnoringWhitespace(r'String withoutType(num count) {'));
});
// TODO(thkim1011): Uncomment when implementing escaping. // TODO(thkim1011): Uncomment when implementing escaping.
// See https://github.com/flutter/flutter/issues/113455. // See https://github.com/flutter/flutter/issues/113455.
// testWithoutContext('escaping with single quotes', () { // testWithoutContext('escaping with single quotes', () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment