New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flutter How to translate text snippet that comes from backend (api) (i.e. translation as key) #104249
Comments
Can you check if your case is same as #67092 ? |
I don't think the feature request you mentioned is related with mine. Let's say I have the translation json file with { "Hello": "မင်္ဂလာပါ" } I will only display "Hello" in my app in proper way and flutter must handle to show "Hello" text on English language devices and "မင်္ဂလာပါ" on Myanmar (Burmese) language devices and the text "Hello" can also be a static hardcoded text or comes from API. |
OT: Just curious, how is defining keys more painful than using whole sentences as keys? And for translating backend messages. ...
"some_text": "Some text.",
"api_codes": {
"some_error": "Some error.",
"other_error": "Other error.",
"Your non key sentence.": "Your non key sentence."
}
... and tell final translatedText = i18n.someText; //returns already translated string
final translatedApiResponse = i18n.apiCodes[backendResponseCode]; I've once got an old PHP eshop to maintain for a few weeks (never done PHP before) and they wanted to change some strings. Fun times, searching through that ugly code, modifying those hardcoded strings and then also modifying them in translation mappings :) |
Not unless you want more than 2 languages in your app. That's the main reason I want this feature. According to my example, I would only need one .arb file, let's say { "Hello": "မင်္ဂလာပါ" } As you might guess, it shouldn't need to translate from English to English. So, displaying the text But let's say you want to add Spanish to your app and your app would now have 3 languages, English (primary), Burmese and Spanish. Only then, you need another .arb file (e.g, { "Hello": "Hola" } Then in the place of |
I would still hate seeing this anywhere in my codebase: Text('This is your profile. Here you can manage your subscriptions, get in touch with your friends and etc.'); // de.json
"This is your profile. Here you can manage your subscriptions, get in touch with your friends and etc.": "Dies ist Ihr Profil. Hier können Sie Ihre Abonnements verwalten und mit Ihren Freunden und usw. in Verbindung setzen."
// es.json
"This is your profile. Here you can manage your subscriptions, get in touch with your friends and etc.": "Este es tu perfil. Aquí puede administrar sus suscripciones, ponerse en contacto con sus amigos y etc." when I can have it clean like this: Text(i18n.profileDescription); // en.json
"profile_description": "This is your profile. Here you can manage your subscriptions, get in touch with your friends and etc."
// de.json
"profile_description": "Dies ist Ihr Profil. Hier können Sie Ihre Abonnements verwalten und mit Ihren Freunden und usw. in Verbindung setzen."
// es.json
"profile_description": "Este es tu perfil. Aquí puede administrar sus suscripciones, ponerse en contacto con sus amigos y etc." But hey, your code, just my two cents! |
Maybe check this issue which looks a bit similar ? #84326 |
@leoshusar glad you get my point and thank you for your two cents.
|
@darshankawar Thank you for your effort to merge similar issues/feature requests but #84326 isn't even similar to mine. If you need more information, kindly go through all the links I provided in first thread. |
Thanks for the update. I am going ahead and labeling it for further insights from the team. |
I guess, I just wanted to confirm that flutter doesn't support translation string as key. I have followed "Introduction to localizations in Flutter" tutorial and checked out packages like "Easy Localization".
Defining a key for a string in every language is a pain, time consuming and impossible to translate strings that comes from backend api. What I want to achieved is something that is possible in Laravel. Is that possible in Flutter yet?
Thanks in advance!
This question was asked on Stackoverflow a month ago but without any relevant answers.
The text was updated successfully, but these errors were encountered: