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
550281e5
Unverified
Commit
550281e5
authored
Nov 08, 2021
by
J-P Nurmi
Committed by
GitHub
Nov 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[gen_l10n] retain full output file suffix (#88362)
parent
2b33dae9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
7 deletions
+109
-7
gen_l10n.dart
packages/flutter_tools/lib/src/localizations/gen_l10n.dart
+18
-4
generate_localizations_test.dart
...tools/test/general.shard/generate_localizations_test.dart
+91
-3
No files found.
packages/flutter_tools/lib/src/localizations/gen_l10n.dart
View file @
550281e5
...
@@ -1167,6 +1167,12 @@ class LocalizationsGenerator {
...
@@ -1167,6 +1167,12 @@ class LocalizationsGenerator {
final
String
directory
=
_fs
.
path
.
basename
(
outputDirectory
.
path
);
final
String
directory
=
_fs
.
path
.
basename
(
outputDirectory
.
path
);
final
String
outputFileName
=
_fs
.
path
.
basename
(
baseOutputFile
.
path
);
final
String
outputFileName
=
_fs
.
path
.
basename
(
baseOutputFile
.
path
);
if
(!
outputFileName
.
endsWith
(
'.dart'
))
{
throw
L10nException
(
"The 'output-localization-file',
$outputFileName
, is invalid.
\n
"
'The file name must have a .dart extension.'
);
}
final
Iterable
<
String
>
supportedLocalesCode
=
supportedLocales
.
map
((
LocaleInfo
locale
)
{
final
Iterable
<
String
>
supportedLocalesCode
=
supportedLocales
.
map
((
LocaleInfo
locale
)
{
final
String
languageCode
=
locale
.
languageCode
;
final
String
languageCode
=
locale
.
languageCode
;
...
@@ -1189,10 +1195,18 @@ class LocalizationsGenerator {
...
@@ -1189,10 +1195,18 @@ class LocalizationsGenerator {
);
);
final
List
<
LocaleInfo
>
allLocales
=
_allBundles
.
locales
.
toList
()..
sort
();
final
List
<
LocaleInfo
>
allLocales
=
_allBundles
.
locales
.
toList
()..
sort
();
final
String
fileName
=
outputFileName
.
split
(
'.'
)[
0
];
final
int
extensionIndex
=
outputFileName
.
indexOf
(
'.'
);
if
(
extensionIndex
<=
0
)
{
throw
L10nException
(
"The 'output-localization-file',
$outputFileName
, is invalid.
\n
"
'The base name cannot be empty.'
);
}
final
String
fileName
=
outputFileName
.
substring
(
0
,
extensionIndex
);
final
String
fileExtension
=
outputFileName
.
substring
(
extensionIndex
+
1
);
for
(
final
LocaleInfo
locale
in
allLocales
)
{
for
(
final
LocaleInfo
locale
in
allLocales
)
{
if
(
isBaseClassLocale
(
locale
,
locale
.
languageCode
))
{
if
(
isBaseClassLocale
(
locale
,
locale
.
languageCode
))
{
final
File
languageMessageFile
=
outputDirectory
.
childFile
(
'
${fileName}
_
$locale
.
dart
'
);
final
File
languageMessageFile
=
outputDirectory
.
childFile
(
'
${fileName}
_
$locale
.
$fileExtension
'
);
// Generate the template for the base class file. Further string
// Generate the template for the base class file. Further string
// interpolation will be done to determine if there are
// interpolation will be done to determine if there are
...
@@ -1229,9 +1243,9 @@ class LocalizationsGenerator {
...
@@ -1229,9 +1243,9 @@ class LocalizationsGenerator {
.
map
((
LocaleInfo
locale
)
{
.
map
((
LocaleInfo
locale
)
{
final
String
library
=
'
${fileName}
_
${locale.toString()}
'
;
final
String
library
=
'
${fileName}
_
${locale.toString()}
'
;
if
(
useDeferredLoading
)
{
if
(
useDeferredLoading
)
{
return
"import '
$library
.
dart
' deferred as
$library
;"
;
return
"import '
$library
.
$fileExtension
' deferred as
$library
;"
;
}
else
{
}
else
{
return
"import '
$library
.
dart
';"
;
return
"import '
$library
.
$fileExtension
';"
;
}
}
})
})
.
toList
()
.
toList
()
...
...
packages/flutter_tools/test/general.shard/generate_localizations_test.dart
View file @
550281e5
...
@@ -751,7 +751,7 @@ void main() {
...
@@ -751,7 +751,7 @@ void main() {
arbDirectory:
Uri
.
directory
(
defaultL10nPathString
),
arbDirectory:
Uri
.
directory
(
defaultL10nPathString
),
deferredLoading:
true
,
deferredLoading:
true
,
outputClass:
'Foo'
,
outputClass:
'Foo'
,
outputLocalizationsFile:
Uri
.
file
(
'bar'
,
windows:
false
),
outputLocalizationsFile:
Uri
.
file
(
'bar
.dart
'
,
windows:
false
),
outputDirectory:
Uri
.
directory
(
defaultL10nPathString
,
windows:
false
),
outputDirectory:
Uri
.
directory
(
defaultL10nPathString
,
windows:
false
),
preferredSupportedLocales:
<
String
>[
'es'
],
preferredSupportedLocales:
<
String
>[
'es'
],
templateArbFile:
Uri
.
file
(
defaultTemplateArbFileName
,
windows:
false
),
templateArbFile:
Uri
.
file
(
defaultTemplateArbFileName
,
windows:
false
),
...
@@ -773,7 +773,7 @@ void main() {
...
@@ -773,7 +773,7 @@ void main() {
expect
(
generator
.
inputDirectory
.
path
,
'/lib/l10n/'
);
expect
(
generator
.
inputDirectory
.
path
,
'/lib/l10n/'
);
expect
(
generator
.
outputDirectory
.
path
,
'/lib/l10n/'
);
expect
(
generator
.
outputDirectory
.
path
,
'/lib/l10n/'
);
expect
(
generator
.
templateArbFile
.
path
,
'/lib/l10n/app_en.arb'
);
expect
(
generator
.
templateArbFile
.
path
,
'/lib/l10n/app_en.arb'
);
expect
(
generator
.
baseOutputFile
.
path
,
'/lib/l10n/bar'
);
expect
(
generator
.
baseOutputFile
.
path
,
'/lib/l10n/bar
.dart
'
);
expect
(
generator
.
className
,
'Foo'
);
expect
(
generator
.
className
,
'Foo'
);
expect
(
generator
.
preferredSupportedLocales
.
single
,
LocaleInfo
.
fromString
(
'es'
));
expect
(
generator
.
preferredSupportedLocales
.
single
,
LocaleInfo
.
fromString
(
'es'
));
expect
(
generator
.
header
,
'HEADER'
);
expect
(
generator
.
header
,
'HEADER'
);
...
@@ -790,7 +790,7 @@ void main() {
...
@@ -790,7 +790,7 @@ void main() {
HEADER
HEADER
import '
bar
';
import '
bar
.
dart
';
/// The translations for English (`en`).
/// The translations for English (`en`).
class FooEn extends Foo {
class FooEn extends Foo {
...
@@ -1322,6 +1322,94 @@ import 'output-localization-file_zh.dart';
...
@@ -1322,6 +1322,94 @@ import 'output-localization-file_zh.dart';
'''
));
'''
));
});
});
// Regression test for https://github.com/flutter/flutter/issues/88356
testWithoutContext
(
'full output file suffix is retained'
,
()
{
fs
.
currentDirectory
.
childDirectory
(
'lib'
).
childDirectory
(
'l10n'
)..
createSync
(
recursive:
true
)
..
childFile
(
defaultTemplateArbFileName
).
writeAsStringSync
(
singleMessageArbFileString
);
LocalizationsGenerator
(
fileSystem:
fs
,
inputPathString:
defaultL10nPathString
,
outputPathString:
defaultL10nPathString
,
templateArbFileName:
defaultTemplateArbFileName
,
outputFileString:
'output-localization-file.g.dart'
,
classNameString:
defaultClassNameString
,
)
..
loadResources
()
..
writeOutputFiles
(
BufferLogger
.
test
());
final
String
baseLocalizationsFile
=
fs
.
file
(
fs
.
path
.
join
(
syntheticL10nPackagePath
,
'output-localization-file.g.dart'
),
).
readAsStringSync
();
expect
(
baseLocalizationsFile
,
contains
(
'''
import '
output
-
localization
-
file_en
.
g
.
dart
';
'''
));
final
String
englishLocalizationsFile
=
fs
.
file
(
fs
.
path
.
join
(
syntheticL10nPackagePath
,
'output-localization-file_en.g.dart'
),
).
readAsStringSync
();
expect
(
englishLocalizationsFile
,
contains
(
'''
import '
output
-
localization
-
file
.
g
.
dart
';
'''
));
});
testWithoutContext
(
'throws an exception when invalid output file name is passed in'
,
()
{
fs
.
currentDirectory
.
childDirectory
(
'lib'
).
childDirectory
(
'l10n'
)..
createSync
(
recursive:
true
)
..
childFile
(
defaultTemplateArbFileName
).
writeAsStringSync
(
singleMessageArbFileString
);
expect
(
()
{
LocalizationsGenerator
(
fileSystem:
fs
,
inputPathString:
defaultL10nPathString
,
outputPathString:
defaultL10nPathString
,
templateArbFileName:
defaultTemplateArbFileName
,
outputFileString:
'asdf'
,
classNameString:
defaultClassNameString
,
)
..
loadResources
()
..
writeOutputFiles
(
BufferLogger
.
test
());
},
throwsA
(
isA
<
L10nException
>().
having
(
(
L10nException
e
)
=>
e
.
message
,
'message'
,
allOf
(
contains
(
'output-localization-file'
),
contains
(
'asdf'
),
contains
(
'is invalid'
),
contains
(
'The file name must have a .dart extension.'
),
),
)),
);
expect
(
()
{
LocalizationsGenerator
(
fileSystem:
fs
,
inputPathString:
defaultL10nPathString
,
outputPathString:
defaultL10nPathString
,
templateArbFileName:
defaultTemplateArbFileName
,
outputFileString:
'.g.dart'
,
classNameString:
defaultClassNameString
,
)
..
loadResources
()
..
writeOutputFiles
(
BufferLogger
.
test
());
},
throwsA
(
isA
<
L10nException
>().
having
(
(
L10nException
e
)
=>
e
.
message
,
'message'
,
allOf
(
contains
(
'output-localization-file'
),
contains
(
'.g.dart'
),
contains
(
'is invalid'
),
contains
(
'The base name cannot be empty.'
),
),
)),
);
});
testWithoutContext
(
'imports are deferred and loaded when useDeferredImports are set'
,
()
{
testWithoutContext
(
'imports are deferred and loaded when useDeferredImports are set'
,
()
{
fs
.
currentDirectory
.
childDirectory
(
'lib'
).
childDirectory
(
'l10n'
)..
createSync
(
recursive:
true
)
fs
.
currentDirectory
.
childDirectory
(
'lib'
).
childDirectory
(
'l10n'
)..
createSync
(
recursive:
true
)
..
childFile
(
defaultTemplateArbFileName
).
writeAsStringSync
(
singleMessageArbFileString
);
..
childFile
(
defaultTemplateArbFileName
).
writeAsStringSync
(
singleMessageArbFileString
);
...
...
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