From 159a47da648a37f0fcd9e5e5c0f6121b2e075baa Mon Sep 17 00:00:00 2001 From: Shi-Hao Hong Date: Mon, 11 Nov 2019 14:42:29 -0800 Subject: [PATCH] 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 --- dev/tools/localization/gen_l10n.dart | 8 +++++--- examples/stocks/lib/i18n/regenerate.md | 4 ++-- examples/stocks/lib/i18n/stock_strings.dart | 15 ++++++--------- examples/stocks/lib/i18n/stocks_en_US.arb | 12 +++--------- examples/stocks/lib/i18n/stocks_es_ES.arb | 19 +------------------ examples/stocks/lib/stock_home.dart | 6 +++--- 6 files changed, 20 insertions(+), 44 deletions(-) diff --git a/dev/tools/localization/gen_l10n.dart b/dev/tools/localization/gen_l10n.dart index 95d53ae5ec..e8e4634790 100644 --- a/dev/tools/localization/gen_l10n.dart +++ b/dev/tools/localization/gen_l10n.dart @@ -79,7 +79,7 @@ class @className { static Future<@className> load(Locale locale) { return initializeMessages(locale.toString()) - .then<@className>((void _) => @className(locale)); + .then<@className>((_) => @className(locale)); } static @className of(BuildContext context) { @@ -168,8 +168,10 @@ List genIntlMethodArgs(Map bundle, String key) { } if (attributesMap.containsKey('placeholders')) { final Map placeholders = attributesMap['placeholders']; - final String args = placeholders.keys.join(', '); - attributes.add('args: [$args]'); + if (placeholders.isNotEmpty) { + final String args = placeholders.keys.join(', '); + attributes.add('args: [$args]'); + } } } return attributes; diff --git a/examples/stocks/lib/i18n/regenerate.md b/examples/stocks/lib/i18n/regenerate.md index 86967eb24a..331a433505 100644 --- a/examples/stocks/lib/i18n/regenerate.md +++ b/examples/stocks/lib/i18n/regenerate.md @@ -16,8 +16,8 @@ for more info. ```dart 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 \ - --output-class=StockStrings + --template-arb-file=stocks_en_US.arb --output-localization-file=stock_strings.dart \ + --output-class=StockStrings ``` The `StockStrings` class uses the generated `initializeMessages()`function diff --git a/examples/stocks/lib/i18n/stock_strings.dart b/examples/stocks/lib/i18n/stock_strings.dart index d8a3c81614..dee4073c94 100644 --- a/examples/stocks/lib/i18n/stock_strings.dart +++ b/examples/stocks/lib/i18n/stock_strings.dart @@ -93,33 +93,30 @@ class StockStrings { Locale('en', 'US'), ]; - String title() { + String get title { return Intl.message( r'Stocks', locale: _localeName, name: 'title', - desc: r'Title for the Stocks application', - args: [] + desc: r'Title for the Stocks application' ); } - String market() { + String get market { return Intl.message( r'MARKET', locale: _localeName, name: 'market', - desc: r'Label for the Market tab', - args: [] + desc: r'Label for the Market tab' ); } - String portfolio() { + String get portfolio { return Intl.message( r'PORTFOLIO', locale: _localeName, name: 'portfolio', - desc: r'Label for the Portfolio tab', - args: [] + desc: r'Label for the Portfolio tab' ); } diff --git a/examples/stocks/lib/i18n/stocks_en_US.arb b/examples/stocks/lib/i18n/stocks_en_US.arb index f28c71de16..2d4b4f2505 100644 --- a/examples/stocks/lib/i18n/stocks_en_US.arb +++ b/examples/stocks/lib/i18n/stocks_en_US.arb @@ -1,22 +1,16 @@ { "title": "Stocks", "@title": { - "description": "Title for the Stocks application", - "type": "text", - "placeholders": {} + "description": "Title for the Stocks application" }, "market": "MARKET", "@market": { - "description": "Label for the Market tab", - "type": "text", - "placeholders": {} + "description": "Label for the Market tab" }, "portfolio": "PORTFOLIO", "@portfolio": { - "description": "Label for the Portfolio tab", - "type": "text", - "placeholders": {} + "description": "Label for the Portfolio tab" } } diff --git a/examples/stocks/lib/i18n/stocks_es_ES.arb b/examples/stocks/lib/i18n/stocks_es_ES.arb index 89cff4e9bc..3d41a884be 100644 --- a/examples/stocks/lib/i18n/stocks_es_ES.arb +++ b/examples/stocks/lib/i18n/stocks_es_ES.arb @@ -1,22 +1,5 @@ { "title": "Acciones", - "@title": { - "description": "Title for the Stocks application", - "type": "text", - "placeholders": {} - }, - "market": "MERCADO", - "@market": { - "description": "Label for the Market tab", - "type": "text", - "placeholders": {} - }, - - "portfolio": "CARTERA", - "@portfolio": { - "description": "Label for the Portfolio tab", - "type": "text", - "placeholders": {} - } + "portfolio": "CARTERA" } diff --git a/examples/stocks/lib/stock_home.dart b/examples/stocks/lib/stock_home.dart index 545c7e51c4..63a59c2716 100644 --- a/examples/stocks/lib/stock_home.dart +++ b/examples/stocks/lib/stock_home.dart @@ -191,7 +191,7 @@ class StockHomeState extends State { Widget buildAppBar() { return AppBar( elevation: 0.0, - title: Text(StockStrings.of(context).title()), + title: Text(StockStrings.of(context).title), actions: [ IconButton( icon: const Icon(Icons.search), @@ -223,8 +223,8 @@ class StockHomeState extends State { ], bottom: TabBar( tabs: [ - Tab(text: StockStrings.of(context).market()), - Tab(text: StockStrings.of(context).portfolio()), + Tab(text: StockStrings.of(context).market), + Tab(text: StockStrings.of(context).portfolio), ], ), );