[Disclaimer: This blog has no intentions to be a definitive opinion on Lua or Corona development. It is just an opinion under the perspective of a non-professional developer, working for the first time with both technologies. If you find anything wrong with the expressed opinions, please feel free to comment and I will revise the text.]

My app must be international. Saying that, I planned to allow it to find which is the current language setup in the device and, enabling the correct idiom according that. I created an “.idi” file for each language I am planning to reach. For example, the english.idi file contains:

line 1: Send Mail

line 2: More Picts

line 3: More Stories

and the list goes on…

Below the code I used to make the selection, according the information coming from the phone:

   1: — Read idiom file according locale

   2: local language = system.getPreference( “ui”, “language” )

   3: local translatedStrings = {}

   4: local function loadIdiom (language)

   5: local path = system.pathForFile(language, system.ResourceDirectory)

   6: local file = io.open(path, “r”)

   7: if file then

   8:    local i = 0

   9:    while true do

  10:      i = i + 1

  11:      local line = file:read(“*l”)

  12:       if line == nil then break end

  13:           — load all strings according idiom

  14:         translatedStrings[i] = line –.. “n”

  15:     end

  16:       print(translatedStrings[1])  –shows first line

  17:   end

  18:   io.close(file)

  19: end

  20:  

  21: if language == “en” then

  22:  loadIdiom(“english.idi”)

  23: elseif language == “pt” then

  24:  loadIdiom(“brazilian.idi”)

  25: else

  26:  loadIdiom(“english.idi”)

  27: end

  28:  

As you can see, I started getting the current language at line 2. Lines 21 to 27 select the correct .idi file and call the function loadIdiom, which reads the correct file and save all lines in a table (array). With this table, I will be able to call the correct string according the number of the line. For example, when I need to refer to string Send Mail, I will use translatedStrings[1], considering the string Send Mail is in the first line of the .idi file.

Hope it helps!

Alex