Lokalise SDK
This package provides Over-the-Air translation updates from the Lokalise platform.
Prerequisites
-
As of version
0.1.7
, 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
- Update
pubspec.yaml
file
dependencies: ... lokalise_ota_sdk: ^0.1.7 flutter_intl: ... lokalise: ota_enabled: true # Required for Over-the-Air translation updates
-
Trigger localization files generation by Flutter Intl IDE plugin or by intl_utils library
-
Initialize Lokalise SDK (e.g.
main.dart
file)
import 'package:flutter/material.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:lokalise_ota_sdk/lokalise_ota_sdk.dart'; // Import sdk package import 'generated/l10n.dart'; void main() { Lokalise.init('<SDK_TOKEN>', '<DISTRIBUTION_ID>'); // Init sdk Lokalise.setPreRelease(true); // Add this only if you want to use prereleases Lokalise.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(); Lokalise.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
- Update
pubspec.yaml
file
dependencies: ... lokalise_ota_sdk: ^0.1.7
- Generate localization files
flutter pub run lokalise_ota_sdk:generate
Update localizationsDelegates
and supportedLocales
props of the MaterialApp
widget.
import 'package:flutter_gen/gen_l10n/lokalise_localizations.dart'; class MyApp extends StatelessWidget { ... @override Widget build(BuildContext context) { return MaterialApp( ... localizationsDelegates: LokaliseLocalizations.localizationsDelegates, supportedLocales: LokaliseLocalizations.supportedLocales, ... ); } }
- Wrap the root of the app (e.g.
main.dart
file)
import 'package:lokalise_ota_sdk/lokalise_ota_sdk.dart'; // Import sdk package void main() { runApp( LokaliseInContextEditing( enabled: true, // set to false to disable In-Context Editing for production app builds child: MyApp(), ), ); }
- Connect to Lokalise
Run Flutter app on a real device and connect with Lokalise (paste the token).
Setup for Flutter Intl
- Update
pubspec.yaml
file
dependencies: ... lokalise_ota_sdk: ^0.1.7 flutter_intl: ... lokalise: ota_enabled: true # Required for In-Context Editing
-
Trigger localization files generation by Flutter Intl IDE plugin or by intl_utils library
-
Wrap the root of the app (e.g.
main.dart
file)
import 'package:lokalise_ota_sdk/lokalise_ota_sdk.dart'; // Import sdk package void main() { runApp( LokaliseInContextEditing( enabled: true, // set to false to disable In-Context Editing for production app builds child: MyApp(), ), ); }
- Connect to Lokalise
Run Flutter app on a real device and connect with Lokalise (paste the token).