i18n-plus
Features
- helps you to implement different languages in your app
- set the language for the i18nTextfields with one call globally
- provides easy and effortless live-changing of current the language
- i18nText is as customizeable as the original Text Widget
- checks if your languagesets are consistent
Example
import 'package:flutter/material.dart';
import 'package:i18n_plus/i18n.dart';
import 'package:i18n_plus/i18nLanguageset.dart';
import 'package:i18n_plus/i18nMap.dart';
import 'package:i18n_plus/i18nText.dart';
main() {
runApp(MaterialApp(home: Example()));
}
class Example extends StatefulWidget {
Example({Key key}) : super(key: key);
_ExampleState createState() => _ExampleState();
}
class _ExampleState extends State<Example> {
I18NMap map = I18NMap([
Langaugeset.fromJsonString(Locale('zh', 'CN'), "{\"greeting\":\"您好\"}"),
Langaugeset(Locale('en', 'Us'), {"greeting": "Hello"}),
Langaugeset(Locale('de', 'De'), {"greeting": "Hallo"}),
Langaugeset(Locale('fr', 'Fr'), {"greeting": "Bonjour"})
]);
I18N i18n = I18N();
@override
void initState() {
i18n.seti18nMap(map);
print(i18n.getI18nString("greeting", Locale("de", "De")));
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(children: [
Container(
child: I18NText(
i18nKey: "greeting",
additionalString: " Flutter Dev!",
)),
DropdownButton<Locale>(
items: i18n.allLocale().map((Locale value) {
return new DropdownMenuItem<Locale>(
value: value,
child: new Text(value.toLanguageTag()),
);
}).toList(),
onChanged: (value) {
i18n.setCurrentLocale(value);
},
)
]));
}
}
I18NMap map = I18NMap([
Langaugeset(Locale('en', 'Us'), {"greeting": "Hello"}),
Langaugeset(Locale('de', 'De'), {"greeting": "Hallo"}),
Langaugeset(Locale('fr', 'Fr'), {"greeting": "Bonjour"})
]);
I18N i18n = I18N();
i18n.seti18nMap(map);
i18n.allLocale();
- get single String from i18n
I18NMap map = I18NMap([
Langaugeset(Locale('en', 'Us'), {"greeting": "Hello"}),
Langaugeset(Locale('de', 'De'), {"greeting": "Hallo"}),
Langaugeset(Locale('fr', 'Fr'), {"greeting": "Bonjour"})
]);
I18N i18n = I18N();
i18n.seti18nMap(map);
///first param [i18nKey]; second param [Locale] can be null
///if you want to use current [Locale]
i18n.getI18nString("greeting", Locale('de', 'De'))
I18NMap map = I18NMap([
Langaugeset.fromJsonString(Locale('zh', 'CN'), "{\"greeting\":\"您好\"}"),
Langaugeset(Locale('en', 'Us'), {"greeting": "Hello"}),
Langaugeset(Locale('de', 'De'), {"greeting": "Hallo"}),
Langaugeset(Locale('fr', 'Fr'), {"greeting": "Bonjour"})
]);
I18N i18n = I18N();
i18n.seti18nMap(map);
///first param [i18nKey]; second param [Locale] can be null
///if you want to use current [Locale]
i18n.getI18nString("greeting", Locale('de', 'De'))