Skip to content

Commit 159a47d

Browse files
author
Shi-Hao Hong
authored
l10n tool improvements, stocks app i18n refresh (flutter#44473)
* Add check for placeholders being an empty map * Remove unnecessary properties from en_ES.arb in the stocks example * Use getter instead of methods in the stocks example * Fixed "annotating types for function expression parameters" lint issue from generated localizations delegate code
1 parent 9307a83 commit 159a47d

File tree

6 files changed

+20
-44
lines changed

6 files changed

+20
-44
lines changed

dev/tools/localization/gen_l10n.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class @className {
7979
8080
static Future<@className> load(Locale locale) {
8181
return initializeMessages(locale.toString())
82-
.then<@className>((void _) => @className(locale));
82+
.then<@className>((_) => @className(locale));
8383
}
8484
8585
static @className of(BuildContext context) {
@@ -168,8 +168,10 @@ List<String> genIntlMethodArgs(Map<String, dynamic> bundle, String key) {
168168
}
169169
if (attributesMap.containsKey('placeholders')) {
170170
final Map<String, dynamic> placeholders = attributesMap['placeholders'];
171-
final String args = placeholders.keys.join(', ');
172-
attributes.add('args: <Object>[$args]');
171+
if (placeholders.isNotEmpty) {
172+
final String args = placeholders.keys.join(', ');
173+
attributes.add('args: <Object>[$args]');
174+
}
173175
}
174176
}
175177
return attributes;

examples/stocks/lib/i18n/regenerate.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ for more info.
1616

1717
```dart
1818
dart ${FLUTTER_PATH}/dev/tools/localization/gen_l10n.dart --arb-dir=lib/i18n \
19-
--template-arb-file=stocks_en_US.arb --output-localization-file=stock_strings.dart \
20-
--output-class=StockStrings
19+
--template-arb-file=stocks_en_US.arb --output-localization-file=stock_strings.dart \
20+
--output-class=StockStrings
2121
```
2222

2323
The `StockStrings` class uses the generated `initializeMessages()`function

examples/stocks/lib/i18n/stock_strings.dart

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,33 +93,30 @@ class StockStrings {
9393
Locale('en', 'US'),
9494
];
9595

96-
String title() {
96+
String get title {
9797
return Intl.message(
9898
r'Stocks',
9999
locale: _localeName,
100100
name: 'title',
101-
desc: r'Title for the Stocks application',
102-
args: <Object>[]
101+
desc: r'Title for the Stocks application'
103102
);
104103
}
105104

106-
String market() {
105+
String get market {
107106
return Intl.message(
108107
r'MARKET',
109108
locale: _localeName,
110109
name: 'market',
111-
desc: r'Label for the Market tab',
112-
args: <Object>[]
110+
desc: r'Label for the Market tab'
113111
);
114112
}
115113

116-
String portfolio() {
114+
String get portfolio {
117115
return Intl.message(
118116
r'PORTFOLIO',
119117
locale: _localeName,
120118
name: 'portfolio',
121-
desc: r'Label for the Portfolio tab',
122-
args: <Object>[]
119+
desc: r'Label for the Portfolio tab'
123120
);
124121
}
125122

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
{
22
"title": "Stocks",
33
"@title": {
4-
"description": "Title for the Stocks application",
5-
"type": "text",
6-
"placeholders": {}
4+
"description": "Title for the Stocks application"
75
},
86

97
"market": "MARKET",
108
"@market": {
11-
"description": "Label for the Market tab",
12-
"type": "text",
13-
"placeholders": {}
9+
"description": "Label for the Market tab"
1410
},
1511

1612
"portfolio": "PORTFOLIO",
1713
"@portfolio": {
18-
"description": "Label for the Portfolio tab",
19-
"type": "text",
20-
"placeholders": {}
14+
"description": "Label for the Portfolio tab"
2115
}
2216
}
Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
{
22
"title": "Acciones",
3-
"@title": {
4-
"description": "Title for the Stocks application",
5-
"type": "text",
6-
"placeholders": {}
7-
},
8-
93
"market": "MERCADO",
10-
"@market": {
11-
"description": "Label for the Market tab",
12-
"type": "text",
13-
"placeholders": {}
14-
},
15-
16-
"portfolio": "CARTERA",
17-
"@portfolio": {
18-
"description": "Label for the Portfolio tab",
19-
"type": "text",
20-
"placeholders": {}
21-
}
4+
"portfolio": "CARTERA"
225
}

examples/stocks/lib/stock_home.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class StockHomeState extends State<StockHome> {
191191
Widget buildAppBar() {
192192
return AppBar(
193193
elevation: 0.0,
194-
title: Text(StockStrings.of(context).title()),
194+
title: Text(StockStrings.of(context).title),
195195
actions: <Widget>[
196196
IconButton(
197197
icon: const Icon(Icons.search),
@@ -223,8 +223,8 @@ class StockHomeState extends State<StockHome> {
223223
],
224224
bottom: TabBar(
225225
tabs: <Widget>[
226-
Tab(text: StockStrings.of(context).market()),
227-
Tab(text: StockStrings.of(context).portfolio()),
226+
Tab(text: StockStrings.of(context).market),
227+
Tab(text: StockStrings.of(context).portfolio),
228228
],
229229
),
230230
);

0 commit comments

Comments
 (0)