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
diff --git a/dev/tools/localization/gen_l10n.dart b/dev/tools/localization/gen_l10n.dart index 95d53ae..e8e4634 100644 --- a/dev/tools/localization/gen_l10n.dart +++ b/dev/tools/localization/gen_l10n.dart
@@ -79,7 +79,7 @@ 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 @@ } if (attributesMap.containsKey('placeholders')) { final Map<String, dynamic> placeholders = attributesMap['placeholders']; - final String args = placeholders.keys.join(', '); - attributes.add('args: <Object>[$args]'); + if (placeholders.isNotEmpty) { + final String args = placeholders.keys.join(', '); + attributes.add('args: <Object>[$args]'); + } } } return attributes;
diff --git a/examples/stocks/lib/i18n/regenerate.md b/examples/stocks/lib/i18n/regenerate.md index 86967eb..331a433 100644 --- a/examples/stocks/lib/i18n/regenerate.md +++ b/examples/stocks/lib/i18n/regenerate.md
@@ -16,8 +16,8 @@ ```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 d8a3c81..dee4073 100644 --- a/examples/stocks/lib/i18n/stock_strings.dart +++ b/examples/stocks/lib/i18n/stock_strings.dart
@@ -93,33 +93,30 @@ 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: <Object>[] + 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: <Object>[] + 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: <Object>[] + 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 f28c71d..2d4b4f2 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 89cff4e..3d41a88 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 545c7e5..63a59c2 100644 --- a/examples/stocks/lib/stock_home.dart +++ b/examples/stocks/lib/stock_home.dart
@@ -191,7 +191,7 @@ Widget buildAppBar() { return AppBar( elevation: 0.0, - title: Text(StockStrings.of(context).title()), + title: Text(StockStrings.of(context).title), actions: <Widget>[ IconButton( icon: const Icon(Icons.search), @@ -223,8 +223,8 @@ ], bottom: TabBar( tabs: <Widget>[ - Tab(text: StockStrings.of(context).market()), - Tab(text: StockStrings.of(context).portfolio()), + Tab(text: StockStrings.of(context).market), + Tab(text: StockStrings.of(context).portfolio), ], ), );