Home > Back-end >  how to make Localization with Getx if there is parameter in the text
how to make Localization with Getx if there is parameter in the text

Time:11-17

if the text like this:

           Text(
              'Put something ${widget.profileA} might like'.tr,        
            ),

Here is the code for the translation example:

class Language extends Translations {
  @override
  Map<String, Map<String, String>> get keys => {
        'en_US': {
          'Put something ${widget.profileA} might like': 'some translation', 
        };
      };
}

My question is since there is a parameter ${widget.profileA} in the text, is there a good solution to translate whole sentence with this parameter? thank you!

CodePudding user response:

The documentation of GetX explains well how you can do that here: https://pub.dev/packages/get#internationalization

Using translation with parameters



Map<String, Map<String, String>> get keys => {
    'en_US': {
        'logged_in': 'logged in as @name with email @email',
    },
    'es_ES': {
       'logged_in': 'iniciado sesión como @name con e-mail @email',
    } };

Text('logged_in'.trParams({   
  'name': 'Jhon',
  'email':'[email protected]'
}));

So for your example:

class Language extends Translations {
  @override
  Map<String, Map<String, String>> get keys => {
        'en_US': {
          'Put something @profile might like': 'some translation with @profile', 
        };
      };
}

and then

Text('Put something @profile might like'.trParams({
  'profile': widget.profileA,
}));
  • Related