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
dca58a28
Unverified
Commit
dca58a28
authored
Apr 24, 2022
by
Alex Li
Committed by
GitHub
Apr 24, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[gen_l10n] Throw a specified exception when the language code is invalid (#102431)
parent
c654d04f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
2 deletions
+43
-2
localizations_utils.dart
...tter_tools/lib/src/localizations/localizations_utils.dart
+10
-2
generate_localizations_test.dart
...tools/test/general.shard/generate_localizations_test.dart
+33
-0
No files found.
packages/flutter_tools/lib/src/localizations/localizations_utils.dart
View file @
dca58a28
...
...
@@ -7,6 +7,7 @@ import 'package:yaml/yaml.dart';
import
'../base/file_system.dart'
;
import
'../base/logger.dart'
;
import
'gen_l10n_types.dart'
;
import
'language_subtag_registry.dart'
;
typedef
HeaderGenerator
=
String
Function
(
String
regenerateInstructions
);
...
...
@@ -215,8 +216,15 @@ void precacheLanguageAndRegionTags() {
String
describeLocale
(
String
tag
)
{
final
List
<
String
>
subtags
=
tag
.
split
(
'_'
);
assert
(
subtags
.
isNotEmpty
);
assert
(
_languages
.
containsKey
(
subtags
[
0
]));
final
String
language
=
_languages
[
subtags
[
0
]]!;
final
String
languageCode
=
subtags
[
0
];
if
(!
_languages
.
containsKey
(
languageCode
))
{
throw
L10nException
(
'"
$languageCode
" is not a supported language code.
\n
'
'See https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry '
'for the supported list.'
,
);
}
final
String
language
=
_languages
[
languageCode
]!;
String
output
=
language
;
String
?
region
;
String
?
script
;
...
...
packages/flutter_tools/test/general.shard/generate_localizations_test.dart
View file @
dca58a28
...
...
@@ -2595,6 +2595,39 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
);
});
});
testWithoutContext('throws when the language code is not supported', () {
const String arbFileWithInvalidCode = '''
{
"
@
@locale
": "
invalid
",
"
title
": "
invalid
"
}''';
final Directory l10nDirectory = fs.currentDirectory.childDirectory('lib').childDirectory('l10n')
..createSync(recursive: true);
l10nDirectory.childFile('app_invalid.arb')
.writeAsStringSync(arbFileWithInvalidCode);
expect(
() {
LocalizationsGenerator(
fileSystem: fs,
inputPathString: defaultL10nPathString,
outputPathString: defaultL10nPathString,
templateArbFileName: 'app_invalid.arb',
outputFileString: defaultOutputFileString,
classNameString: defaultClassNameString,
)
..loadResources()
..writeOutputFiles(BufferLogger.test());
},
throwsA(isA<L10nException>().having(
(L10nException e) => e.message,
'message',
contains('"
invalid
" is not a supported language code.'),
)),
);
});
});
testWithoutContext('should generate a valid pubspec.yaml file when using synthetic package if it does not already exist', () {
...
...
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