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
Show 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 {
...
@@ -87,16 +87,26 @@ Future<void> main(List<String> rawArgs) async {
// To regenerate run (omit --overwrite to print to console instead of the file):
// 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
// dart --enable-asserts dev/tools/localization/bin/gen_date_localizations.dart --overwrite
import '
package:
intl
/
date_symbols
.
dart
' as intl;
'''
'''
);
);
buffer
.
writeln
(
'''
buffer
.
writeln
(
'''
/// The subset of date symbols supported by the intl package which are also
/// The subset of date symbols supported by the intl package which are also
/// supported by flutter_localizations.'''
);
/// 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
)
{
symbolFiles
.
forEach
((
String
locale
,
File
data
)
{
currentLocale
=
locale
;
currentLocale
=
locale
;
if
(
supportedLocales
.
contains
(
locale
))
if
(
supportedLocales
.
contains
(
locale
))
{
buffer
.
writeln
(
_jsonToMapEntry
(
locale
,
json
.
decode
(
data
.
readAsStringSync
())));
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
;
currentLocale
=
null
;
buffer
.
writeln
(
'};'
);
buffer
.
writeln
(
'};'
);
...
@@ -123,28 +133,67 @@ Future<void> main(List<String> rawArgs) async {
...
@@ -123,28 +133,67 @@ Future<void> main(List<String> rawArgs) async {
if
(
writeToFile
)
{
if
(
writeToFile
)
{
final
File
dateLocalizationsFile
=
File
(
path
.
join
(
'packages'
,
'flutter_localizations'
,
'lib'
,
'src'
,
'l10n'
,
'generated_date_localizations.dart'
));
final
File
dateLocalizationsFile
=
File
(
path
.
join
(
'packages'
,
'flutter_localizations'
,
'lib'
,
'src'
,
'l10n'
,
'generated_date_localizations.dart'
));
dateLocalizationsFile
.
writeAsStringSync
(
buffer
.
toString
());
dateLocalizationsFile
.
writeAsStringSync
(
buffer
.
toString
());
Process
.
runSync
(
path
.
join
(
'bin'
,
'cache'
,
'dart-sdk'
,
'bin'
,
'dartfmt'
),
<
String
>[
final
String
extension
=
Platform
.
isWindows
?
'.exe'
:
''
;
'-w'
,
final
ProcessResult
result
=
Process
.
runSync
(
path
.
join
(
'bin'
,
'cache'
,
'dart-sdk'
,
'bin'
,
'dart
$extension
'
),
<
String
>[
'format'
,
dateLocalizationsFile
.
path
,
dateLocalizationsFile
.
path
,
]);
]);
if
(
result
.
exitCode
!=
0
)
{
print
(
result
.
exitCode
);
print
(
result
.
stdout
);
print
(
result
.
stderr
);
}
}
else
{
}
else
{
print
(
buffer
);
print
(
buffer
);
}
}
}
}
String
_jsonToConstructorEntry
(
String
key
,
dynamic
value
)
{
return
'
$key
:
${_jsonToObject(value)}
,'
;
}
String
_jsonToMapEntry
(
String
key
,
dynamic
value
)
{
String
_jsonToMapEntry
(
String
key
,
dynamic
value
)
{
return
"'
$key
':
${_jsonToMap(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
)
{
String
_jsonToMap
(
dynamic
json
)
{
if
(
json
==
null
||
json
is
num
||
json
is
bool
)
if
(
json
==
null
||
json
is
num
||
json
is
bool
)
return
'
$json
'
;
return
'
$json
'
;
if
(
json
is
String
)
if
(
json
is
String
)
return
generateEncodedString
(
currentLocale
!
,
json
);
return
generateEncodedString
(
currentLocale
,
json
);
if
(
json
is
Iterable
)
{
if
(
json
is
Iterable
)
{
final
StringBuffer
buffer
=
StringBuffer
(
'<
dynamic
>['
);
final
StringBuffer
buffer
=
StringBuffer
(
'<
String
>['
);
for
(
final
dynamic
value
in
json
)
{
for
(
final
dynamic
value
in
json
)
{
buffer
.
writeln
(
'
${_jsonToMap(value)}
,'
);
buffer
.
writeln
(
'
${_jsonToMap(value)}
,'
);
}
}
...
@@ -153,7 +202,7 @@ String _jsonToMap(dynamic json) {
...
@@ -153,7 +202,7 @@ String _jsonToMap(dynamic json) {
}
}
if
(
json
is
Map
<
String
,
dynamic
>)
{
if
(
json
is
Map
<
String
,
dynamic
>)
{
final
StringBuffer
buffer
=
StringBuffer
(
'<String,
dynamic
>{'
);
final
StringBuffer
buffer
=
StringBuffer
(
'<String,
Object
>{'
);
json
.
forEach
((
String
key
,
dynamic
value
)
{
json
.
forEach
((
String
key
,
dynamic
value
)
{
buffer
.
writeln
(
_jsonToMapEntry
(
key
,
value
));
buffer
.
writeln
(
_jsonToMapEntry
(
key
,
value
));
});
});
...
...
dev/tools/localization/localizations_utils.dart
View file @
29d814b7
...
@@ -427,7 +427,7 @@ String generateString(String value) {
...
@@ -427,7 +427,7 @@ String generateString(String value) {
/// Only used to generate localization strings for the Kannada locale ('kn') because
/// 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.
/// some of the localized strings contain characters that can crash Emacs on Linux.
/// See packages/flutter_localizations/lib/src/l10n/README for more information.
/// 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
))
if
(
locale
!=
'kn'
||
value
.
runes
.
every
((
int
code
)
=>
code
<=
0xFF
))
return
generateString
(
value
);
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;
...
@@ -17,11 +17,9 @@ bool _dateIntlDataInitialized = false;
void
loadDateIntlDataIfNotLoaded
(
)
{
void
loadDateIntlDataIfNotLoaded
(
)
{
if
(!
_dateIntlDataInitialized
)
{
if
(!
_dateIntlDataInitialized
)
{
date_localizations
.
dateSymbols
date_localizations
.
dateSymbols
.
cast
<
String
,
Map
<
String
,
dynamic
>>()
.
forEach
((
String
locale
,
intl
.
DateSymbols
symbols
)
{
.
forEach
((
String
locale
,
Map
<
String
,
dynamic
>
data
)
{
// Perform initialization.
// Perform initialization.
assert
(
date_localizations
.
datePatterns
.
containsKey
(
locale
));
assert
(
date_localizations
.
datePatterns
.
containsKey
(
locale
));
final
intl
.
DateSymbols
symbols
=
intl
.
DateSymbols
.
deserializeFromMap
(
data
);
date_symbol_data_custom
.
initializeDateFormattingCustom
(
date_symbol_data_custom
.
initializeDateFormattingCustom
(
locale:
locale
,
locale:
locale
,
symbols:
symbols
,
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