Unverified Commit 159a47da authored by Shi-Hao Hong's avatar Shi-Hao Hong Committed by GitHub

l10n tool improvements, stocks app i18n refresh (#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
parent 9307a83f
...@@ -79,7 +79,7 @@ class @className { ...@@ -79,7 +79,7 @@ class @className {
static Future<@className> load(Locale locale) { static Future<@className> load(Locale locale) {
return initializeMessages(locale.toString()) return initializeMessages(locale.toString())
.then<@className>((void _) => @className(locale)); .then<@className>((_) => @className(locale));
} }
static @className of(BuildContext context) { static @className of(BuildContext context) {
...@@ -168,8 +168,10 @@ List<String> genIntlMethodArgs(Map<String, dynamic> bundle, String key) { ...@@ -168,8 +168,10 @@ List<String> genIntlMethodArgs(Map<String, dynamic> bundle, String key) {
} }
if (attributesMap.containsKey('placeholders')) { if (attributesMap.containsKey('placeholders')) {
final Map<String, dynamic> placeholders = attributesMap['placeholders']; final Map<String, dynamic> placeholders = attributesMap['placeholders'];
final String args = placeholders.keys.join(', '); if (placeholders.isNotEmpty) {
attributes.add('args: <Object>[$args]'); final String args = placeholders.keys.join(', ');
attributes.add('args: <Object>[$args]');
}
} }
} }
return attributes; return attributes;
......
...@@ -16,8 +16,8 @@ for more info. ...@@ -16,8 +16,8 @@ for more info.
```dart ```dart
dart ${FLUTTER_PATH}/dev/tools/localization/gen_l10n.dart --arb-dir=lib/i18n \ dart ${FLUTTER_PATH}/dev/tools/localization/gen_l10n.dart --arb-dir=lib/i18n \
--template-arb-file=stocks_en_US.arb --output-localization-file=stock_strings.dart \ --template-arb-file=stocks_en_US.arb --output-localization-file=stock_strings.dart \
--output-class=StockStrings --output-class=StockStrings
``` ```
The `StockStrings` class uses the generated `initializeMessages()`function The `StockStrings` class uses the generated `initializeMessages()`function
......
...@@ -93,33 +93,30 @@ class StockStrings { ...@@ -93,33 +93,30 @@ class StockStrings {
Locale('en', 'US'), Locale('en', 'US'),
]; ];
String title() { String get title {
return Intl.message( return Intl.message(
r'Stocks', r'Stocks',
locale: _localeName, locale: _localeName,
name: 'title', name: 'title',
desc: r'Title for the Stocks application', desc: r'Title for the Stocks application'
args: <Object>[]
); );
} }
String market() { String get market {
return Intl.message( return Intl.message(
r'MARKET', r'MARKET',
locale: _localeName, locale: _localeName,
name: 'market', name: 'market',
desc: r'Label for the Market tab', desc: r'Label for the Market tab'
args: <Object>[]
); );
} }
String portfolio() { String get portfolio {
return Intl.message( return Intl.message(
r'PORTFOLIO', r'PORTFOLIO',
locale: _localeName, locale: _localeName,
name: 'portfolio', name: 'portfolio',
desc: r'Label for the Portfolio tab', desc: r'Label for the Portfolio tab'
args: <Object>[]
); );
} }
......
{ {
"title": "Stocks", "title": "Stocks",
"@title": { "@title": {
"description": "Title for the Stocks application", "description": "Title for the Stocks application"
"type": "text",
"placeholders": {}
}, },
"market": "MARKET", "market": "MARKET",
"@market": { "@market": {
"description": "Label for the Market tab", "description": "Label for the Market tab"
"type": "text",
"placeholders": {}
}, },
"portfolio": "PORTFOLIO", "portfolio": "PORTFOLIO",
"@portfolio": { "@portfolio": {
"description": "Label for the Portfolio tab", "description": "Label for the Portfolio tab"
"type": "text",
"placeholders": {}
} }
} }
{ {
"title": "Acciones", "title": "Acciones",
"@title": {
"description": "Title for the Stocks application",
"type": "text",
"placeholders": {}
},
"market": "MERCADO", "market": "MERCADO",
"@market": { "portfolio": "CARTERA"
"description": "Label for the Market tab",
"type": "text",
"placeholders": {}
},
"portfolio": "CARTERA",
"@portfolio": {
"description": "Label for the Portfolio tab",
"type": "text",
"placeholders": {}
}
} }
...@@ -191,7 +191,7 @@ class StockHomeState extends State<StockHome> { ...@@ -191,7 +191,7 @@ class StockHomeState extends State<StockHome> {
Widget buildAppBar() { Widget buildAppBar() {
return AppBar( return AppBar(
elevation: 0.0, elevation: 0.0,
title: Text(StockStrings.of(context).title()), title: Text(StockStrings.of(context).title),
actions: <Widget>[ actions: <Widget>[
IconButton( IconButton(
icon: const Icon(Icons.search), icon: const Icon(Icons.search),
...@@ -223,8 +223,8 @@ class StockHomeState extends State<StockHome> { ...@@ -223,8 +223,8 @@ class StockHomeState extends State<StockHome> {
], ],
bottom: TabBar( bottom: TabBar(
tabs: <Widget>[ tabs: <Widget>[
Tab(text: StockStrings.of(context).market()), Tab(text: StockStrings.of(context).market),
Tab(text: StockStrings.of(context).portfolio()), Tab(text: StockStrings.of(context).portfolio),
], ],
), ),
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment