Skip to content

Commit

Permalink
feat(fronted): add catalyst_voices_localization pub
Browse files Browse the repository at this point in the history
  • Loading branch information
minikin committed Nov 20, 2023
1 parent e82e3c8 commit d955e94
Show file tree
Hide file tree
Showing 18 changed files with 374 additions and 130 deletions.
110 changes: 1 addition & 109 deletions catalyst_voices/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
* [Getting Started](#getting-started)
* [Bootstrapping](#bootstrapping)
* [Running Tests](#running-tests)
* [Working with Translations](#working-with-translations)
* [Adding Strings](#adding-strings)
* [Adding Supported Locales](#adding-supported-locales)
* [Adding Translations](#adding-translations)

## Requirements

Expand Down Expand Up @@ -79,108 +75,4 @@ genhtml coverage/lcov.info -o coverage/

# Open Coverage Report
open coverage/index.html
```

## Working with Translations

This project relies on [flutter_localizations](https://github.com/flutter/flutter/tree/master/packages/flutter_localizations).
It follows the [official internationalization guide for Flutter][flutter-intl-guide].

### Adding Strings

1. To add a new localizable string, open the `app_en.arb` file at `lib/l10n/arb/app_en.arb`.

```arb
{
"@@locale": "en",
"counterAppBarTitle": "Counter",
"@counterAppBarTitle": {
"description": "Text shown in the AppBar of the Counter Page"
}
}
```

2. 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"
}
}
```

3. Use the new string

```dart
import 'package:catalyst_voices/l10n/l10n.dart';
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
return Text(l10n.helloWorld);
}
```

### Adding Supported Locales

Update the `CFBundleLocalizations` array in the `Info.plist` at `ios/Runner/Info.plist` to include the new locale.

```xml
...

<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>es</string>
</array>

...
```

### 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:

`app_en.arb`

```arb
{
"@@locale": "en",
"counterAppBarTitle": "Counter",
"@counterAppBarTitle": {
"description": "Text shown in the AppBar of the Counter Page"
}
}
```

<!-- cspell: words Contador Texto mostrado página -->

`app_es.arb`

```arb
{
"@@locale": "es",
"counterAppBarTitle": "Contador",
"@counterAppBarTitle": {
"description": "Texto mostrado en la AppBar de la página del contador"
}
}
```

[flutter-intl-guide]: https://docs.flutter.dev/development/accessibility-and-localization/internationalization
```
4 changes: 0 additions & 4 deletions catalyst_voices/l10n.yaml

This file was deleted.

12 changes: 9 additions & 3 deletions catalyst_voices/lib/app/view/app.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import 'package:catalyst_voices/dummy/dummy.dart';
import 'package:catalyst_voices/l10n/l10n.dart';
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localized_locales/flutter_localized_locales.dart';

final class App extends StatelessWidget {
const App({super.key});

@override
Widget build(BuildContext context) {
return const MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
restorationScopeId: 'rootVoices',
localizationsDelegates: [
...VoicesLocalizations.localizationsDelegates,
LocaleNamesLocalizationsDelegate(),
],
supportedLocales: VoicesLocalizations.supportedLocales,
localeListResolutionCallback: basicLocaleListResolution,
home: LoginPage(),
);
}
Expand Down
8 changes: 0 additions & 8 deletions catalyst_voices/lib/l10n/l10n.dart

This file was deleted.

44 changes: 44 additions & 0 deletions catalyst_voices/packages/catalyst_voices_localization/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# VSCode related
.vscode/*

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/
pubspec.lock

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Test related
coverage
118 changes: 118 additions & 0 deletions catalyst_voices/packages/catalyst_voices_localization/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Catalyst Voices Localization

This package contains the localization files for the Catalyst Voices app.

* [Catalyst Voices Localization](#catalyst-voices-localization)
* [Working with Translations](#working-with-translations)
* [Adding Strings](#adding-strings)
* [Adding Supported Locales](#adding-supported-locales)
* [Adding Translations](#adding-translations)

## Working with Translations

This project relies on [flutter_localizations](https://github.com/flutter/flutter/tree/master/packages/flutter_localizations).
It follows the [official internationalization guide for Flutter][flutter-intl-guide].

### Adding Strings

1. To add a new localizable string, open the `app_en.arb` file at `lib/l10n/arb/app_en.arb`.

```arb
{
"@@locale": "en",
"counterAppBarTitle": "Counter",
"@counterAppBarTitle": {
"description": "Text shown in the AppBar of the Counter Page"
}
}
```

2. 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"
}
}
```

3. Use the new string

```dart
import 'package:catalyst_voices/l10n/l10n.dart';
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
return Text(l10n.helloWorld);
}
```

### Adding Supported Locales

Update the `CFBundleLocalizations` array in the `Info.plist` at `ios/Runner/Info.plist` to include the new locale.

```xml
...

<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>es</string>
</array>

...
```

### 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:

`app_en.arb`

```arb
{
"@@locale": "en",
"counterAppBarTitle": "Counter",
"@counterAppBarTitle": {
"description": "Text shown in the AppBar of the Counter Page"
}
}
```

<!-- cspell: words Contador Texto mostrado página -->

`app_es.arb`

```arb
{
"@@locale": "es",
"counterAppBarTitle": "Contador",
"@counterAppBarTitle": {
"description": "Texto mostrado en la AppBar de la página del contador"
}
}
```

```shell
flutter gen-l10n
```


[flutter-intl-guide]: https://docs.flutter.dev/development/accessibility-and-localization/internationalization
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
arb-dir: lib/l10n
output-dir: lib/generated/
template-arb-file: intl_en.arb
output-localization-file: catalyst_voices_localizations.dart
output-class: VoicesLocalizations
preferred-supported-locales:
- en
use-deferred-loading: true
synthetic-package: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// A Very Good Project created by Very Good CLI.
library catalyst_voices_localization;

export 'src/catalyst_voices_localization.dart';
Loading

0 comments on commit d955e94

Please sign in to comment.