Newbie needs help with method to translate text in 3 languages, En, Sp, French

I am a real newbie, I am faced with a problem of trying to present "text" information on a screen to users
in different languages. The three primary languages are: English, Spanish, French.

Example: English = "Welcome"
Spanish = "Bienvenido"
French = "Bienvenue"

I have googled and gaggled but have not found a good example to follow.
In operation a "User" would select a preferred language and then all subsequent text would be presented
in that chosen language.
Need expert help please I am so confused!
Thank you

One approach is to use an integer state variable (e.g. "lang") that takes on values like 1, 2 or 3.

Then use switch/case statements for printing or any other relevant action.

 switch ( lang ) {
  case 1:            // Note the colon, not semicolon
    Serial.println("Welcome");
    break;
  case 2:
    Serial.println ("Bienvenido");
    break;
  case 3:
    Serial.println("Bienvenue");
}

Thanks for the reply guys, I was not clear enough in my posting, I have to continue to display additional
phrases based on user input, such as "We are located in Mare Largo, Mars". Except that the text needs to be in the chosen language.
Am I asking too much ?? Because there is many "textual" phrases that need to be translated!.

I wish, I knew how commercial programs do their translation, but do not have a clue!

All comments suggestions or recommendation to abandon project gladly accepted.

Thank you

You have a two dimensional array of pointers to phrases (in PROGMEM, of course), and a simple byte variable "language" selects which row of the array you take the phrases from.

I really don't see a problem

@AWOL, thank you for the reply, as I stated I am a newbie, and totally confused on the use of arrays and pointers. My vision (I think?) was three arrays one for each language and then a pointer to the message for display. However, I am totally lost on how to pass this information to a TFT Display?
Do I temporarily store the decoded phrase to a variable and pass that variable to the TFT Print function?.

I think this is the area I am getting lost in???

A sample code would be great to help me visualize what it would look like!!

Thanks for the great info

azsuns:
However, I am totally lost on how to pass this information to a TFT Display?

Well, how are you currently passing text to your TFT?

Except that the text needs to be in the chosen language.

See reply #2 for a solution that does not involve arrays and pointers.

jremington, thanks for the feedback. I do believe the switch statement is the simplest for me to tackle.
I am thinking along the area assigning "lang" as suggested and then each text string would have that value as the prefix along with a number for the text string:

code:
switch ( lang ) {
case 1: // Note the colon, not semicolon
Serial.println("Welcome");
break;
case 2:
Serial.println ("Bienvenido");
break;
case 3:
Serial.println("Bienvenue");

case 11:
Serial.println("We are located blah blah");
break;
case 21:
Serial.println("Estamos Spanish");
break;
case 31:
Serial.println("Nous Sommes French");
break ;

and so on with the 1,2 or 3 being the first value to represent the language???

Am I on the right track???

Comments welcomed!

}

Am I on the right track???

If you plan to support 31 (or more) languages, yes. If you only plan to support 3, you need a block of code like was proposed for EACH string you want to print.

That is encouraging, the next question is? Does this method become a memory hog? I plan on using an
Arduino Mega2560.
And I wonder PaulS, if this gives me latitude to add additional languages in the future?

All of this is basically in my "Napkin" paper and not even begun to code anything, a feasibility test.

Thank you all for the valuable input.

More comments & suggestion always welcome.

"Stupid is forever, Ignorance can be fixed", I am ignorant on this matter!

I would be rude not to thank jremington first for the suggestion.
Thanks jremington !!!

case 11:
  Serial.println("We are located blah blah");
  break;
  case 21:
  Serial.println("Estamos   Spanish");
  break;
  case 31:
  Serial.println("Nous Sommes   French");

The above should be 1, 2 and 3, not 11, 21 and 31. And should not #2 should be "Somos de Espana (or) Hablamos espanol"? Likewise for French.

Does this method become a memory hog?

No, but the print statements must be in flash memory or you will run out of RAM. Use the "F" macro to accomplish that, e.g.

Serial.print(F(“Hello World”));

if this gives me latitude to add additional languages in the future?

Yes. For language number 4, set "lang = 4" and so on. Your case statements acquire more entries. Don't forget the essential "break;" statements.

byte ENGLISH = 0, SPANISH=1, FRENCH=2;
byte language = ENGLISH;  // default value; changeable by user
char welcomeMsg[= {"Welcome","Bienvenido", "Bienvenue"};
   :
Serial.println(welcomeMsg[langauge]);

Am I asking too much ?? Because there is many "textual" phrases that need to be translated!.
Does this method become a memory hog?

It certainly becomes a memory hog, depending on your definition of "many." User interfaces in general are hoggy, and you're talking about having 3x the text plus logic to switch between them. A MEGA 2560 might have enough memory, depending on what else you're doing. You'd certainly want to exhance the examples to use flash memory for the texts rather than ram, which gets a little non-trivial when you start talking about arrays of strings :frowning:

I wish, I knew how commercial programs do their translation, but do not have a clue!

There are surely many tutorials. And standard libraries/methods. (the key search words are "localization" and "internationalization.") About Internationalization and Localization for example. But the short answer is that a desktop program has so much memory and other resources that you just let the "localization" effort be as much of a hog as it needs to be. (after all, a typical novel is about 1Mbyte of actual text. A relatively small application like "arduino-builder" (a tiny sub-program of the Arduino IDE) is 3.6MB, and application sizes in excess of several gigabytes are not uncommon.)

As above...
This compiles, but not tested running

#define NUM_LANG 3
#define ENGLISH 0
#define SPANISH 1
#define FRENCH 2

// numbver of phrases must be the same in each row

// names must be LESS than 10 chars
char *lang_names[NUM_LANG][10] = {"ENGLISH", "SPANISH", "FRENCH"};

// phrases must be LESS than 16 chars
char *phrases[NUM_LANG][16] = {"Hello", "Goodbye", "Welcome", "Good Morning",
                               "Hola", "Adios", "Bienvenido", "Buenos d�as",
                               "Bonjour", "Au revoir", "Bienvenue", "Bonjour"
                              };
// ------------------------------------------------------------------
void setup() {
  Serial.begin(115200);

  for (char language_num = 0; language_num <= 2; language_num++) {
    for (char phrase_num = 0; phrase_num <= 3; phrase_num++) {
      Serial.print(phrases[language_num][phrase_num]);
    }
  }
}

// ------------------------------------------------------------------
void loop() {
}
// ------------------------------------------------------------------

The above does compile, however the print out is only for the first 3 phrases. I can only print when
language_num =0 on the first pass of the for/next loop.
I don't see how I can select the language I want and decode the associate phrase I want to print.

Example: Select "FRENCH" and print "BonJour", then select "SPANISH" and print "Hola".

I dont see where I can select 1) the language and 2) the phrase to use???

Sorry I am so new at this and I can't see what may be obvious to experts...

Any changes I make to the above code to select a different language becomes an error.

Sorry - I wasn't really paying too much attention
THIS COMPILES & RUNS CORRECTLY !

#define NUM_LANG 3
#define ENGLISH 0
#define SPANISH 1
#define FRENCH 2
// names must be LESS than 10 chars
char lang_names[NUM_LANG][10] = {"ENGLISH", "SPANISH", "FRENCH"};

#define NUM_PHRASES 4
#define PHRASE_LEN 16
// phrases must be LESS than PHRASE_LEN chars
// number of phrases must be the same in each row
char phrases[NUM_LANG][NUM_PHRASES][PHRASE_LEN] = {
   "Hello", "Goodbye", "Welcome", "Good Morning",  
   "Hola", "Adios", "Bienvenido", "Buenos dias",   
   "Bonjour", "Au revoir", "Bienvenue", "Bonjour" };
// ------------------------------------------------------------------
void setup() {
  Serial.begin(115200);

  for (char language_num = 0; language_num < NUM_LANG; language_num++) {
 Serial.print(F("Language: "));
 Serial.print(lang_names[language_num]);
        Serial.print(F("  "));
    for (char phrase_num = 0; phrase_num < NUM_PHRASES; phrase_num++) {
      Serial.print(phrases[language_num][phrase_num]);
      Serial.print(F(",  "));
    }
    Serial.println();
  }
}

// ------------------------------------------------------------------
void loop() {
}
// ------------------------------------------------------------------

OUTPUT looks like this

Language: ENGLISH Hello, Goodbye, Welcome, Good Morning,
Language: SPANISH Hola, Adios, Bienvenido, Buenos dias,
Language: FRENCH Bonjour, Au revoir, Bienvenue, Bonjour,