Localizely SDK

pub package

This package provides Over-the-Air translation updates and In-Context Editing from the Localizely platform.

Platform Support

AndroidiOSWebMacOSLinuxWindows

Prerequisites

  • As of version 2.4.0, an update of min platform versions is required:

    • Android: Require Android SDK 21 or newer

    • iOS: Require iOS 11 or newer

Over-the-Air translation updates

Update translations for your Flutter applications over the air. Learn more

Setup

  1. Update pubspec.yaml file
dependencies:
  ...
  localizely_sdk: ^2.4.0

flutter_intl:
  ...
  localizely:
    ota_enabled: true # Required for Over-the-Air translation updates
  1. Trigger localization files generation by Flutter Intl IDE plugin or by intl_utils library

  2. Initialize Localizely SDK (e.g. main.dart file)

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:localizely_sdk/localizely_sdk.dart'; // Import sdk package
import 'generated/l10n.dart';

void main() {
  Localizely.init('<SDK_TOKEN>', '<DISTRIBUTION_ID>'); // Init sdk 
  Localizely.setPreRelease(true); // Add this only if you want to use prereleases
  Localizely.setAppVersion('<APP_VERSION>'); // Add this only if you want to explicitly set the application version, or in cases when automatic detection is not possible (e.g. Flutter web apps)

  runApp(MaterialApp(
      onGenerateTitle: (context) => S.of(context).appTitle,
      localizationsDelegates: [
        S.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: S.delegate.supportedLocales,
      home: HomePage()));
}

class HomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  bool _isLoading = true;

  @override
  void initState() {
    super.initState();

    Localizely.updateTranslations().then( // Call 'updateTranslations' after localization delegates initialization
        (response) => setState(() {
              _isLoading = false;
            }),
        onError: (error) => setState(() {
              _isLoading = false;
            }));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text(S.of(context).pageHomeTitle)),
        body: Center(
            child: _isLoading ? CircularProgressIndicator() : Column(children: <Widget>[Text(S.of(context).welcome)])));
  }
}

In-Context Editing

Instantly see how your translations fit on a real device without unnecessary app builds. Learn more. Works with projects that use Flutter's gen_l10n approach for internationalization, and with projects that use Flutter Intl IDE plugin / intl_utils.

Setup for gen_l10n

  1. Update pubspec.yaml file
dependencies:
  ...
  localizely_sdk: ^2.4.0
  1. Generate localization files
flutter pub run localizely_sdk:generate

Update localizationsDelegates and supportedLocales props of the MaterialApp widget.

import 'package:flutter_gen/gen_l10n/localizely_localizations.dart';

class MyApp extends StatelessWidget {
  ...

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      ...
      localizationsDelegates: LocalizelyLocalizations.localizationsDelegates,
      supportedLocales: LocalizelyLocalizations.supportedLocales,
      ...
    );
  }
}
  1. Wrap the root of the app (e.g. main.dart file)
import 'package:localizely_sdk/localizely_sdk.dart'; // Import sdk package

void main() {
  runApp(
    LocalizelyInContextEditing(
      enabled: true, // set to false to disable In-Context Editing for production app builds
      child: MyApp(),
    ),
  );
}
  1. Connect to Localizely

Run Flutter app on a real device and connect with Localizely by scanning the QR code (for web & desktop apps paste the token).

Setup for Flutter Intl

  1. Update pubspec.yaml file
dependencies:
  ...
  localizely_sdk: ^2.4.0

flutter_intl:
  ...
  localizely:
    ota_enabled: true # Required for In-Context Editing
  1. Trigger localization files generation by Flutter Intl IDE plugin or by intl_utils library

  2. Wrap the root of the app (e.g. main.dart file)

import 'package:localizely_sdk/localizely_sdk.dart'; // Import sdk package

void main() {
  runApp(
    LocalizelyInContextEditing(
      enabled: true, // set to false to disable In-Context Editing for production app builds
      child: MyApp(),
    ),
  );
}
  1. Connect to Localizely

Run Flutter app on a real device and connect with Localizely by scanning the QR code (for web & desktop apps paste the token).

Want to learn more?

Libraries

localizely_sdk