Requirements

Locale Sync’s SDK integrates with Flutter through flutter_localizations package, so, naturally, you’ll need to get this added to your pubspec.yaml:

pubspec.yaml
    ...
    flutter_localizations:
        sdk: flutter
    intl: any
    ...

Once added, you need to add your supported locales on your app widget along with the localization delegates:

lib/app.dart
    return MaterialApp(
        supportedLocales: const [
            Locale("pt"),
            Locale("en"),
        ],
        localizationsDelegates: [
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
        ],
    );

Installing

Add locale_sync package as a dependency:

    flutter pub add locale_sync

Once you have already added your config file and your translation fallback file you can generate your .dart files by running:

    dart run locale_sync gen

If you want to upload it to servers already you can just run after:

    dart run locale_sync upload

This will send your translations to the repository specified in your config file, upserting languages and strings from your file.

On your app widget you need to add LocaleSync.delegate to that list:

lib/app.dart
    return MaterialApp(
        supportedLocales: const [
            Locale("pt"),
            Locale("en"),
        ],
        localizationsDelegates: [
            // Add this line
            LocaleSync.delegate
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
        ],
    );

Over the air

If you want to use our over-the-air strings feature you just need to call setup method from LocaleSync on your main.dart, or whatever entry point you’re using:

main.dart
    void main() async {
        // setups
        await LocaleSync.setup(
            apiToken: "your-api-token",
            repositoryId: "your-repository-id",
        );
        
        // run your app
        runApp(
            const App(),
        );
    }

Getting translations

lib/screens/my_screen.dart
    ...,
    Text(
        LocaleSync.of(context).yourString
    ),
    ...

When you get strings which takes arguments you add it as a function arg, and the same is applied to plural strings:

lib/screens/my_screen.dart
    ...,
    Text(
        LocaleSync.of(context).minValidation(
            count: 8,
            name: translations.password,
        ),
    ),
    ...
lib/translations/fallback_translation.json
    {
        "en": {
            "minValidation" : {
                "plural" : "{name} deve ter no mínimo {count} caracteres",
                "value" : "{name} deve ter no mínimo 1 caracter"
            }
        }
    }