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
c3e0f2d4
Unverified
Commit
c3e0f2d4
authored
Feb 05, 2020
by
Hans Muller
Committed by
GitHub
Feb 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Message.isPlural, Message.getCountPlaceholder() to gen_l10n_types (#50132)
parent
94c7e823
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
6 deletions
+30
-6
gen_l10n.dart
dev/tools/localization/gen_l10n.dart
+12
-5
gen_l10n_types.dart
dev/tools/localization/gen_l10n_types.dart
+18
-1
No files found.
dev/tools/localization/gen_l10n.dart
View file @
c3e0f2d4
...
...
@@ -286,9 +286,17 @@ String generatePluralMethod(Message message) {
'other'
:
'other'
};
final
String
countPlaceholder
=
message
.
value
.
split
(
','
)[
0
].
substring
(
1
);
final
Placeholder
countPlaceholder
=
message
.
getCountPlaceholder
();
if
(
countPlaceholder
==
null
)
{
throw
L10nException
(
'Unable to find the count placeholder for the plural message:
${message.resourceId}
.
\n
'
'Check to see if the plural message is in the proper ICU syntax format '
'and ensure that placeholders are properly specified.'
);
}
final
List
<
String
>
intlMethodArgs
=
<
String
>[
countPlaceholder
,
countPlaceholder
.
name
,
'locale: _localeName'
,
...
generateIntlMethodArgs
(
message
),
];
...
...
@@ -311,7 +319,7 @@ String generatePluralMethod(Message message) {
List
<
String
>
generatePluralMethodParameters
([
String
type
])
{
return
message
.
placeholders
.
map
((
Placeholder
placeholder
)
{
final
String
placeholderType
=
placeholder
.
name
==
countPlaceholder
?
'int'
:
(
type
??
placeholder
.
type
);
final
String
placeholderType
=
placeholder
==
countPlaceholder
?
'int'
:
(
type
??
placeholder
.
type
);
return
'
$placeholderType
${placeholder.name}
'
;
}).
toList
();
}
...
...
@@ -346,7 +354,6 @@ class LocalizationsGenerator {
static
RegExp
arbFilenameLocaleRE
=
RegExp
(
r'^[^_]*_(\w+)\.arb$'
);
static
RegExp
arbFilenameRE
=
RegExp
(
r'(\w+)\.arb$'
);
static
RegExp
pluralValueRE
=
RegExp
(
r'^\s*\{[\w\s,]*,\s*plural\s*,'
);
final
file
.
FileSystem
_fs
;
...
...
@@ -673,7 +680,7 @@ class LocalizationsGenerator {
}
final
Message
message
=
Message
(
bundle
,
key
);
if
(
pluralValueRE
.
hasMatch
(
message
.
value
)
)
if
(
message
.
isPlural
)
classMethods
.
add
(
generatePluralMethod
(
message
));
else
classMethods
.
add
(
genSimpleMethod
(
message
));
...
...
dev/tools/localization/gen_l10n_types.dart
View file @
c3e0f2d4
...
...
@@ -81,15 +81,32 @@ class Message {
assert
(
resourceId
!=
null
&&
resourceId
.
isNotEmpty
),
value
=
_value
(
bundle
,
resourceId
),
description
=
_description
(
bundle
,
resourceId
),
placeholders
=
_placeholders
(
bundle
,
resourceId
);
placeholders
=
_placeholders
(
bundle
,
resourceId
),
_pluralMatch
=
_pluralRE
.
firstMatch
(
_value
(
bundle
,
resourceId
));
static
final
RegExp
_pluralRE
=
RegExp
(
r'\s*\{([\w\s,]*),\s*plural\s*,'
);
final
String
resourceId
;
final
String
value
;
final
String
description
;
final
List
<
Placeholder
>
placeholders
;
final
RegExpMatch
_pluralMatch
;
bool
get
isPlural
=>
_pluralMatch
!=
null
&&
_pluralMatch
.
groupCount
==
1
;
bool
get
placeholdersRequireFormatting
=>
placeholders
.
any
((
Placeholder
p
)
=>
p
.
requiresFormatting
);
Placeholder
getCountPlaceholder
()
{
assert
(
isPlural
);
final
String
countPlaceholderName
=
_pluralMatch
[
1
];
return
placeholders
.
firstWhere
(
(
Placeholder
p
)
=>
p
.
name
==
countPlaceholderName
,
orElse:
()
{
throw
L10nException
(
'Cannot find the
$countPlaceholderName
placeholder in plural message "
$resourceId
".'
);
}
);
}
static
String
_value
(
Map
<
String
,
dynamic
>
bundle
,
String
resourceId
)
{
final
dynamic
value
=
bundle
[
resourceId
];
if
(
value
==
null
)
...
...
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