Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add arb_translate package to auto-translate the app strings #1801

Merged
merged 6 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions lib/sharezone_localizations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

**Sharezone Localizations** generates easily accessible translatable strings for the Sharezone-App. This package leverages Flutter's [Internationalization (i18n)](https://docs.flutter.dev/development/accessibility-and-localization/internationalization) features, providing an easy interface for adding, generating, and accessing localized strings in your application.

Additionally:

- AppLocaleProviderBloc: Allows you to manage and switch the current locale at runtime.
- AppLocaleBuilder: Enables direct access to the current AppLocales enum value in your UI, making it straightforward to conditionally render widgets or styles based on the current locale.

## Table of Contents

- [sharezone\_localizations](#sharezone_localizations)
Expand All @@ -18,6 +13,7 @@ Additionally:
- [Generating Localizations](#generating-localizations)
- [Flutter Gen-L10n Command](#flutter-gen-l10n-command)
- [Using VS Code Task](#using-vs-code-task)
- [Translating with arb\_translate](#translating-with-arb_translate)

---

Expand All @@ -28,6 +24,7 @@ Additionally:
- Automatic Code Generation: Easily generate localization delegates and associated code using the flutter gen-l10n tool (or a dedicated VS Code Task).
- Locale Management:
- `AppLocaleProvider` helps you access and manage the current locale in real time, allowing dynamic locale switching.
- Auto-translate with [arb_translate](https://pub.dev/packages/arb_translate): Use the arb_translate package to auto-translate your .arb files.

---

Expand Down Expand Up @@ -120,3 +117,22 @@ If you have a VS Code task called "Generate l10n for sharezone_localizations", y
3. Choose "Generate l10n for sharezone_localizations".

This task runs `flutter gen-l10n` with your chosen configuration.

### Translating with arb_translate

With the [arb_translate](https://pub.dev/packages/arb_translate) package, you can auto-translate your .arb files using
Large Language Models (LLMs). We're going to use [Gemini](https://deepmind.google/technologies/gemini/). An LLM has the advantage that we can provide the model with context (what our application does, what the string is for, etc.), which can lead to better translations.

1. Install the arb_translate package:

```bash
dart pub global activate arb_translate
```

2. Generate your API key. You can create your Gemini key [here](https://makersuite.google.com/app/apikey).
3. Save your API token in the environment variable `ARB_TRANSLATE_API_KEY`
4. Run the following command to translate your .arb files (from the `lib/sharezone_localizations` directory):

```bash
arb_translate
```
nilsreichardt marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 3 additions & 1 deletion lib/sharezone_localizations/l10n.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ output-dir: lib/localizations
output-localization-file: sharezone_localizations.gen.dart
output-class: SharezoneLocalizations
synthetic-package: false
format: true
format: true
arb-translate-model: gemini-1.5-pro
arb-translate-context: A collaborative school planner for students, teachers and parents. Use informal language.
Loading