Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
117a83a4
Unverified
Commit
117a83a4
authored
Dec 08, 2022
by
Tae Hyung Kim
Committed by
GitHub
Dec 08, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Throw error when plural case had undefined behavior (#116622)
* init * add comment * make error more actionable
parent
bebea0cc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
1 deletion
+46
-1
gen_l10n.dart
packages/flutter_tools/lib/src/localizations/gen_l10n.dart
+14
-1
generate_localizations_test.dart
...tools/test/general.shard/generate_localizations_test.dart
+32
-0
No files found.
packages/flutter_tools/lib/src/localizations/gen_l10n.dart
View file @
117a83a4
...
...
@@ -1167,7 +1167,20 @@ class LocalizationsGenerator {
}
if
(!
pluralLogicArgs
.
containsKey
(
pluralCases
[
pluralCase
]))
{
final
String
pluralPartExpression
=
generateVariables
(
pluralMessage
);
pluralLogicArgs
[
pluralCases
[
pluralCase
]!]
=
'
${pluralCases[pluralCase]}
:
$pluralPartExpression
,'
;
final
String
?
transformedPluralCase
=
pluralCases
[
pluralCase
];
// A valid plural case is one of "=0", "=1", "=2", "zero", "one", "two", "few", "many", or "other".
if
(
transformedPluralCase
==
null
)
{
throw
L10nParserException
(
'''
The plural cases must be one of "=0", "=1", "=2", "zero", "one", "two", "few", "many", or "other.
$pluralCase
is not a valid plural case.'''
,
_inputFileNames
[
locale
]!,
message
.
resourceId
,
translationForMessage
,
pluralPart
.
positionInMessage
,
);
}
pluralLogicArgs
[
transformedPluralCase
]
=
'
${pluralCases[pluralCase]}
:
$pluralPartExpression
,'
;
}
else
if
(!
suppressWarnings
)
{
logger
.
printWarning
(
'''
[
${_inputFileNames[locale]}
:
${message.resourceId}
] ICU Syntax Warning: The plural part specified below is overridden by a later plural part.
...
...
packages/flutter_tools/test/general.shard/generate_localizations_test.dart
View file @
117a83a4
...
...
@@ -2027,6 +2027,38 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
^'''));
});
testWithoutContext('undefined plural cases throws syntax error', () {
const String pluralMessageWithUndefinedParts = '''
{
"
count
": "
{
count
,
plural
,
=
0
{
None
}
=
1
{
One
}
=
2
{
Two
}
=
3
{
Undefined
Behavior
!}
other
{
Hmm
...}}
"
}''';
final Directory l10nDirectory = fs.currentDirectory.childDirectory('lib').childDirectory('l10n')
..createSync(recursive: true);
l10nDirectory.childFile(defaultTemplateArbFileName)
.writeAsStringSync(pluralMessageWithUndefinedParts);
try {
LocalizationsGenerator(
fileSystem: fs,
inputPathString: defaultL10nPathString,
outputPathString: defaultL10nPathString,
templateArbFileName: defaultTemplateArbFileName,
outputFileString: defaultOutputFileString,
classNameString: defaultClassNameString,
logger: logger,
)
..loadResources()
..writeOutputFiles();
} on L10nException catch (error) {
expect(error.message, contains('Found syntax errors.'));
expect(logger.hadErrorOutput, isTrue);
expect(logger.errorText, contains('''
[app_en.arb:count] The plural cases must be one of "
=
0
", "
=
1
", "
=
2
", "
zero
", "
one
", "
two
", "
few
", "
many
", or "
other
.
3
is
not
a
valid
plural
case
.
{
count
,
plural
,
=
0
{
None
}
=
1
{
One
}
=
2
{
Two
}
=
3
{
Undefined
Behavior
!}
other
{
Hmm
...}}
^
'''));
}
});
testWithoutContext('
should
automatically
infer
plural
placeholders
that
are
not
explicitly
defined
', () {
const String pluralMessageWithoutPlaceholdersAttribute = '''
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment