I want to translate my hint text but don't know how.Is there away I can translate this
InternationalPhoneNumberInput(
searchBoxDecoration: InputDecoration(
hintText: 'country_code',)) //how can i translate this in getX
CodePudding user response:
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,
)