translate_hub_handler 1.0.0
translate_hub_handler: ^1.0.0 copied to clipboard
Over-The-Air (OTA) localization SDK for Flutter. Update translations instantly without resubmitting to the App Store or Google Play. Supports offline fallback, automatic language resolution, and daily [...]
translate_hub_handler #
Over-The-Air (OTA) localization SDK for Flutter. Update your app's translations instantly — no App Store or Google Play resubmission required.
Manage all your translation keys from the TranslationsHub dashboard, and the SDK delivers updates to your users automatically every day.
Features #
- OTA updates — translations refresh daily in the background
- Offline fallback — bundled JSON asset used when the network is unavailable
- Zero backend cost — translations are fetched directly via a signed URL
- Automatic language resolution — saved choice → device locale →
en - RTL support —
THLanguageItem.textDirectionfor Arabic, Hebrew, etc. - Simple API — one
.translateextension onString
Installation #
dependencies:
translate_hub_handler: ^1.0.0
flutter pub get
Setup #
1. Add INTERNET permission (Android only) #
Flutter does not include the INTERNET permission by default on Android.
<!-- android/app/src/main/AndroidManifest.xml -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
...
</manifest>
2. Add the fallback translations file (optional but recommended) #
Place your translations.json in assets/ and register it in pubspec.yaml:
flutter:
assets:
- assets/translations.json
See the JSON format section below.
Usage #
Initialize #
import 'package:translate_hub_handler/translate_hub_handler.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await TranslateHub.shared.initialize(
const TranslateHubConfig(
apiKey: 'YOUR_API_KEY', // from the TranslationsHub dashboard
fallbackFile: 'translations', // asset name without .json
),
);
runApp(const MyApp());
}
Translate strings #
// In any widget:
Text('greeting'.translate ?? 'Hello!'),
Text('subtitle'.translate ?? 'Welcome'),
Switch language #
final hub = TranslateHub.shared;
// Available languages
final languages = hub.translation?.languages ?? [];
// Current language
final current = hub.current; // THLanguageItem?
// RTL direction (useful for Directionality widget)
final dir = current?.textDirection; // TextDirection.ltr / .rtl
// Switch
hub.pickLanguage('he');
setState(() {});
Offline mode #
const TranslateHubConfig(
apiKey: 'YOUR_API_KEY',
fallbackFile: 'translations',
offline: true, // skip network, load bundled asset only
)
JSON Format #
All languages share the same file structure:
{
"languages": [
{ "code": "en", "name": "English", "direction": "ltr" },
{ "code": "fr", "name": "French", "direction": "ltr" },
{ "code": "he", "name": "Hebrew", "direction": "rtl" }
],
"en": {
"greeting": "Hello!",
"subtitle": "Your app, in every language"
},
"fr": {
"greeting": "Bonjour!",
"subtitle": "Votre app, dans toutes les langues"
},
"he": {
"greeting": "שלום!",
"subtitle": "האפליקציה שלך, בכל שפה"
}
}
Additional information #
- Dashboard: translate-io.com
- iOS SDK: github.com/translate-hub/ios_sdk
- Android SDK: github.com/translate-hub/android_sdk
- Issues: github.com/translate-hub/flutter_sdk/issues