0

I want to translate my hint text, but I don't know how. Is there a way I can translate this?

InternationalPhoneNumberInput(
    searchBoxDecoration: InputDecoration(
        hintText: 'country_code',)) // How can I translate this in GetX?
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

2 Answers2

1

First you need to prepare your GetMaterialApp:

GetMaterialApp(
    translationsKeys:AppTranslation.translationsKeys,
    locale: Get.deviceLocale,
    fallbackLocale: Locale("en" , "US").
    title: "Application"
    initialRoute: Routes.HOME,
    defaultTransition: Transition.fade,
    onGenerateRoute:RouteGenerator.generateRoute,)

Then create a AppTranslation.dart:

//AppTranslation.dart
abstract class AppTranslation {
  static Map<String, Map<String, String>> translationsKeys = {
    "en_US": enUS,
    "fr": fr
  };
}

final Map<String, String> enUS = {
  'greeting': 'Hello, How are you?',
  'day': "Awesome day..."
};

final Map<String, String> fr = {
  'greeting': "Salut comment allez-vous?",
  'day': "Super journée..."
};

To change the locale:

Locale locale = new Locale(languageCode); //languageCode=en_US or fr
Get.updateLocale(locale);

And you can call translation text like that:

Text(
    'greeting'.tr,
)
Maikzen
  • 1,504
  • 2
  • 6
  • 18
-1
hintText: ("greeting".tr).toString()
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103