bhashini_flutter_translation_plugin_sdk 1.0.0
bhashini_flutter_translation_plugin_sdk: ^1.0.0 copied to clipboard
Bhashini Flutter SDK — auto-translates any Flutter app into 22 Indian languages. Zero widget changes required. Works by walking the element tree and injecting translations directly into RenderParagrap [...]
Bhashini Flutter SDK #
Translate any Flutter app into 22 Indian languages — without changing a single widget.
The SDK walks the Flutter element tree, collects every Text string on screen, sends them to the Bhashini translation backend in batches, and mutates the RenderParagraph objects in-place. No setState, no rebuilds, no wrapper widgets.
Features #
- Zero widget changes — works on existing apps as-is
- 22 Indian languages — all IndicTrans2-supported languages
- Auto-retranslation on screen navigation via
NavigatorObserver - Progressive rendering — each chunk appears as it arrives
- In-memory cache — subsequent visits to a screen are instant
- Drop-in FAB — pre-built translate button with language picker
Installation #
dependencies:
bhashini_flutter_translation_plugin_sdk: ^1.0.0
flutter pub get
Setup #
1. Register your app on the Bhashini portal #
Go to the Bhashini developer portal and register your Android app. You will need:
| Field | Where to find it |
|---|---|
| Package name | android/app/build.gradle → applicationId |
| Certificate fingerprint | keytool -list -v -keystore your-release.jks → SHA-256 line |
After registration you will receive a serviceId for use in step 2.
2. Initialise the SDK in main.dart #
void main() {
WidgetsFlutterBinding.ensureInitialized();
BhashiniSDK.init(
baseUrl: 'https://mobile-plugin.bhashini.gov.in',
serviceId: 'ai4bharat/indictrans-v2-all-gpu--t4/btp',
packageName: 'com.example.myapp',
certificateFingerprint: 'AB:CD:EF:12:34:...', // SHA-256 of your signing cert
);
runApp(const MyApp());
}
3. Wire into MaterialApp — two lines #
MaterialApp(
navigatorObservers: [BhashiniSDK.navigatorObserver], // detects screen changes
home: Scaffold(
floatingActionButton: const BhashiniFAB(), // translate button
body: const MyHomeScreen(),
),
)
That's the entire integration. The SDK handles everything else automatically.
How it works #
User taps FAB → language picker sheet
↓
User picks a language (e.g. Hindi)
↓
SDK walks the Flutter element tree
element.visitChildren() on rootElement
↓
Collects all Text widget strings
↓
Sends batches of 25 to /mobile/translate-text
with X-App-Package + X-App-Certificate headers
↓
Translations injected into RenderParagraph.text
(no widget rebuild required)
↓
NavigatorObserver detects screen push/pop
→ re-translates new screen automatically
API reference #
BhashiniSDK.init() #
BhashiniSDK.init({
required String baseUrl, // backend URL
required String serviceId, // IndicTrans2 service ID
String sourceLanguage = 'en', // source language (default English)
String? packageName, // X-App-Package header
String? certificateFingerprint, // X-App-Certificate header
});
BhashiniSDK.setLanguage(SupportedLanguage) #
Programmatically set the translation language without showing the picker UI.
BhashiniSDK.restoreOriginal() #
Restore all text to the original English (or source language).
BhashiniSDK.navigatorObserver #
Add to MaterialApp.navigatorObservers to re-translate automatically on every screen change.
BhashiniFAB #
Drop-in FloatingActionButton. Shows a spinner while translating, a language/restore menu when already translated.
Scaffold(
floatingActionButton: const BhashiniFAB(),
)
BhashiniSDK.instance.status #
BhashiniStatus enum: idle | loading | translated | error
BhashiniSDK.instance.onStateChanged #
Callback fired on every status change. Use to show custom loading indicators or error banners.
BhashiniSDK.instance.onStateChanged = () {
if (BhashiniSDK.instance.status == BhashiniStatus.error) {
showErrorSnackbar(BhashiniSDK.instance.lastError);
}
};
Supported languages #
| Code | Language |
|---|---|
as |
অসমীয়া (Assamese) |
bn |
বাংলা (Bengali) |
brx |
बड़ो (Bodo) |
doi |
डोगरी (Dogri) |
gu |
ગુજરાતી (Gujarati) |
hi |
हिन्दी (Hindi) |
kn |
ಕನ್ನಡ (Kannada) |
ks |
كٲشُر (Kashmiri) |
kok |
कोंकणी (Konkani) |
mai |
मैथिली (Maithili) |
ml |
മലയാളം (Malayalam) |
mni |
মৈতৈলোন্ (Manipuri) |
mr |
मराठी (Marathi) |
ne |
नेपाली (Nepali) |
or |
ଓଡ଼ିଆ (Odia) |
pa |
ਪੰਜਾਬੀ (Punjabi) |
sa |
संस्कृतम् (Sanskrit) |
sat |
ᱥᱟᱱᱛᱟᱲᱤ (Santali) |
sd |
سنڌي (Sindhi) |
ta |
தமிழ் (Tamil) |
te |
తెలుగు (Telugu) |
ur |
اردو (Urdu) |
License #
MIT — see LICENSE.