From f4288f6bbf3893bec3e84b0c8f93697e0d48ed42 Mon Sep 17 00:00:00 2001 From: minikin Date: Wed, 22 Nov 2023 14:38:11 +0100 Subject: [PATCH] feat: update localization pub --- .config/dictionaries/project.dic | 1 + catalyst_voices/lib/dummy/home_screen.dart | 2 +- catalyst_voices/lib/dummy/login_page.dart | 9 +- .../catalyst_voices_localization/README.md | 129 +++++++++--------- .../build_context_localization_extension.dart | 2 +- 5 files changed, 73 insertions(+), 70 deletions(-) diff --git a/.config/dictionaries/project.dic b/.config/dictionaries/project.dic index e9ea387626f..e946395ed50 100644 --- a/.config/dictionaries/project.dic +++ b/.config/dictionaries/project.dic @@ -8,6 +8,7 @@ auditability bluefireteam BROTLI cardano +Catalyst CEST cfbundle chromedriver diff --git a/catalyst_voices/lib/dummy/home_screen.dart b/catalyst_voices/lib/dummy/home_screen.dart index 78bd68240a9..84e1415ffa5 100644 --- a/catalyst_voices/lib/dummy/home_screen.dart +++ b/catalyst_voices/lib/dummy/home_screen.dart @@ -15,7 +15,7 @@ final class HomeScreen extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, children: [ Text( - context.l.homeScreenText, + context.l10n.homeScreenText, style: const TextStyle( color: VoicesColors.purpleGradientStart, fontFamily: VoicesFonts.sFPro, diff --git a/catalyst_voices/lib/dummy/login_page.dart b/catalyst_voices/lib/dummy/login_page.dart index 207ed746937..e80241e7e64 100644 --- a/catalyst_voices/lib/dummy/login_page.dart +++ b/catalyst_voices/lib/dummy/login_page.dart @@ -20,6 +20,7 @@ final class _LoginPageState extends State { @override Widget build(BuildContext context) { + final l10n = context.l10n; return Scaffold( key: WidgetKeys.loginScreen, body: Center( @@ -38,7 +39,7 @@ final class _LoginPageState extends State { controller: usernameTextController, decoration: InputDecoration( border: const OutlineInputBorder(), - labelText: context.l.loginScreenUsernameLabelText, + labelText: l10n.loginScreenUsernameLabelText, ), ), ), @@ -50,7 +51,7 @@ final class _LoginPageState extends State { obscureText: true, decoration: InputDecoration( border: const OutlineInputBorder(), - labelText: context.l.loginScreenPasswordLabelText, + labelText: l10n.loginScreenPasswordLabelText, ), ), ), @@ -59,7 +60,7 @@ final class _LoginPageState extends State { child: ElevatedButton( key: WidgetKeys.loginButton, onPressed: () async => _loginButtonPressed(context), - child: Text(context.l.loginScreenLoginButtonText), + child: Text(l10n.loginScreenLoginButtonText), ), ), ], @@ -105,7 +106,7 @@ final class _LoginPageState extends State { ScaffoldMessenger.of(context).showSnackBar( SnackBar( key: WidgetKeys.loginErrorSnackbar, - content: Text(context.l.loginScreenErrorMessage), + content: Text(context.l10n.loginScreenErrorMessage), ), ); } diff --git a/catalyst_voices/packages/catalyst_voices_localization/README.md b/catalyst_voices/packages/catalyst_voices_localization/README.md index 8e73864e5c6..3435ecb25fb 100644 --- a/catalyst_voices/packages/catalyst_voices_localization/README.md +++ b/catalyst_voices/packages/catalyst_voices_localization/README.md @@ -5,10 +5,10 @@ This package contains the localization files for the Catalyst Voices app. * [Catalyst Voices Localization](#catalyst-voices-localization) * [Working with Translations](#working-with-translations) * [Creating New Locale Messages](#creating-new-locale-messages) - * [Generating VoicesLocalizations](#generating-voiceslocalizations) * [Adding Strings](#adding-strings) - * [Adding Supported Locales](#adding-supported-locales) * [Adding Translations](#adding-translations) + * [Adding Supported Locales](#adding-supported-locales) + * [Generating VoicesLocalizations](#generating-voiceslocalizations) ## Working with Translations @@ -36,105 +36,106 @@ Once you've updated `intl_en.arb` with the new message, regenerate the `VoicesLo immediate use of the English message in your application code through the localizations delegate, bypassing the need to wait for translation completion. -## Generating VoicesLocalizations - ### Adding Strings -1. To add a new localizable string, open the `app_en.arb` file at `lib/l10n/arb/app_en.arb`. +* To add a new localizable string, open the `intl_en.arb` file at `lib/l10n/`. ```arb { - "@@locale": "en", - "counterAppBarTitle": "Counter", - "@counterAppBarTitle": { - "description": "Text shown in the AppBar of the Counter Page" - } + "@@locale": "en", + "loginScreenUsernameLabelText": "Username", + "@loginScreenUsernameLabelText": { + "description": "Text shown in the login screen for the username field" + } } ``` -2. Then add a new key/value and description +* Then add a new key/value and description ```arb { - "@@locale": "en", - "counterAppBarTitle": "Counter", - "@counterAppBarTitle": { - "description": "Text shown in the AppBar of the Counter Page" - }, - "helloWorld": "Hello World", - "@helloWorld": { - "description": "Hello World Text" - } + "@@locale": "en", + "loginScreenUsernameLabelText": "Username", + "@loginScreenUsernameLabelText": { + "description": "Text shown in the login screen for the username field" + }, + "loginScreenPasswordLabelText": "Password", + "@loginScreenPasswordLabelText": { + "description": "Text shown in the login screen for the password field" + } } ``` -3. Use the new string +### Adding Translations -```dart -import 'package:catalyst_voices/l10n/l10n.dart'; +* For each supported locale, add a new ARB file in `lib/l10n/`. -@override -Widget build(BuildContext context) { - final l10n = context.l10n; - return Text(l10n.helloWorld); +```tree +├── l10n +│ ├── intl_en.arb +│ ├── intl_es.arb +``` + +* Add the translated strings to each `.arb` file: + +`intl_en.arb` + +```arb +{ + "@@locale": "en", + "loginScreenUsernameLabelText": "Username", + "@loginScreenUsernameLabelText": { + "description": "Text shown in the login screen for the username field" + }, + "loginScreenPasswordLabelText": "Password", + "@loginScreenPasswordLabelText": { + "description": "Text shown in the login screen for the password field" + } +} +``` + +`app_es.arb` + + +```arb +{ + "@@locale": "es", + "loginScreenUsernameLabelText": "Nombre de usuario", + "loginScreenPasswordLabelText": "Contraseña", } ``` ### Adding Supported Locales -Update the `CFBundleLocalizations` array in the `Info.plist` at `ios/Runner/Info.plist` to include the new locale. +Update the `CFBundleLocalizations` array in the `Info.plist` at +`ios/Runner/Info.plist` to include the new locale. ```xml ... - CFBundleLocalizations en es - ... ``` -### Adding Translations - -1. For each supported locale, add a new ARB file in `lib/l10n/arb`. - -```tree -├── l10n -│ ├── arb -│ │ ├── app_en.arb -│ │ └── app_es.arb -``` - -2. Add the translated strings to each `.arb` file: +## Generating VoicesLocalizations -`app_en.arb` +* Run the following command in `catalyst_voices_localization` package to +generate the `VoicesLocalizations` class: -```arb -{ - "@@locale": "en", - "counterAppBarTitle": "Counter", - "@counterAppBarTitle": { - "description": "Text shown in the AppBar of the Counter Page" - } -} +```sh +flutter gen-l10n ``` - +* Use the new string -`app_es.arb` +```dart +import 'package:catalyst_voices_localization/catalyst_voices_localization.dart'; -```arb -{ - "@@locale": "es", - "counterAppBarTitle": "Contador", - "@counterAppBarTitle": { - "description": "Texto mostrado en la AppBar de la página del contador" - } +@override +Widget build(BuildContext context) { + return Text(context.l10n.loginScreenPasswordLabelText); } ``` - -```shell -flutter gen-l10n -``` diff --git a/catalyst_voices/packages/catalyst_voices_localization/lib/src/build_context_localization_extension.dart b/catalyst_voices/packages/catalyst_voices_localization/lib/src/build_context_localization_extension.dart index b2a60ec800e..3daeda8576c 100644 --- a/catalyst_voices/packages/catalyst_voices_localization/lib/src/build_context_localization_extension.dart +++ b/catalyst_voices/packages/catalyst_voices_localization/lib/src/build_context_localization_extension.dart @@ -2,5 +2,5 @@ import 'package:catalyst_voices_localization/generated/catalyst_voices_localizat import 'package:flutter/widgets.dart'; extension BuildContextLocalizationExtension on BuildContext { - VoicesLocalizations get l => VoicesLocalizations.of(this)!; + VoicesLocalizations get l10n => VoicesLocalizations.of(this)!; }