lokalise_flutter_sdk 0.0.6 lokalise_flutter_sdk: ^0.0.6 copied to clipboard
Lokalise Flutter SDK over-the-air translations update
Lokalise Flutter SDK #
This package provides Over-the-Air translation updates
Over-the-air translation updates #
Update translations for your Flutter applications over the air. Learn more
Getting started #
Initialize Lokalise SDK (main.dart
file)
Usage #
import 'package:flutter/material.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:lokalise_flutter_sdk/lokalise_flutter_sdk.dart'; // Import sdk package import 'generated/l10n.dart'; void main() { Lokalise.init('<SDK_TOKEN>', '<PROJECT ID>'); // Init sdk Lokalise.setPreRelease(true); // Add this only if you want to use prereleases runApp(MaterialApp( onGenerateTitle: (context) => Tr.of(context).appTitle, localizationsDelegates: [ Tr.delegate, GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], supportedLocales: Tr.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(Tr.of(context).pageHomeTitle)), body: Center( child: _isLoading ? CircularProgressIndicator() : Column(children: <Widget>[Text(Tr.of(context).welcome)]))); } }
Additional information #
Generate localization files
To generate dart class for OTA service, after the translation keys have been changed use this command: flutter pub run lokalise_flutter_sdk:tr or this command once: dart pub global activate lokalise_flutter_sdk and use: tr