translations_center 0.1.0
translations_center: ^0.1.0 copied to clipboard
Offline-first OTA localization SDK for Flutter apps. Stale-While-Revalidate caching with ETag support.
translations_center #
Offline-first OTA (Over-The-Air) localization SDK for Flutter apps, featuring Stale-While-Revalidate caching with ETag support.
Architecture #
This package implements an offline-first strategy:
- Try loading from SharedPreferences cache (zero latency).
- If empty, load from fallback assets.
- In the background, ping the server using the stored ETag.
- If a newer translation bundle is available (HTTP 200), update the cache.
- If nothing changed, the server returns HTTP 304, saving bandwidth.
Missing keys are buffered and automatically reported to the server.
Installation #
dependencies:
translations_center: ^0.1.0
Quick Start #
1. Initialization #
Call init in your main() before runApp.
import 'package:flutter/material.dart';
import 'package:translations_center/translations_center.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await TranslationsCenter.init(
serverUrl: 'https://api.translations-center.com',
apiKey: 'your_api_key_here',
defaultLocale: const Locale('en'),
fallbackAssetsPath: 'assets/i18n',
);
runApp(const MyApp());
}
2. AppStrings Pattern #
Create an enum for your keys:
enum AppStrings {
exit,
welcome;
String get([dynamic arg0, dynamic arg1, dynamic arg2, dynamic arg3]) {
final args = <dynamic>[
if (arg0 != null) arg0,
if (arg1 != null) arg1,
if (arg2 != null) arg2,
if (arg3 != null) arg3,
];
return TranslationsCenter.instance.get(name, args);
}
}
3. Usage #
Text(AppStrings.exit.get());
Text(AppStrings.welcome.get('Eyal', 'My App'));
License #
MIT