### Example JSON File After Extraction and Update Source: https://github.com/thanhtunguet/supa_l10n_manager/blob/main/README.md Presents an example of a JSON translation file (`assets/i18n/en/user.json`) after it has been updated by the `extract` command, showing a newly added missing key. ```json { "login.username": "Username", "login.password": "Password", "profile.email": "" } ``` -------------------------------- ### Install supa_l10n_manager Flutter Package Source: https://github.com/thanhtunguet/supa_l10n_manager/blob/main/README.md Add the supa_l10n_manager package to your Flutter project's dependencies by specifying its Git repository in `pubspec.yaml`. After adding the dependency, run `flutter pub get` to install it. ```yaml dependencies: supa_l10n_manager: git: url: https://github.com/thanhtunguet/supa_l10n_manager.git ``` ```bash flutter pub get ``` -------------------------------- ### Reorder Translation Keys - Before and After Example Source: https://github.com/thanhtunguet/supa_l10n_manager/blob/main/README.md Demonstrates the effect of the `reorder` command on a JSON translation file. Keys are rearranged alphabetically to improve readability and version control. ```json { "login.password": "Password", "profile.email": "Email", "login.username": "Username" } ``` ```json { "login.password": "Password", "login.username": "Username", "profile.email": "Email" } ``` -------------------------------- ### JSON Translation File Structure Source: https://context7.com/thanhtunguet/supa_l10n_manager/llms.txt Demonstrates the structure of namespace-based JSON translation files for different locales. Each file contains key-value pairs for translations within a specific namespace (e.g., 'user', 'product'). The 'en.json' example shows a merged locale file containing all namespaces for a given locale. ```json // assets/i18n/en/user.json { "login.password": "Password", "login.username": "Username", "profile.email": "Email Address", "profile.name": "Full Name" } // assets/i18n/en/product.json { "detail.description": "Description", "detail.name": "Product Name", "detail.price": "Price: ${value}", "list.empty": "No products found", "list.title": "Products" } // assets/i18n/vi/user.json { "login.password": "Mật khẩu", "login.username": "Tên đăng nhập", "profile.email": "Địa chỉ email", "profile.name": "Họ và tên" } // assets/i18n/en.json (after running merge command) { "product.detail.description": "Description", "product.detail.name": "Product Name", "product.detail.price": "Price: ${value}", "product.list.empty": "No products found", "product.list.title": "Products", "user.login.password": "Password", "user.login.username": "Username", "user.profile.email": "Email Address", "user.profile.name": "Full Name" } ``` -------------------------------- ### Flutter App Localization Setup (Dart) Source: https://context7.com/thanhtunguet/supa_l10n_manager/llms.txt Demonstrates how to integrate the Supa L10n Manager with a Flutter application for internationalization. It utilizes the `AppLocalizationsDelegate` to handle different locales and the `translate` function for accessing localized strings within the UI. Dependencies include 'flutter/material.dart', 'supa_l10n_manager/localization_delegate.dart', and 'supa_l10n_manager/translator.dart'. ```dart import 'package:flutter/material.dart'; import 'package:supa_l10n_manager/localization_delegate.dart'; import 'package:supa_l10n_manager/translator.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Localization Demo', localizationsDelegates: const [ AppLocalizationsDelegate(fallbackLocale: 'en'), ], supportedLocales: const [ Locale('en'), Locale('vi'), Locale('ja'), ], home: HomeScreen(), ); } } class HomeScreen extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(translate('app.title')), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text(translate('user.login.username')), Text(translate('user.login.password')), Text(translate('dashboard.welcome', {'name': 'User'})), ], ), ), ); } } ``` -------------------------------- ### Extract Missing Keys from Dart Code - Example Usage Source: https://github.com/thanhtunguet/supa_l10n_manager/blob/main/README.md Illustrates how specific `translate` calls in Dart code are used to generate or update JSON translation entries. This functionality helps maintain consistency between code and translation files. ```dart translate('user.login.username'); translate('user.login.password'); ``` -------------------------------- ### Basic Translation with Placeholders Source: https://context7.com/thanhtunguet/supa_l10n_manager/llms.txt Provides basic translation functionality using the `translate` function. It supports simple key lookups and also allows for placeholder substitution within translation strings. If a key is not found, the function returns the key itself. ```dart import 'package:supa_l10n_manager/translator.dart'; // Simple translation String username = translate('user.login.username'); // Output: "Username" // Translation with placeholders String welcome = translate('dashboard.welcome', {'name': 'John', 'role': 'Admin'}); // Expected output: "Welcome, John! You are logged in as Admin." // Handling missing keys - returns the key itself String missing = translate('nonexistent.key'); // Output: "nonexistent.key" ``` -------------------------------- ### Load Localization Data in Flutter App Source: https://github.com/thanhtunguet/supa_l10n_manager/blob/main/README.md Initialize the localization system by calling `Localization.load()` with the desired locale before running your Flutter application. Ensure `WidgetsFlutterBinding.ensureInitialized()` is called first. ```dart import 'package:supa_l10n_manager/localization.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); await Localization.load('en'); runApp(MyApp()); } ``` -------------------------------- ### Initialize Localization System in Flutter Source: https://context7.com/thanhtunguet/supa_l10n_manager/llms.txt Initializes the Supa L10n Manager localization system by loading a specified locale and an optional fallback locale. This function should be called early in the application lifecycle, typically in the `main` function after `WidgetsFlutterBinding.ensureInitialized()`. ```dart import 'package:flutter/material.dart'; import 'package:supa_l10n_manager/localization.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); // Load English locale with Vietnamese fallback await Localization.load('en', fallbackLocale: 'vi'); runApp(MyApp()); } ``` -------------------------------- ### Extract Missing Keys from Dart Code using CLI Source: https://github.com/thanhtunguet/supa_l10n_manager/blob/main/README.md This command scans Dart source files for `translate('key')` usages and updates the corresponding namespace JSON files. If a key is missing, it is added with an empty string. If the namespace file does not exist, it is automatically created. The `--source` argument specifies the directory to scan. ```bash dart run bin/supa_l10n_manager.dart extract --locale en --source lib ``` -------------------------------- ### Merge JSON Files using Dart CLI Source: https://github.com/thanhtunguet/supa_l10n_manager/blob/main/README.md This command merges all `namespace.json` files into a single file per locale. It's useful for consolidating translations before deployment or further processing. Ensure your JSON files are correctly structured. ```bash dart run bin/supa_l10n_manager.dart merge ``` -------------------------------- ### Integrate supa_l10n_manager with Flutter Localization Delegate Source: https://github.com/thanhtunguet/supa_l10n_manager/blob/main/README.md Integrate the package with Flutter's localization system by adding `AppLocalizationsDelegate` to `MaterialApp`'s `localizationsDelegates`. Specify supported locales and a fallback locale. ```dart import 'package:flutter/material.dart'; import 'package:supa_l10n_manager/localization_delegate.dart'; import 'package:supa_l10n_manager/translator.dart'; // Import translator for translate function void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( localizationsDelegates: const [ AppLocalizationsDelegate(fallbackLocale: 'en'), ], supportedLocales: const [ Locale('en'), Locale('vi'), ], home: Scaffold( appBar: AppBar(title: const Text('Localization Example')), body: Center( child: Text(translate('user.login.username')), ), ), ); } } ``` -------------------------------- ### Extract Missing Keys from Dart Code - Resulting JSON Source: https://github.com/thanhtunguet/supa_l10n_manager/blob/main/README.md Shows the resulting JSON structure after the `extract` command processes Dart code. New keys are added with empty string values, and existing ones are preserved. ```json { "login.username": "Username", "login.password": "Password" } ``` -------------------------------- ### Merge Locale Files using CLI (Bash) Source: https://context7.com/thanhtunguet/supa_l10n_manager/llms.txt A command-line interface command to merge multiple namespaced JSON locale files into single, flat locale files. This command is useful for consolidating translations from different modules or features into a unified structure for each language. It operates on files within a specified directory structure, transforming a namespaced organization into a flat one. ```bash # Merge all namespace files for each locale dart run bin/supa_l10n_manager.dart merge # Before merge (namespace structure): # assets/i18n/ # en/ # user.json -> {"login.username": "Username", "login.password": "Password"} # product.json -> {"list.title": "Products", "detail.name": "Name"} # vi/ # user.json -> {"login.username": "Tên đăng nhập", "login.password": "Mật khẩu"} # product.json -> {"list.title": "Sản phẩm", "detail.name": "Tên"} # After merge (flat structure): # assets/i18n/ # en.json -> { # "user.login.username": "Username", # "user.login.password": "Password", # "product.list.title": "Products", # "product.detail.name": "Name" # } # vi.json -> { # "user.login.username": "Tên đăng nhập", # "user.login.password": "Mật khẩu", ``` -------------------------------- ### Reorder Translation Keys Alphabetically using CLI Source: https://github.com/thanhtunguet/supa_l10n_manager/blob/main/README.md This command sorts all keys within translation JSON files alphabetically. It applies to both merged locale files and individual namespace files, ensuring consistent ordering for easier diffing and management. ```bash dart run bin/supa_l10n_manager.dart reorder ``` -------------------------------- ### Pluralization with supa_l10n_manager Source: https://github.com/thanhtunguet/supa_l10n_manager/blob/main/README.md Handle plural forms in translations using the `plural` function. This function accepts a callback that defines `PluralForm` with different cases (zero, one, other) and a value. It returns the appropriate localized string at runtime. ```dart import 'package:supa_l10n_manager/plural.dart'; final result = plural((t) { return PluralForm( one: t('items.one'), // e.g. "{value} item" other: t('items.other'), // e.g. "{value} items" zero: t('items.zero'), // optional, e.g. "No items" value: 2, ); }); // With value = 2 -> "items.other" (actual translation once keys are provided) ``` -------------------------------- ### Format Time Durations to Localized Strings (Dart) Source: https://context7.com/thanhtunguet/supa_l10n_manager/llms.txt Converts Duration objects into human-readable, localized time strings. It intelligently selects appropriate time units (years, months, days, hours, minutes, seconds) based on the duration's magnitude and supports custom translation keys for different units, including a specific key for zero durations. Dependencies include the 'supa_l10n_manager' package. Input is a Duration object and a function to define translation keys. ```dart import 'package:supa_l10n_manager/time.dart'; // Simple duration formatting final text1 = translateTime( Duration(hours: 2, minutes: 5), (t) => TimeKeySets( years: UnitKeySet(one: t('time.year.one'), other: t('time.year.other')), months: UnitKeySet(one: t('time.month.one'), other: t('time.month.other')), days: UnitKeySet(one: t('time.day.one'), other: t('time.day.other')), hours: UnitKeySet(one: t('time.hour.one'), other: t('time.hour.other')), minutes: UnitKeySet(one: t('time.minute.one'), other: t('time.minute.other')), seconds: UnitKeySet(one: t('time.second.one'), other: t('time.second.other')), ), ); // Output: "2 hours" (minutes ignored by default) // Combined hours and minutes final text2 = translateTime( Duration(hours: 2, minutes: 5), (t) => TimeKeySets( years: UnitKeySet(one: t('time.year.one'), other: t('time.year.other')), months: UnitKeySet(one: t('time.month.one'), other: t('time.month.other')), days: UnitKeySet(one: t('time.day.one'), other: t('time.day.other')), hours: UnitKeySet(one: t('time.hour.one'), other: t('time.hour.other')), minutes: UnitKeySet(one: t('time.minute.one'), other: t('time.minute.other')), seconds: UnitKeySet(one: t('time.second.one'), other: t('time.second.other')), ), combineHoursAndMinutes: true, ); // Output: "2 hours 5 minutes" // Days formatting final text3 = translateTime( Duration(days: 45), (t) => TimeKeySets( years: UnitKeySet(one: t('time.year.one'), other: t('time.year.other')), months: UnitKeySet(one: t('time.month.one'), other: t('time.month.other')), days: UnitKeySet(one: t('time.day.one'), other: t('time.day.other')), hours: UnitKeySet(one: t('time.hour.one'), other: t('time.hour.other')), minutes: UnitKeySet(one: t('time.minute.one'), other: t('time.minute.other')), seconds: UnitKeySet(one: t('time.second.one'), other: t('time.second.other')), ), ); // Output: "1 month" (45 days / 30 = 1 month) // Zero handling with optional zero key final text4 = translateTime( Duration(seconds: 0), (t) => TimeKeySets( years: UnitKeySet(one: t('time.year.one'), other: t('time.year.other')), months: UnitKeySet(one: t('time.month.one'), other: t('time.month.other')), days: UnitKeySet(one: t('time.day.one'), other: t('time.day.other')), hours: UnitKeySet(one: t('time.hour.one'), other: t('time.hour.other')), minutes: UnitKeySet(one: t('time.minute.one'), other: t('time.minute.other')), seconds: UnitKeySet( one: t('time.second.one'), other: t('time.second.other'), zero: t('time.second.zero'), ), ), ); // Output: "Just now" (using zero key if provided) ``` -------------------------------- ### Reorder Translation Keys Alphabetically Source: https://context7.com/thanhtunguet/supa_l10n_manager/llms.txt The 'reorder' command sorts all translation keys alphabetically within JSON files across specified locales. This ensures consistent organization and simplifies diffs in version control systems, making it easier to track changes. It operates on all locale files found in the default or specified directory. ```bash # Reorder all JSON files in assets/i18n dart run bin/supa_l10n_manager.dart reorder ``` -------------------------------- ### Time Duration Formatting with translateTime Source: https://github.com/thanhtunguet/supa_l10n_manager/blob/main/README.md Format `Duration` objects into localized strings using `translateTime`. This function uses a callback to define translation keys for various time units (years, months, days, hours, minutes, seconds) and supports combining hours and minutes. ```dart import 'package:supa_l10n_manager/time.dart'; final text = translateTime( Duration(hours: 2, minutes: 5), (t) => TimeKeySets( years: UnitKeySet(one: t('time.year.one'), other: t('time.year.other'), zero: t('time.year.zero')), months: UnitKeySet(one: t('time.month.one'), other: t('time.month.other'), zero: t('time.month.zero')), days: UnitKeySet(one: t('time.day.one'), other: t('time.day.other'), zero: t('time.day.zero')), hours: UnitKeySet(one: t('time.hour.one'), other: t('time.hour.other'), zero: t('time.hour.zero')), minutes: UnitKeySet(one: t('time.minute.one'), other: t('time.minute.other'), zero: t('time.minute.zero')), seconds: UnitKeySet(one: t('time.second.one'), other: t('time.second.other'), zero: t('time.second.zero')), ), combineHoursAndMinutes: true, // produces e.g. "2 hours 5 minutes" ); ``` -------------------------------- ### Pluralization with Multiple Forms Source: https://context7.com/thanhtunguet/supa_l10n_manager/llms.txt Handles pluralization based on a given value, supporting zero, one, and other forms of translation. It uses the `plural` function and `PluralForm` class to define translations for different quantities. The `value` parameter determines which plural form is used. ```dart import 'package:supa_l10n_manager/plural.dart'; import 'package:supa_l10n_manager/plural_form.dart'; // Define plural forms with translation keys final itemsText = plural((t) { return PluralForm( one: t('cart.items.one'), // Translation: "{value} item" other: t('cart.items.other'), // Translation: "{value} items" zero: t('cart.items.zero'), // Translation: "No items" value: 0, ); }); // Output: "No items" final itemsTextTwo = plural((t) { return PluralForm( one: t('cart.items.one'), other: t('cart.items.other'), zero: t('cart.items.zero'), value: 2, ); }); // Output: "2 items" final itemsTextOne = plural((t) { return PluralForm( one: t('cart.items.one'), other: t('cart.items.other'), value: 1, ); }); // Output: "1 item" ``` -------------------------------- ### Extract Translation Keys from Dart Code Source: https://context7.com/thanhtunguet/supa_l10n_manager/llms.txt The 'extract' command scans Dart source files to find translation keys used with the 'translate' function. It updates or creates locale-specific JSON files, optionally removing orphan keys and reordering entries for better maintainability. This command is crucial for keeping translation files synchronized with the codebase. ```bash # Extract keys from lib directory for English locale dart run bin/supa_l10n_manager.dart extract --locale en --source lib # Extract with orphan key removal dart run bin/supa_l10n_manager.dart extract -l en -s lib --remove-orphans # Extract with automatic reordering dart run bin/supa_l10n_manager.dart extract -l vi -s lib --reorder # Extract with both orphan removal and reordering dart run bin/supa_l10n_manager.dart extract -l en -s lib -r -o ``` -------------------------------- ### Retrieve Translations using translate Function Source: https://github.com/thanhtunguet/supa_l10n_manager/blob/main/README.md Access localized strings within your Flutter app using the `translate` function. It takes a translation key (potentially nested) and an optional map for dynamic values. The function returns the corresponding localized string. ```dart import 'package:supa_l10n_manager/translator.dart'; String usernameLabel = translate('user.login.username'); print(usernameLabel); // Output: "Username" print(translate('dashboard.welcome', {'name': 'John'})); // Output: "Welcome, John!" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.