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
29d814b7
Unverified
Commit
29d814b7
authored
Apr 27, 2022
by
Jonah Williams
Committed by
GitHub
Apr 27, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[intl] speed up localization generation and regenerate symbols (#102614)
parent
6d8f9ed9
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
2513 additions
and
2558 deletions
+2513
-2558
gen_date_localizations.dart
dev/tools/localization/bin/gen_date_localizations.dart
+57
-8
localizations_utils.dart
dev/tools/localization/localizations_utils.dart
+1
-1
generated_date_localizations.dart
...alizations/lib/src/l10n/generated_date_localizations.dart
+2454
-2546
date_localizations.dart
...utter_localizations/lib/src/utils/date_localizations.dart
+1
-3
No files found.
dev/tools/localization/bin/gen_date_localizations.dart
View file @
29d814b7
...
...
@@ -87,16 +87,26 @@ Future<void> main(List<String> rawArgs) async {
// To regenerate run (omit --overwrite to print to console instead of the file):
// dart --enable-asserts dev/tools/localization/bin/gen_date_localizations.dart --overwrite
import '
package:
intl
/
date_symbols
.
dart
' as intl;
'''
);
buffer
.
writeln
(
'''
/// The subset of date symbols supported by the intl package which are also
/// supported by flutter_localizations.'''
);
buffer
.
writeln
(
'
const Map<String, dynamic> dateSymbols = <String, dynamic
> {'
);
buffer
.
writeln
(
'
final Map<String, intl.DateSymbols> dateSymbols = <String, intl.DateSymbols
> {'
);
symbolFiles
.
forEach
((
String
locale
,
File
data
)
{
currentLocale
=
locale
;
if
(
supportedLocales
.
contains
(
locale
))
buffer
.
writeln
(
_jsonToMapEntry
(
locale
,
json
.
decode
(
data
.
readAsStringSync
())));
if
(
supportedLocales
.
contains
(
locale
))
{
final
Map
<
String
,
Object
?>
objData
=
json
.
decode
(
data
.
readAsStringSync
())
as
Map
<
String
,
Object
?>;
buffer
.
writeln
(
"'
$locale
': intl.DateSymbols("
);
objData
.
forEach
((
String
key
,
Object
?
value
)
{
if
(
value
==
null
)
return
;
buffer
.
writeln
(
_jsonToConstructorEntry
(
key
,
value
));
});
buffer
.
writeln
(
'),'
);
}
});
currentLocale
=
null
;
buffer
.
writeln
(
'};'
);
...
...
@@ -123,28 +133,67 @@ Future<void> main(List<String> rawArgs) async {
if
(
writeToFile
)
{
final
File
dateLocalizationsFile
=
File
(
path
.
join
(
'packages'
,
'flutter_localizations'
,
'lib'
,
'src'
,
'l10n'
,
'generated_date_localizations.dart'
));
dateLocalizationsFile
.
writeAsStringSync
(
buffer
.
toString
());
Process
.
runSync
(
path
.
join
(
'bin'
,
'cache'
,
'dart-sdk'
,
'bin'
,
'dartfmt'
),
<
String
>[
'-w'
,
final
String
extension
=
Platform
.
isWindows
?
'.exe'
:
''
;
final
ProcessResult
result
=
Process
.
runSync
(
path
.
join
(
'bin'
,
'cache'
,
'dart-sdk'
,
'bin'
,
'dart
$extension
'
),
<
String
>[
'format'
,
dateLocalizationsFile
.
path
,
]);
if
(
result
.
exitCode
!=
0
)
{
print
(
result
.
exitCode
);
print
(
result
.
stdout
);
print
(
result
.
stderr
);
}
}
else
{
print
(
buffer
);
}
}
String
_jsonToConstructorEntry
(
String
key
,
dynamic
value
)
{
return
'
$key
:
${_jsonToObject(value)}
,'
;
}
String
_jsonToMapEntry
(
String
key
,
dynamic
value
)
{
return
"'
$key
':
${_jsonToMap(value)}
,"
;
}
String
_jsonToObject
(
dynamic
json
)
{
if
(
json
==
null
||
json
is
num
||
json
is
bool
)
return
'
$json
'
;
if
(
json
is
String
)
return
generateEncodedString
(
currentLocale
,
json
);
if
(
json
is
Iterable
<
Object
?>)
{
final
String
type
=
json
.
first
.
runtimeType
.
toString
();
final
StringBuffer
buffer
=
StringBuffer
(
'const <
$type
>['
);
for
(
final
dynamic
value
in
json
)
{
buffer
.
writeln
(
'
${_jsonToMap(value)}
,'
);
}
buffer
.
write
(
']'
);
return
buffer
.
toString
();
}
if
(
json
is
Map
<
String
,
dynamic
>)
{
final
StringBuffer
buffer
=
StringBuffer
(
'<String, Object>{'
);
json
.
forEach
((
String
key
,
dynamic
value
)
{
buffer
.
writeln
(
_jsonToMapEntry
(
key
,
value
));
});
buffer
.
write
(
'}'
);
return
buffer
.
toString
();
}
throw
'Unsupported JSON type
${json.runtimeType}
of value
$json
.'
;
}
String
_jsonToMap
(
dynamic
json
)
{
if
(
json
==
null
||
json
is
num
||
json
is
bool
)
return
'
$json
'
;
if
(
json
is
String
)
return
generateEncodedString
(
currentLocale
!
,
json
);
return
generateEncodedString
(
currentLocale
,
json
);
if
(
json
is
Iterable
)
{
final
StringBuffer
buffer
=
StringBuffer
(
'<
dynamic
>['
);
final
StringBuffer
buffer
=
StringBuffer
(
'<
String
>['
);
for
(
final
dynamic
value
in
json
)
{
buffer
.
writeln
(
'
${_jsonToMap(value)}
,'
);
}
...
...
@@ -153,7 +202,7 @@ String _jsonToMap(dynamic json) {
}
if
(
json
is
Map
<
String
,
dynamic
>)
{
final
StringBuffer
buffer
=
StringBuffer
(
'<String,
dynamic
>{'
);
final
StringBuffer
buffer
=
StringBuffer
(
'<String,
Object
>{'
);
json
.
forEach
((
String
key
,
dynamic
value
)
{
buffer
.
writeln
(
_jsonToMapEntry
(
key
,
value
));
});
...
...
dev/tools/localization/localizations_utils.dart
View file @
29d814b7
...
...
@@ -427,7 +427,7 @@ String generateString(String value) {
/// Only used to generate localization strings for the Kannada locale ('kn') because
/// some of the localized strings contain characters that can crash Emacs on Linux.
/// See packages/flutter_localizations/lib/src/l10n/README for more information.
String
generateEncodedString
(
String
locale
,
String
value
)
{
String
generateEncodedString
(
String
?
locale
,
String
value
)
{
if
(
locale
!=
'kn'
||
value
.
runes
.
every
((
int
code
)
=>
code
<=
0xFF
))
return
generateString
(
value
);
...
...
packages/flutter_localizations/lib/src/l10n/generated_date_localizations.dart
View file @
29d814b7
This diff is collapsed.
Click to expand it.
packages/flutter_localizations/lib/src/utils/date_localizations.dart
View file @
29d814b7
...
...
@@ -17,11 +17,9 @@ bool _dateIntlDataInitialized = false;
void
loadDateIntlDataIfNotLoaded
(
)
{
if
(!
_dateIntlDataInitialized
)
{
date_localizations
.
dateSymbols
.
cast
<
String
,
Map
<
String
,
dynamic
>>()
.
forEach
((
String
locale
,
Map
<
String
,
dynamic
>
data
)
{
.
forEach
((
String
locale
,
intl
.
DateSymbols
symbols
)
{
// Perform initialization.
assert
(
date_localizations
.
datePatterns
.
containsKey
(
locale
));
final
intl
.
DateSymbols
symbols
=
intl
.
DateSymbols
.
deserializeFromMap
(
data
);
date_symbol_data_custom
.
initializeDateFormattingCustom
(
locale:
locale
,
symbols:
symbols
,
...
...
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