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
d6c77320
Unverified
Commit
d6c77320
authored
Mar 29, 2021
by
Jenn Magder
Committed by
GitHub
Mar 29, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate gen_l10n_types to null safety (#79108)
parent
5231a7dc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
29 deletions
+23
-29
gen_l10n_types.dart
...s/flutter_tools/lib/src/localizations/gen_l10n_types.dart
+23
-29
No files found.
packages/flutter_tools/lib/src/localizations/gen_l10n_types.dart
View file @
d6c77320
...
@@ -2,15 +2,10 @@
...
@@ -2,15 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.8
import
'package:intl/locale.dart'
;
import
'package:intl/locale.dart'
;
import
'../base/file_system.dart'
;
import
'../base/file_system.dart'
;
import
'../convert.dart'
;
import
'../convert.dart'
;
import
'../globals.dart'
as
globals
;
import
'localizations_utils.dart'
;
import
'localizations_utils.dart'
;
// The set of date formats that can be automatically localized.
// The set of date formats that can be automatically localized.
...
@@ -202,9 +197,9 @@ class Placeholder {
...
@@ -202,9 +197,9 @@ class Placeholder {
final
String
resourceId
;
final
String
resourceId
;
final
String
name
;
final
String
name
;
final
String
example
;
final
String
?
example
;
final
String
type
;
final
String
?
type
;
final
String
format
;
final
String
?
format
;
final
List
<
OptionalParameter
>
optionalParameters
;
final
List
<
OptionalParameter
>
optionalParameters
;
bool
get
requiresFormatting
=>
<
String
>[
'DateTime'
,
'double'
,
'int'
,
'num'
].
contains
(
type
);
bool
get
requiresFormatting
=>
<
String
>[
'DateTime'
,
'double'
,
'int'
,
'num'
].
contains
(
type
);
...
@@ -214,7 +209,7 @@ class Placeholder {
...
@@ -214,7 +209,7 @@ class Placeholder {
bool
get
isDate
=>
'DateTime'
==
type
;
bool
get
isDate
=>
'DateTime'
==
type
;
bool
get
hasValidDateFormat
=>
_validDateFormats
.
contains
(
format
);
bool
get
hasValidDateFormat
=>
_validDateFormats
.
contains
(
format
);
static
String
_stringAttribute
(
static
String
?
_stringAttribute
(
String
resourceId
,
String
resourceId
,
String
name
,
String
name
,
Map
<
String
,
dynamic
>
attributes
,
Map
<
String
,
dynamic
>
attributes
,
...
@@ -224,13 +219,13 @@ class Placeholder {
...
@@ -224,13 +219,13 @@ class Placeholder {
if
(
value
==
null
)
{
if
(
value
==
null
)
{
return
null
;
return
null
;
}
}
if
(
value
is
!
String
||
(
value
as
String
)
.
isEmpty
)
{
if
(
value
is
!
String
||
value
.
isEmpty
)
{
throw
L10nException
(
throw
L10nException
(
'The "
$attributeName
" value of the "
$name
" placeholder in message
$resourceId
'
'The "
$attributeName
" value of the "
$name
" placeholder in message
$resourceId
'
'must be a non-empty string.'
,
'must be a non-empty string.'
,
);
);
}
}
return
value
as
String
;
return
value
;
}
}
static
List
<
OptionalParameter
>
_optionalParameters
(
static
List
<
OptionalParameter
>
_optionalParameters
(
...
@@ -249,9 +244,9 @@ class Placeholder {
...
@@ -249,9 +244,9 @@ class Placeholder {
'with keys that are strings.'
'with keys that are strings.'
);
);
}
}
final
Map
<
String
,
dynamic
>
optionalParameterMap
=
value
as
Map
<
String
,
dynamic
>
;
final
Map
<
String
,
Object
>
optionalParameterMap
=
value
;
return
optionalParameterMap
.
keys
.
map
<
OptionalParameter
>((
String
parameterName
)
{
return
optionalParameterMap
.
keys
.
map
<
OptionalParameter
>((
String
parameterName
)
{
return
OptionalParameter
(
parameterName
,
optionalParameterMap
[
parameterName
]);
return
OptionalParameter
(
parameterName
,
optionalParameterMap
[
parameterName
]
!
);
}).
toList
();
}).
toList
();
}
}
}
}
...
@@ -284,17 +279,17 @@ class Message {
...
@@ -284,17 +279,17 @@ class Message {
final
String
resourceId
;
final
String
resourceId
;
final
String
value
;
final
String
value
;
final
String
description
;
final
String
?
description
;
final
List
<
Placeholder
>
placeholders
;
final
List
<
Placeholder
>
placeholders
;
final
RegExpMatch
_pluralMatch
;
final
RegExpMatch
?
_pluralMatch
;
bool
get
isPlural
=>
_pluralMatch
!=
null
&&
_pluralMatch
.
groupCount
==
1
;
bool
get
isPlural
=>
_pluralMatch
!=
null
&&
_pluralMatch
!
.
groupCount
==
1
;
bool
get
placeholdersRequireFormatting
=>
placeholders
.
any
((
Placeholder
p
)
=>
p
.
requiresFormatting
);
bool
get
placeholdersRequireFormatting
=>
placeholders
.
any
((
Placeholder
p
)
=>
p
.
requiresFormatting
);
Placeholder
getCountPlaceholder
()
{
Placeholder
getCountPlaceholder
()
{
assert
(
isPlural
);
assert
(
isPlural
);
final
String
countPlaceholderName
=
_pluralMatch
[
1
]
;
final
String
countPlaceholderName
=
_pluralMatch
![
1
]!
;
return
placeholders
.
firstWhere
(
return
placeholders
.
firstWhere
(
(
Placeholder
p
)
=>
p
.
name
==
countPlaceholderName
,
(
Placeholder
p
)
=>
p
.
name
==
countPlaceholderName
,
orElse:
()
{
orElse:
()
{
...
@@ -336,7 +331,7 @@ class Message {
...
@@ -336,7 +331,7 @@ class Message {
);
);
}
}
final
RegExpMatch
pluralRegExp
=
_pluralRE
.
firstMatch
(
_value
(
bundle
,
resourceId
));
final
RegExpMatch
?
pluralRegExp
=
_pluralRE
.
firstMatch
(
_value
(
bundle
,
resourceId
));
final
bool
isPlural
=
pluralRegExp
!=
null
&&
pluralRegExp
.
groupCount
==
1
;
final
bool
isPlural
=
pluralRegExp
!=
null
&&
pluralRegExp
.
groupCount
==
1
;
if
(
attributes
==
null
&&
isPlural
)
{
if
(
attributes
==
null
&&
isPlural
)
{
throw
L10nException
(
throw
L10nException
(
...
@@ -348,7 +343,7 @@ class Message {
...
@@ -348,7 +343,7 @@ class Message {
return
attributes
as
Map
<
String
,
dynamic
>;
return
attributes
as
Map
<
String
,
dynamic
>;
}
}
static
String
_description
(
static
String
?
_description
(
Map
<
String
,
dynamic
>
bundle
,
Map
<
String
,
dynamic
>
bundle
,
String
resourceId
,
String
resourceId
,
bool
isResourceAttributeRequired
,
bool
isResourceAttributeRequired
,
...
@@ -367,7 +362,7 @@ class Message {
...
@@ -367,7 +362,7 @@ class Message {
'The description for "@
$resourceId
" is not a properly formatted String.'
'The description for "@
$resourceId
" is not a properly formatted String.'
);
);
}
}
return
value
as
String
;
return
value
;
}
}
static
List
<
Placeholder
>
_placeholders
(
static
List
<
Placeholder
>
_placeholders
(
...
@@ -379,17 +374,16 @@ class Message {
...
@@ -379,17 +374,16 @@ class Message {
if
(
resourceAttributes
==
null
)
{
if
(
resourceAttributes
==
null
)
{
return
<
Placeholder
>[];
return
<
Placeholder
>[];
}
}
final
dynamic
value
=
resourceAttributes
[
'placeholders'
];
final
dynamic
allPlaceholdersMap
=
resourceAttributes
[
'placeholders'
];
if
(
value
==
null
)
{
if
(
allPlaceholdersMap
==
null
)
{
return
<
Placeholder
>[];
return
<
Placeholder
>[];
}
}
if
(
value
is
!
Map
<
String
,
dynamic
>)
{
if
(
allPlaceholdersMap
is
!
Map
<
String
,
dynamic
>)
{
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.'
);
);
}
}
final
Map
<
String
,
dynamic
>
allPlaceholdersMap
=
value
as
Map
<
String
,
dynamic
>;
return
allPlaceholdersMap
.
keys
.
map
<
Placeholder
>((
String
placeholderName
)
{
return
allPlaceholdersMap
.
keys
.
map
<
Placeholder
>((
String
placeholderName
)
{
final
dynamic
value
=
allPlaceholdersMap
[
placeholderName
];
final
dynamic
value
=
allPlaceholdersMap
[
placeholderName
];
if
(
value
is
!
Map
<
String
,
dynamic
>)
{
if
(
value
is
!
Map
<
String
,
dynamic
>)
{
...
@@ -399,7 +393,7 @@ class Message {
...
@@ -399,7 +393,7 @@ class Message {
'with string valued keys.'
'with string valued keys.'
);
);
}
}
return
Placeholder
(
resourceId
,
placeholderName
,
value
as
Map
<
String
,
dynamic
>
);
return
Placeholder
(
resourceId
,
placeholderName
,
value
);
}).
toList
();
}).
toList
();
}
}
}
}
...
@@ -422,13 +416,13 @@ class AppResourceBundle {
...
@@ -422,13 +416,13 @@ 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
=
globals
.
fs
.
path
.
basenameWithoutExtension
(
file
.
path
);
final
String
fileName
=
file
.
fileSystem
.
path
.
basenameWithoutExtension
(
file
.
path
);
for
(
int
index
=
0
;
index
<
fileName
.
length
;
index
+=
1
)
{
for
(
int
index
=
0
;
index
<
fileName
.
length
;
index
+=
1
)
{
// If an underscore was found, check if locale string follows.
// If an underscore was found, check if locale string follows.
if
(
fileName
[
index
]
==
'_'
&&
fileName
[
index
+
1
]
!=
null
)
{
if
(
fileName
[
index
]
==
'_'
&&
fileName
[
index
+
1
]
!=
null
)
{
// If Locale.tryParse fails, it returns null.
// If Locale.tryParse fails, it returns null.
final
Locale
parserResult
=
Locale
.
tryParse
(
fileName
.
substring
(
index
+
1
));
final
Locale
?
parserResult
=
Locale
.
tryParse
(
fileName
.
substring
(
index
+
1
));
// If the parserResult is not an actual locale identifier, end the loop.
// If the parserResult is not an actual locale identifier, end the loop.
if
(
parserResult
!=
null
&&
_iso639Languages
.
contains
(
parserResult
.
languageCode
))
{
if
(
parserResult
!=
null
&&
_iso639Languages
.
contains
(
parserResult
.
languageCode
))
{
// The parsed result uses dashes ('-'), but we want underscores ('_').
// The parsed result uses dashes ('-'), but we want underscores ('_').
...
@@ -508,7 +502,7 @@ class AppResourceBundleCollection {
...
@@ -508,7 +502,7 @@ class AppResourceBundleCollection {
}
}
localeToBundle
[
bundle
.
locale
]
=
bundle
;
localeToBundle
[
bundle
.
locale
]
=
bundle
;
languageToLocales
[
bundle
.
locale
.
languageCode
]
??=
<
LocaleInfo
>[];
languageToLocales
[
bundle
.
locale
.
languageCode
]
??=
<
LocaleInfo
>[];
languageToLocales
[
bundle
.
locale
.
languageCode
].
add
(
bundle
.
locale
);
languageToLocales
[
bundle
.
locale
.
languageCode
]
!
.
add
(
bundle
.
locale
);
}
}
}
}
...
@@ -539,7 +533,7 @@ class AppResourceBundleCollection {
...
@@ -539,7 +533,7 @@ class AppResourceBundleCollection {
Iterable
<
LocaleInfo
>
get
locales
=>
_localeToBundle
.
keys
;
Iterable
<
LocaleInfo
>
get
locales
=>
_localeToBundle
.
keys
;
Iterable
<
AppResourceBundle
>
get
bundles
=>
_localeToBundle
.
values
;
Iterable
<
AppResourceBundle
>
get
bundles
=>
_localeToBundle
.
values
;
AppResourceBundle
bundleFor
(
LocaleInfo
locale
)
=>
_localeToBundle
[
locale
];
AppResourceBundle
?
bundleFor
(
LocaleInfo
locale
)
=>
_localeToBundle
[
locale
];
Iterable
<
String
>
get
languages
=>
_languageToLocales
.
keys
;
Iterable
<
String
>
get
languages
=>
_languageToLocales
.
keys
;
Iterable
<
LocaleInfo
>
localesForLanguage
(
String
language
)
=>
_languageToLocales
[
language
]
??
<
LocaleInfo
>[];
Iterable
<
LocaleInfo
>
localesForLanguage
(
String
language
)
=>
_languageToLocales
[
language
]
??
<
LocaleInfo
>[];
...
...
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