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
728a1933
Unverified
Commit
728a1933
authored
Apr 20, 2021
by
Jenn Magder
Committed by
GitHub
Apr 20, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate gen_l10n to null safety (#80763)
parent
4cceeaa0
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
140 additions
and
263 deletions
+140
-263
gen_l10n.dart
packages/flutter_tools/lib/src/localizations/gen_l10n.dart
+109
-169
gen_l10n_types.dart
...s/flutter_tools/lib/src/localizations/gen_l10n_types.dart
+28
-28
generate_localizations_test.dart
...tools/test/general.shard/generate_localizations_test.dart
+3
-66
No files found.
packages/flutter_tools/lib/src/localizations/gen_l10n.dart
View file @
728a1933
This diff is collapsed.
Click to expand it.
packages/flutter_tools/lib/src/localizations/gen_l10n_types.dart
View file @
728a1933
...
@@ -187,7 +187,7 @@ class OptionalParameter {
...
@@ -187,7 +187,7 @@ class OptionalParameter {
// }
// }
//
//
class
Placeholder
{
class
Placeholder
{
Placeholder
(
this
.
resourceId
,
this
.
name
,
Map
<
String
,
dynamic
>
attributes
)
Placeholder
(
this
.
resourceId
,
this
.
name
,
Map
<
String
,
Object
?
>
attributes
)
:
assert
(
resourceId
!=
null
),
:
assert
(
resourceId
!=
null
),
assert
(
name
!=
null
),
assert
(
name
!=
null
),
example
=
_stringAttribute
(
resourceId
,
name
,
attributes
,
'example'
),
example
=
_stringAttribute
(
resourceId
,
name
,
attributes
,
'example'
),
...
@@ -212,10 +212,10 @@ class Placeholder {
...
@@ -212,10 +212,10 @@ class Placeholder {
static
String
?
_stringAttribute
(
static
String
?
_stringAttribute
(
String
resourceId
,
String
resourceId
,
String
name
,
String
name
,
Map
<
String
,
dynamic
>
attributes
,
Map
<
String
,
Object
?
>
attributes
,
String
attributeName
,
String
attributeName
,
)
{
)
{
final
dynamic
value
=
attributes
[
attributeName
];
final
Object
?
value
=
attributes
[
attributeName
];
if
(
value
==
null
)
{
if
(
value
==
null
)
{
return
null
;
return
null
;
}
}
...
@@ -231,9 +231,9 @@ class Placeholder {
...
@@ -231,9 +231,9 @@ class Placeholder {
static
List
<
OptionalParameter
>
_optionalParameters
(
static
List
<
OptionalParameter
>
_optionalParameters
(
String
resourceId
,
String
resourceId
,
String
name
,
String
name
,
Map
<
String
,
dynamic
>
attributes
Map
<
String
,
Object
?
>
attributes
)
{
)
{
final
dynamic
value
=
attributes
[
'optionalParameters'
];
final
Object
?
value
=
attributes
[
'optionalParameters'
];
if
(
value
==
null
)
{
if
(
value
==
null
)
{
return
<
OptionalParameter
>[];
return
<
OptionalParameter
>[];
}
}
...
@@ -267,7 +267,7 @@ class Placeholder {
...
@@ -267,7 +267,7 @@ class Placeholder {
// localized string to be shown for the template ARB file's locale.
// localized string to be shown for the template ARB file's locale.
// The docs for the Placeholder explain how placeholder entries are defined.
// The docs for the Placeholder explain how placeholder entries are defined.
class
Message
{
class
Message
{
Message
(
Map
<
String
,
dynamic
>
bundle
,
this
.
resourceId
,
bool
isResourceAttributeRequired
)
Message
(
Map
<
String
,
Object
?
>
bundle
,
this
.
resourceId
,
bool
isResourceAttributeRequired
)
:
assert
(
bundle
!=
null
),
:
assert
(
bundle
!=
null
),
assert
(
resourceId
!=
null
&&
resourceId
.
isNotEmpty
),
assert
(
resourceId
!=
null
&&
resourceId
.
isNotEmpty
),
value
=
_value
(
bundle
,
resourceId
),
value
=
_value
(
bundle
,
resourceId
),
...
@@ -298,23 +298,23 @@ class Message {
...
@@ -298,23 +298,23 @@ class Message {
);
);
}
}
static
String
_value
(
Map
<
String
,
dynamic
>
bundle
,
String
resourceId
)
{
static
String
_value
(
Map
<
String
,
Object
?
>
bundle
,
String
resourceId
)
{
final
dynamic
value
=
bundle
[
resourceId
];
final
Object
?
value
=
bundle
[
resourceId
];
if
(
value
==
null
)
{
if
(
value
==
null
)
{
throw
L10nException
(
'A value for resource "
$resourceId
" was not found.'
);
throw
L10nException
(
'A value for resource "
$resourceId
" was not found.'
);
}
}
if
(
value
is
!
String
)
{
if
(
value
is
!
String
)
{
throw
L10nException
(
'The value of "
$resourceId
" is not a string.'
);
throw
L10nException
(
'The value of "
$resourceId
" is not a string.'
);
}
}
return
bundle
[
resourceId
]
as
String
;
return
value
;
}
}
static
Map
<
String
,
dynamic
>
_attributes
(
static
Map
<
String
,
Object
?>?
_attributes
(
Map
<
String
,
dynamic
>
bundle
,
Map
<
String
,
Object
?
>
bundle
,
String
resourceId
,
String
resourceId
,
bool
isResourceAttributeRequired
,
bool
isResourceAttributeRequired
,
)
{
)
{
final
dynamic
attributes
=
bundle
[
'@
$resourceId
'
];
final
Object
?
attributes
=
bundle
[
'@
$resourceId
'
];
if
(
isResourceAttributeRequired
)
{
if
(
isResourceAttributeRequired
)
{
if
(
attributes
==
null
)
{
if
(
attributes
==
null
)
{
throw
L10nException
(
throw
L10nException
(
...
@@ -324,7 +324,7 @@ class Message {
...
@@ -324,7 +324,7 @@ class Message {
}
}
}
}
if
(
attributes
!=
null
&&
attributes
is
!
Map
<
String
,
dynamic
>)
{
if
(
attributes
!=
null
&&
attributes
is
!
Map
<
String
,
Object
?
>)
{
throw
L10nException
(
throw
L10nException
(
'The resource attribute "@
$resourceId
" is not a properly formatted Map. '
'The resource attribute "@
$resourceId
" is not a properly formatted Map. '
'Ensure that it is a map with keys that are strings.'
'Ensure that it is a map with keys that are strings.'
...
@@ -340,20 +340,20 @@ class Message {
...
@@ -340,20 +340,20 @@ class Message {
);
);
}
}
return
attributes
as
Map
<
String
,
dynamic
>
;
return
attributes
as
Map
<
String
,
Object
?>?
;
}
}
static
String
?
_description
(
static
String
?
_description
(
Map
<
String
,
dynamic
>
bundle
,
Map
<
String
,
Object
?
>
bundle
,
String
resourceId
,
String
resourceId
,
bool
isResourceAttributeRequired
,
bool
isResourceAttributeRequired
,
)
{
)
{
final
Map
<
String
,
dynamic
>
resourceAttributes
=
_attributes
(
bundle
,
resourceId
,
isResourceAttributeRequired
);
final
Map
<
String
,
Object
?>?
resourceAttributes
=
_attributes
(
bundle
,
resourceId
,
isResourceAttributeRequired
);
if
(
resourceAttributes
==
null
)
{
if
(
resourceAttributes
==
null
)
{
return
null
;
return
null
;
}
}
final
dynamic
value
=
resourceAttributes
[
'description'
];
final
Object
?
value
=
resourceAttributes
[
'description'
];
if
(
value
==
null
)
{
if
(
value
==
null
)
{
return
null
;
return
null
;
}
}
...
@@ -366,27 +366,27 @@ class Message {
...
@@ -366,27 +366,27 @@ class Message {
}
}
static
List
<
Placeholder
>
_placeholders
(
static
List
<
Placeholder
>
_placeholders
(
Map
<
String
,
dynamic
>
bundle
,
Map
<
String
,
Object
?
>
bundle
,
String
resourceId
,
String
resourceId
,
bool
isResourceAttributeRequired
,
bool
isResourceAttributeRequired
,
)
{
)
{
final
Map
<
String
,
dynamic
>
resourceAttributes
=
_attributes
(
bundle
,
resourceId
,
isResourceAttributeRequired
);
final
Map
<
String
,
Object
?>?
resourceAttributes
=
_attributes
(
bundle
,
resourceId
,
isResourceAttributeRequired
);
if
(
resourceAttributes
==
null
)
{
if
(
resourceAttributes
==
null
)
{
return
<
Placeholder
>[];
return
<
Placeholder
>[];
}
}
final
dynamic
allPlaceholdersMap
=
resourceAttributes
[
'placeholders'
];
final
Object
?
allPlaceholdersMap
=
resourceAttributes
[
'placeholders'
];
if
(
allPlaceholdersMap
==
null
)
{
if
(
allPlaceholdersMap
==
null
)
{
return
<
Placeholder
>[];
return
<
Placeholder
>[];
}
}
if
(
allPlaceholdersMap
is
!
Map
<
String
,
dynamic
>)
{
if
(
allPlaceholdersMap
is
!
Map
<
String
,
Object
?
>)
{
throw
L10nException
(
throw
L10nException
(
'The "placeholders" attribute for message
$resourceId
, is not '
'The "placeholders" attribute for message
$resourceId
, is not '
'properly formatted. Ensure that it is a map with string valued keys.'
'properly formatted. Ensure that it is a map with string valued keys.'
);
);
}
}
return
allPlaceholdersMap
.
keys
.
map
<
Placeholder
>((
String
placeholderName
)
{
return
allPlaceholdersMap
.
keys
.
map
<
Placeholder
>((
String
placeholderName
)
{
final
dynamic
value
=
allPlaceholdersMap
[
placeholderName
];
final
Object
?
value
=
allPlaceholdersMap
[
placeholderName
];
if
(
value
is
!
Map
<
String
,
dynamic
>)
{
if
(
value
is
!
Map
<
String
,
Object
?
>)
{
throw
L10nException
(
throw
L10nException
(
'The value of the "
$placeholderName
" placeholder attribute for message '
'The value of the "
$placeholderName
" placeholder attribute for message '
'"
$resourceId
", is not properly formatted. Ensure that it is a map '
'"
$resourceId
", is not properly formatted. Ensure that it is a map '
...
@@ -403,9 +403,9 @@ class AppResourceBundle {
...
@@ -403,9 +403,9 @@ class AppResourceBundle {
factory
AppResourceBundle
(
File
file
)
{
factory
AppResourceBundle
(
File
file
)
{
assert
(
file
!=
null
);
assert
(
file
!=
null
);
// Assuming that the caller has verified that the file exists and is readable.
// Assuming that the caller has verified that the file exists and is readable.
Map
<
String
,
dynamic
>
resources
;
Map
<
String
,
Object
?
>
resources
;
try
{
try
{
resources
=
json
.
decode
(
file
.
readAsStringSync
())
as
Map
<
String
,
dynamic
>;
resources
=
json
.
decode
(
file
.
readAsStringSync
())
as
Map
<
String
,
Object
?
>;
}
on
FormatException
catch
(
e
)
{
}
on
FormatException
catch
(
e
)
{
throw
L10nException
(
throw
L10nException
(
'The arb file
${file.path}
has the following formatting issue:
\n
'
'The arb file
${file.path}
has the following formatting issue:
\n
'
...
@@ -413,7 +413,7 @@ class AppResourceBundle {
...
@@ -413,7 +413,7 @@ class AppResourceBundle {
);
);
}
}
String
localeString
=
resources
[
'@@locale'
]
as
String
;
String
?
localeString
=
resources
[
'@@locale'
]
as
String
?
;
// Look for the first instance of an ISO 639-1 language code, matching exactly.
// Look for the first instance of an ISO 639-1 language code, matching exactly.
final
String
fileName
=
file
.
fileSystem
.
path
.
basenameWithoutExtension
(
file
.
path
);
final
String
fileName
=
file
.
fileSystem
.
path
.
basenameWithoutExtension
(
file
.
path
);
...
@@ -470,10 +470,10 @@ class AppResourceBundle {
...
@@ -470,10 +470,10 @@ class AppResourceBundle {
final
File
file
;
final
File
file
;
final
LocaleInfo
locale
;
final
LocaleInfo
locale
;
final
Map
<
String
,
dynamic
>
resources
;
final
Map
<
String
,
Object
?
>
resources
;
final
Iterable
<
String
>
resourceIds
;
final
Iterable
<
String
>
resourceIds
;
String
translationFor
(
Message
message
)
=>
resources
[
message
.
resourceId
]
as
String
;
String
?
translationFor
(
Message
message
)
=>
resources
[
message
.
resourceId
]
as
String
?
;
@override
@override
String
toString
()
{
String
toString
()
{
...
...
packages/flutter_tools/test/general.shard/generate_localizations_test.dart
View file @
728a1933
...
@@ -98,75 +98,12 @@ void main() {
...
@@ -98,75 +98,12 @@ void main() {
);
);
});
});
testWithoutContext
(
'set
InputDirectory fails if input string is null
'
,
()
{
testWithoutContext
(
'set
ting className fails if input string is empty
'
,
()
{
_standardFlutterDirectoryL10nSetup
(
fs
);
_standardFlutterDirectoryL10nSetup
(
fs
);
try
{
try
{
LocalizationsGenerator
.
inputDirectoryFromPath
(
fs
,
null
,
fs
.
directory
(
'bogus'
)
);
LocalizationsGenerator
.
classNameFromString
(
''
);
}
on
L10nException
catch
(
e
)
{
}
on
L10nException
catch
(
e
)
{
expect
(
e
.
message
,
contains
(
'cannot be null'
));
expect
(
e
.
message
,
contains
(
'cannot be empty'
));
return
;
}
fail
(
'LocalizationsGenerator.setInputDirectory should fail if the '
'input string is null.'
);
});
testWithoutContext
(
'setOutputDirectory fails if output string is null while not using the '
'synthetic package option'
,
()
{
_standardFlutterDirectoryL10nSetup
(
fs
);
try
{
LocalizationsGenerator
.
outputDirectoryFromPath
(
fs
,
null
,
false
,
null
);
}
on
L10nException
catch
(
e
)
{
expect
(
e
.
message
,
contains
(
'cannot be null'
));
return
;
}
fail
(
'LocalizationsGenerator.setOutputDirectory should fail if the '
'input string is null.'
);
},
);
testWithoutContext
(
'setTemplateArbFile fails if inputDirectory is null'
,
()
{
try
{
LocalizationsGenerator
.
templateArbFileFromFileName
(
defaultTemplateArbFileName
,
null
);
}
on
L10nException
catch
(
e
)
{
expect
(
e
.
message
,
contains
(
'cannot be null'
));
return
;
}
fail
(
'LocalizationsGenerator.setTemplateArbFile should fail if the '
'inputDirectory is not specified.'
);
});
testWithoutContext
(
'setTemplateArbFile fails if templateArbFileName is null'
,
()
{
_standardFlutterDirectoryL10nSetup
(
fs
);
try
{
LocalizationsGenerator
.
templateArbFileFromFileName
(
null
,
fs
.
directory
(
'bogus'
));
}
on
L10nException
catch
(
e
)
{
expect
(
e
.
message
,
contains
(
'cannot be null'
));
return
;
}
fail
(
'LocalizationsGenerator.setTemplateArbFile should fail if the '
'templateArbFileName passed in is null.'
);
});
testWithoutContext
(
'setting className fails if input string is null'
,
()
{
_standardFlutterDirectoryL10nSetup
(
fs
);
try
{
LocalizationsGenerator
.
classNameFromString
(
null
);
}
on
L10nException
catch
(
e
)
{
expect
(
e
.
message
,
contains
(
'cannot be null'
));
return
;
return
;
}
}
...
...
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