Internationalization in Flutter using GetX

Overview

Implementation

  1. Wrap you MaterialApp widget with GetMaterialApp and set the device locale as the default app locale for the application using locale: Get.deviceLocale what this will do is that it will get the user's default locale and set it to apps locale.
  2. Define the fallback locale, this will comes into the picture when an invalid locale is selected. This is done using fallbackLocale: Locale(‘en’, ‘US’) the property, here we are specifying that if there is an invalid locale, it will be automatically changed to ‘en_US’
  3. Now we need to add the translationkeys to the GetMaterialApp widget using translationsKeys: AppTranslation.translationsKeys property.
    Note: I am also using the GetX for navigation and state-management but you can use the default navigation or any other state-management provided by the flutter.
    After step 1–3 out main.dart will look something like this.
Locale locale = new Locale(languageCode); //languageCode=ru or esGet.updateLocale(locale);

--

--

I am a Software Engineer @Walmart and instructor @Udemy, working on Blockchain, and Kubernetes. Get in touch: linktr.ee/adityajoshi12

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Aditya Joshi

I am a Software Engineer @Walmart and instructor @Udemy, working on Blockchain, and Kubernetes. Get in touch: linktr.ee/adityajoshi12