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
485c4091
Unverified
Commit
485c4091
authored
May 22, 2021
by
Michael Goderbauer
Committed by
GitHub
May 22, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
import pkg:intl when DateFormat or NumberFormat is used (#83122)
parent
e069578f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
3 deletions
+76
-3
gen_l10n.dart
packages/flutter_tools/lib/src/localizations/gen_l10n.dart
+3
-3
generate_localizations_test.dart
...tools/test/general.shard/generate_localizations_test.dart
+73
-0
No files found.
packages/flutter_tools/lib/src/localizations/gen_l10n.dart
View file @
485c4091
...
...
@@ -1020,7 +1020,7 @@ class LocalizationsGenerator {
.
replaceAll
(
'@(class)'
,
'
$className${locale.camelCase()}
'
)
.
replaceAll
(
'@(localeName)'
,
locale
.
toString
())
.
replaceAll
(
'@(methods)'
,
methods
.
join
(
'
\n\n
'
))
.
replaceAll
(
'@(requiresIntlImport)'
,
_
containsPluralMessage
()
?
"import 'package:intl/intl.dart' as intl;"
:
''
);
.
replaceAll
(
'@(requiresIntlImport)'
,
_
requiresIntlImport
()
?
"import 'package:intl/intl.dart' as intl;"
:
''
);
}
String
_generateSubclass
(
...
...
@@ -1159,7 +1159,7 @@ class LocalizationsGenerator {
.
replaceAll
(
'@(messageClassImports)'
,
sortedClassImports
.
join
(
'
\n
'
))
.
replaceAll
(
'@(delegateClass)'
,
delegateClass
)
.
replaceAll
(
'@(requiresFoundationImport)'
,
useDeferredLoading
?
''
:
"import 'package:flutter/foundation.dart';"
)
.
replaceAll
(
'@(requiresIntlImport)'
,
_
containsPluralMessage
()
?
"import 'package:intl/intl.dart' as intl;"
:
''
)
.
replaceAll
(
'@(requiresIntlImport)'
,
_
requiresIntlImport
()
?
"import 'package:intl/intl.dart' as intl;"
:
''
)
.
replaceAll
(
'@(canBeNullable)'
,
usesNullableGetter
?
'?'
:
''
)
.
replaceAll
(
'@(needsNullCheck)'
,
usesNullableGetter
?
''
:
'!'
)
// Removes all trailing whitespace from the generated file.
...
...
@@ -1168,7 +1168,7 @@ class LocalizationsGenerator {
.
replaceAll
(
'
\n\n\n
'
,
'
\n\n
'
);
}
bool
_
containsPluralMessage
()
=>
_allMessages
.
any
((
Message
message
)
=>
message
.
isPlural
);
bool
_
requiresIntlImport
()
=>
_allMessages
.
any
((
Message
message
)
=>
message
.
isPlural
||
message
.
placeholdersRequireFormatting
);
void
writeOutputFiles
(
Logger
logger
,
{
bool
isFromYaml
=
false
})
{
// First, generate the string contents of all necessary files.
...
...
packages/flutter_tools/test/general.shard/generate_localizations_test.dart
View file @
485c4091
...
...
@@ -1489,6 +1489,41 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
});
group
(
'DateTime tests'
,
()
{
testWithoutContext
(
'imports package:intl'
,
()
{
const
String
singleDateMessageArbFileString
=
'''
{
"@@locale": "en",
"springBegins": "Spring begins on {springStartDate}",
"@springBegins": {
"description": "The first day of spring",
"placeholders": {
"springStartDate": {
"type": "DateTime",
"format": "yMd"
}
}
}
}'''
;
fs
.
currentDirectory
.
childDirectory
(
'lib'
).
childDirectory
(
'l10n'
)..
createSync
(
recursive:
true
)
..
childFile
(
defaultTemplateArbFileName
).
writeAsStringSync
(
singleDateMessageArbFileString
);
LocalizationsGenerator
(
fileSystem:
fs
,
inputPathString:
defaultL10nPathString
,
outputPathString:
defaultL10nPathString
,
templateArbFileName:
defaultTemplateArbFileName
,
outputFileString:
defaultOutputFileString
,
classNameString:
defaultClassNameString
,
)
..
loadResources
()
..
writeOutputFiles
(
BufferLogger
.
test
());
final
String
localizationsFile
=
fs
.
file
(
fs
.
path
.
join
(
syntheticL10nPackagePath
,
'output-localization-file_en.dart'
),
).
readAsStringSync
();
expect
(
localizationsFile
,
contains
(
intlImportDartCode
));
});
testWithoutContext
(
'throws an exception when improperly formatted date is passed in'
,
()
{
const
String
singleDateMessageArbFileString
=
'''
{
...
...
@@ -1565,6 +1600,44 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
fail
(
'Improper date formatting should throw an exception'
);
});
});
group
(
'NumberFormat tests'
,
()
{
testWithoutContext
(
'imports package:intl'
,
()
{
const
String
singleDateMessageArbFileString
=
'''
{
"courseCompletion": "You have completed {progress} of the course.",
"@courseCompletion": {
"description": "The amount of progress the student has made in their class.",
"placeholders": {
"progress": {
"type": "double",
"format": "percentPattern"
}
}
}
}'''
;
fs
.
currentDirectory
.
childDirectory
(
'lib'
).
childDirectory
(
'l10n'
)
..
createSync
(
recursive:
true
)
..
childFile
(
defaultTemplateArbFileName
).
writeAsStringSync
(
singleDateMessageArbFileString
);
LocalizationsGenerator
(
fileSystem:
fs
,
inputPathString:
defaultL10nPathString
,
outputPathString:
defaultL10nPathString
,
templateArbFileName:
defaultTemplateArbFileName
,
outputFileString:
defaultOutputFileString
,
classNameString:
defaultClassNameString
,
)
..
loadResources
()
..
writeOutputFiles
(
BufferLogger
.
test
());
final
String
localizationsFile
=
fs
.
file
(
fs
.
path
.
join
(
syntheticL10nPackagePath
,
'output-localization-file_en.dart'
),
).
readAsStringSync
();
expect
(
localizationsFile
,
contains
(
intlImportDartCode
));
});
testWithoutContext
(
'throws an exception when improperly formatted number is passed in'
,
()
{
const
String
singleDateMessageArbFileString
=
'''
...
...
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