0

I am using key - value translation-S.of(context).translation_key- but I need something like "Translation string".translate() or translate("Translation string")

How can I do this ?

I am using localizely plugin. Flutter version is lastest.

Attention: I am not asking for translate("key") I am asking translate("Translate String") I want to give a value and get current translation value.

1 Answers1

0

I'd suggest you to do it the other way:

String _localeCode = 'en';

Your method:

String translate(String key) {
  if (_localeCode == 'en') {
    if (key == 'key1') return 'English translation for key1';
    else if (key == 'key2') return 'English translation for key2';
  } else if (_localeCode == 'es') {
    if (key == 'key1') return 'Spanish translation for key1';
    else if (key == 'key2') return 'Spanish translation for key2';
  }
}

And you'd use it:

void main() {
  var translatedString = translate('key1');
}

For simplicity I hardcoded the things, but a better solution is to load the keys through a json file, here's a better approach

iDecode
  • 22,623
  • 19
  • 99
  • 186
  • My company bought the plugin for 1 year. At the moment, I can't go thro json file but I got idea from this. I will something – Oğuzhan Aksoy Oct 08 '20 at 14:48
  • Plus you didn't understand the question. I already have KEY - VALUE translation system. I want to give a Value and get current translation Value For Example: `En => App Title` | `Another Lang => Title App` I will give **App Title** and get **Title App**. – Oğuzhan Aksoy Oct 08 '20 at 15:38