Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make Localization with Getx if there is parameter in the text

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!

like image 975
matti peter Avatar asked Oct 27 '25 05:10

matti peter


1 Answers

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,
}));
like image 119
Ivo Beckers Avatar answered Oct 28 '25 18:10

Ivo Beckers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!