Thread: Handling strings in 2 dimensional arrays / multilingual string organisation

  1. #1
    Registered User
    Join Date
    Jan 2015
    Posts
    3

    Handling strings in 2 dimensional arrays / multilingual string organisation

    Hello,

    I have a firmware application that works well where I display simple text messages on an LCD screen. At the moment, the User Interface is only in English and I have the text strings simply declared as follows:
    Code:
    static char msg1[] = "   Welcome   ";
    static char msg2[] = "   Data Read  ";
    //etc...
    I want to add a variable that can set the language dynamically from an external device, and so I thought I could do the following:

    Code:
    #define ENG 0
    #define FRE 1
    #define GER 2
    //...
    
    
    static char msg1[ENG][] = "   Welcome   ";
    static char msg2[ENG][] = "  Data Read  ";
    //...
    static char msg1[FRE][] = "   Bienvenue  ";
    static char msg2[FRE][] = "Données lues ";
    //...
    //etc...
    
    
    char cLang = 0;  //English is default
    
    
    writeLCD(msg1[cLang][]);
    When I try to compile the above I get a compiler error at the "static char msg..." declarations. The error is: "error: array type has incomplete element type"

    Is this method valid, but I have a simple syntax problem with the arrray declarations?
    Or is this method unworkable and I should find a different method? If so, any suggestions?

    Thanks for any help
    Cheers

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    You either need to initialize the arrays when you declare them or use strcpy().

    Something like this perhaps?

    Code:
    #define NUM_LANGUAGES 2
    
    static char *msg1[NUM_LANGUAGES] = {"   Welcome   ", "   Bienvenue  "};
    Jim

  3. #3
    Registered User
    Join Date
    Jan 2015
    Posts
    3

    Thumbs up

    Many thanks Jim, that's got past the compiler error. I'll stick to the method you gave.

  4. #4
    Registered User
    Join Date
    Sep 2014
    Posts
    364
    Are you sure the LCD can display the character 'é'?
    An LCD has mostly his own characterset in a ROM chip.
    Normaly, the 26 standard characters of latin charset in upper and lowercase will work.
    But spezial characters have a value higher then 127.
    It could be that it bring up completly differend characters or graphical symbols.
    Please check the documentation of the hardware, or write a program that send the codes from 128 to 255 on the display to see what it will display.
    Other have classes, we are class

  5. #5
    Registered User
    Join Date
    Jan 2015
    Posts
    3
    Quote Originally Posted by WoodSTokk View Post
    Are you sure the LCD can display the character 'é'?
    An LCD has mostly his own characterset in a ROM chip.
    Normaly, the 26 standard characters of latin charset in upper and lowercase will work.
    But spezial characters have a value higher then 127.
    It could be that it bring up completly differend characters or graphical symbols.
    Please check the documentation of the hardware, or write a program that send the codes from 128 to 255 on the display to see what it will display.
    Yes, they can be displayed as there are several character sets already in the ROM. Also, the LCD module allows custom character sets to be uploaded into its RAM, but I don't think we'll use this. At worst, we could always write in CAPS and avoid the accented characters.

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    I would use the actual character code that the LCD expects instead of putting "é" directly into your source code. eg. "\xe9"

    Non-English characters with cout

    gg

  7. #7
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    555
    I would suggest storing the strings in a separate flat text file. Perhaps one file per language. You can store them sequentially then use IDs to reference each message. Then all you have to do is load the file for the appropriate language set into an array. Then you can reference the messages as usual. This also allows you to change messages without re-compiling your program.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 12-01-2011, 04:00 AM
  2. Multilingual Text Engine
    By Northstar7t in forum C Programming
    Replies: 12
    Last Post: 10-18-2010, 07:40 AM
  3. Two-dimensional arrays with strings
    By Niels_M in forum C Programming
    Replies: 25
    Last Post: 08-02-2010, 04:02 PM
  4. Program Organisation in multiple files
    By hilarius in forum C Programming
    Replies: 2
    Last Post: 11-26-2009, 02:20 PM
  5. Help with multi-dimensional string arrays
    By nsaP in forum C Programming
    Replies: 9
    Last Post: 12-13-2004, 08:17 PM