Kai Oswald

Add internationalization section to readme

@@ -29,10 +29,11 @@ @@ -29,10 +29,11 @@
29 - [More details about dependency management](#more-details-about-dependency-management) 29 - [More details about dependency management](#more-details-about-dependency-management)
30 - [How to contribute](#how-to-contribute) 30 - [How to contribute](#how-to-contribute)
31 - [Utils](#utils) 31 - [Utils](#utils)
  32 + - [Internationalization](#internationalization)
32 - [Change Theme](#change-theme) 33 - [Change Theme](#change-theme)
33 - [Other Advanced APIs](#other-advanced-apis) 34 - [Other Advanced APIs](#other-advanced-apis)
34 - [Optional Global Settings and Manual configurations](#optional-global-settings-and-manual-configurations) 35 - [Optional Global Settings and Manual configurations](#optional-global-settings-and-manual-configurations)
35 - - [Video explanation of Other GetX Features](#video-explanation-of-other-getx-features) 36 + - [Video explanation of Other GetX Features](#video-explanation-of-other-getx-features)
36 - [Breaking changes from 2.0](#breaking-changes-from-20) 37 - [Breaking changes from 2.0](#breaking-changes-from-20)
37 - [Why Getx?](#why-getx) 38 - [Why Getx?](#why-getx)
38 39
@@ -296,7 +297,61 @@ Text(controller.textFromApi); @@ -296,7 +297,61 @@ Text(controller.textFromApi);
296 Any contribution is welcome! 297 Any contribution is welcome!
297 298
298 # Utils 299 # Utils
  300 +## Internationalization
  301 +### Translations
  302 +Translations are kept as a simple key-value dictionary map.
  303 +To add custom translations, create a class and extend `Translations`.
  304 +```dart
  305 +import 'package:get/get.dart';
  306 +
  307 +class Messages extends Translations {
  308 + @override
  309 + Map<String, Map<String, String>> get keys => {
  310 + 'en_US': {
  311 + 'hello': 'Hello World',
  312 + },
  313 + 'de_DE': {
  314 + 'hello': 'Hallo Welt',
  315 + }
  316 + };
  317 +}
  318 +```
  319 +
  320 +#### Using translations
  321 +Just append `.tr` to the specified key and it will be translated, using the current value of `Get.locale` and `Get.fallbackLocale`.
  322 +```dart
  323 +Text('title'.tr);
  324 +```
  325 +
  326 +### Locales
  327 +Pass parameters to `GetMaterialApp` to define the locale and translations.
  328 +
  329 +```dart
  330 +return GetMaterialApp(
  331 + translations: Messages(), // your translations
  332 + locale: Locale('en_US'), // translations will be displayed in that locale
  333 + fallbackLocale: Locale('en_US'), // specify the fallback locale in case an invalid locale is selected.
  334 + supportedLocales: <Locale>[Locale('en_US'), Locale('de_DE')] // specify the supported locales
  335 +);
  336 +```
  337 +
  338 +#### Change locale
  339 +Call `Get.updateLocale(locale)` to update the locale. Translations then automatically use the new locale.
  340 +```dart
  341 +var locale = Locale('en_US');
  342 +Get.updateLocale(locale);
  343 +```
299 344
  345 +#### System locale
  346 +To read the system locale, you could use `Platform.localeName`.
  347 +```dart
  348 +return GetMaterialApp(
  349 + locale: Locale(Platform.localeName),
  350 +);
  351 +```
  352 +
  353 +### More details about state management
  354 +**See a more in-depth explanation of internationalization [here](./docs/en_US/internationalization.md)**
300 ## Change Theme 355 ## Change Theme
301 356
302 Please do not use any higher level widget than GetMaterialApp in order to update it. This can trigger duplicate keys. A lot of people are used to the prehistoric approach of creating a "ThemeProvider" widget just to change the theme of your app, and this is definitely NOT necessary with Get. 357 Please do not use any higher level widget than GetMaterialApp in order to update it. This can trigger duplicate keys. A lot of people are used to the prehistoric approach of creating a "ThemeProvider" widget just to change the theme of your app, and this is definitely NOT necessary with Get.