How to set automatically translation for all words, when click to the "switch language" buttons?

Hello everyone! Im going to do switch language automatically.

I created app variables like there Multi Lingual app - #6 by Tomi_Laakso .

Also i connected formula to title as in that link (LOOKUP…)

So, my questions are:

1) How to set automatically translation for all words, when click to the "switch language" button?

2) Do i need to create translations for all words in my app to app variables ? 

Hi!

  1. As for your object translations, I would add a separate app variable currentLanguage, a text type that can be set to ru or kz. When you click on a language option, you set the app variable to that value, ru or kz, and then use that to LOOKUP the correct language, like the formula in the original question thread you posted:
    LOOKUP(translations.hello_world, appVars.currentLanguage) .Then, when the language is switched, all words should switch too according to appVars.currentLanguage

  2. Unfortunately yes, you have to manually create the translations and add them to the app variable translations, identical to how that hello_world was done. However each word doesn’t have to be separately, you can use phrases:

translations: {
  first_page_title: {
    en: "This is my first page title",
    ru: "...",
    kz: "..."
  }
  first_page_subtitle: {
    en: "This is my first page subtitle",
    ru: "...",
    kz: "..."
  }
}

and so on!

Hi! Thank you for your answer! I didn’t understand a little bit.

I created app variable “currentLanguage” with variable value type “text”.

Then i set my “Language setting components” like this:

And there for each component i set these formulas:

But it is not working… Maybe i did not do correctly? Could you help, please?

Hi,

When the user chooses a language, the currentLanguage variable is set as “ru” or “kz”, you seem to be setting it as something else starting with LOOKUP(..). This variable only tracks what language is chosen, not anything else. This is the only place where you set the variable value.

Then anywhere where you use text, you use the formula LOOKUP(translations.hello_world, appVars.currentLanguage) , where the translations.___ depends on what text should be displayed in that component. Here’s a bit from that original question thread:

And then you would have an appVars.currentLanguage that resolves to e.g. en or de based on user choice, and everywhere you use a string text you would have formula such as

LOOKUP(translations.hello_world, appVars.currentLanguage)

which would then resolve to e.g. “Hello World!” or “Hallo Welt!” depending on appVars.currentLanguage .

so no need for .kz or .ru in the LOOKUP formula.

It is working! I got it! Thank yoou!!! :smiling_face_with_three_hearts:

1 Like

I have one more question… In my application I have the list from the database. So, in this case i need to have in my database translations of this list? And can i connect them also?

So you want to translate the data in your database? Then you’d have to have the translations in the database with the same structure as the translations object for the LOOKUP() to work. If possible, you can have separate databases, one in ru and one in kz, and depending on the language choice you get the database with the correct language.

okay, i got it! thank you!!!

1 Like