Welcome to Translatron!
##!BETA VERSION - NOT FOR LIVE OR PROD USAGE!
Description
Comming soon...
Usage
Comming soon...
Initilazion
Basic Initilazion
void main() async {
await Translatron.init(
hostname: "https://example.com",
versionPath: "/api/translation/version",
translationsPath: "/api/translation/translations",
);
]);
Initilazion with custom supported languages
void main() async {
await Translatron.init(
hostname: "https://example.com",
versionPath: "/api/translation/version",
translationsPath: "/api/translation/translations",
supportedLocales: const [
Locale('hu'),
Locale('en'),
],
);
]);
Initilazion with custom supported languages and custom api headers
void main() async {
await Translatron.init(
hostname: "https://example.com",
versionPath: "/api/translation/version",
translationsPath: "/api/translation/translations",
supportedLocales: const [
Locale('hu'),
Locale('en'),
],
apiHeaders: const {
"Authorization" : "Bearer $token",
"Content-Type: application/json"
}
);
]);
Add the custom delegate to app
return MaterialApp.router(
title: 'DemoApp',
localizationsDelegates: const [
Translatron.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
//To change to your state management
locale: Provider.of<LocaleProvider>(context, listen: true).getlocale,
supportedLocales: Translatron.getSupportedLocales,
);
Demo provider
class LocaleProvider with ChangeNotifier {
Locale? locale = Translatron.getSelectedLanguageLocale;
Locale? get getlocale {
return locale;
}
void changeLocale(Locale newLocale) {
locale = newLocale;
Translatron.setSelectedLanguageLocale = locale!;
notifyListeners();
}
}
Language change with provider
Provider.of<LocaleProvider>(context, listen: false)
.changeLocale(const Locale('hu', 'HU'));
Functions
Translate, returns string
Translatron.of(context)!.translate("translation.key");
Return if language is active, returns bool
Translatron.isLanguageActice('en');
Returns the supported locales in List of Locale
Translatron.getSupportedLocales;
Returns the selected Language Locale, in some cases nullable
Translatron.getSelectedLanguageLocale;
Sets the selected Language Locale, in some cases nullable
Translatron.setSelectedLanguageLocale = locale!;