2

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!

matti peter
  • 150
  • 10

1 Answers1

10

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':'jhon@example.com'
}));

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,
}));
Ivo
  • 18,659
  • 2
  • 23
  • 35