Making every text available in multiple languages?

Title says it all. Already done a game and everything’s working but… only in English. I want to make it available in Portuguese in the same package but dunno how. It is in an alpha channel at Play Store now and one solution could be making different APK to every single language, but is there any easier way?

And sorry for any grammar errors, newbie with English here.

For things like display.newText() or content in native.newTextField() and native.newTextBox()'s. you can use a Lua table to hold multiple values:

local helloTextStrings = {} helloTextStrings["en"] = "Hello" helloTextStrings["es"] = "Hola" helloTextStrings["fr"] = "Bonjour" helloTextStrings["pt-br"] = "Alô" local language = "pt-br" local helloText = display.newText( helloTextStrings[language], ... )

For things like text in graphics, you would need an image for each language and tack the language on the end of the filename:

local object = display.newRect(“image-” … language … “.png”)

You would need:   image-en.png, image-es.png, image-pt-br.png, etc.

Finally for your App’s icon and text on the device’s launcher, that’s pretty difficult on Android. iOS is pretty straight forward.

Rob

And what about widgets? Same way as newText? And Play Store will detect that language variable and change it?

Yes, for strings in widgets it would work the same way.  The play store would does not really control that. The device has the language setting not Google Play.

Rob

But it changes automatically with each device? And thanks!

That is correct. Most developers don’t publish multiple versions of their app in different languages, instead they publish one app that is sensitive to the language on device.

Rob

To be clear, simply defining language as local language = “pt-br” will not do as advertised.

See the example for the functions to get the actual language on the device being used:

[lua]print( system.getPreference( “locale”, “country” ) ) – print the locale country (eg. US)

print( system.getPreference( “locale”, “identifier” ) ) – print the locale language identifier (eg. us_US)

print( system.getPreference( “locale”, “language” ) ) – print the locale language (eg. en)

print( system.getPreference( “ui”, “language” ) ) – print the ui (device) language (eg. en)[/lua]

Good point Michael.  You’re right, he would need to get the device’s language.  I was just demo’ing having a variable with the language string in it.

And we do have a sample app that shows how to do all of this in SampleCode/GettingStarted/HelloWorldLocalized

Rob

Which you can view here: https://github.com/coronalabs/samples-coronasdk/blob/master/GettingStarted/HelloWorldLocalized/main.lua

Thank you very much! Everything is working now.

I’m using code like this:

GAME.NLS = {

TITLE_PLAY = {NL=“Spelen” ,EN=“Play Now”},

TITLE_OPTIONS = {NL=“Opties” ,EN=“Options”},

OPTIONS_SOUNDOPTIONS = {NL=“Geluidsinstellingen” ,EN=“Sound Options”},

OPTIONS_SOUNDEFFECTS = {NL=“Geluidseffecten” ,EN=“Sound Effects”},

OPTIONS_MUSIC = {NL=“Muziek” ,EN=“Music”},

READY = {NL=“Klaar” ,EN=“Ready”},

LEVEL = {NL=“Level” ,EN=“Level”},

STARS = {NL=“Sterren” ,EN=“Stars”},

BUTTON_BACK = {NL=“Terug” ,EN=“Back”},

BUTTON_PLAY = {NL=“Spelen” ,EN=“Play”},

and use this get function the select the text:

function M:getText(id)

    local txt = self.nls[id][self.language]

    if txt ~= nil then

       txt = self.nls[id][“EN”]

   end

   if txt ~= nil then

      libDebug:warn ("getText() Could not find NLS text with id "…id,self)

   end

   return txt

end

For things like display.newText() or content in native.newTextField() and native.newTextBox()'s. you can use a Lua table to hold multiple values:

local helloTextStrings = {} helloTextStrings["en"] = "Hello" helloTextStrings["es"] = "Hola" helloTextStrings["fr"] = "Bonjour" helloTextStrings["pt-br"] = "Alô" local language = "pt-br" local helloText = display.newText( helloTextStrings[language], ... )

For things like text in graphics, you would need an image for each language and tack the language on the end of the filename:

local object = display.newRect(“image-” … language … “.png”)

You would need:   image-en.png, image-es.png, image-pt-br.png, etc.

Finally for your App’s icon and text on the device’s launcher, that’s pretty difficult on Android. iOS is pretty straight forward.

Rob

And what about widgets? Same way as newText? And Play Store will detect that language variable and change it?

Yes, for strings in widgets it would work the same way.  The play store would does not really control that. The device has the language setting not Google Play.

Rob

But it changes automatically with each device? And thanks!

That is correct. Most developers don’t publish multiple versions of their app in different languages, instead they publish one app that is sensitive to the language on device.

Rob

To be clear, simply defining language as local language = “pt-br” will not do as advertised.

See the example for the functions to get the actual language on the device being used:

[lua]print( system.getPreference( “locale”, “country” ) ) – print the locale country (eg. US)

print( system.getPreference( “locale”, “identifier” ) ) – print the locale language identifier (eg. us_US)

print( system.getPreference( “locale”, “language” ) ) – print the locale language (eg. en)

print( system.getPreference( “ui”, “language” ) ) – print the ui (device) language (eg. en)[/lua]

Good point Michael.  You’re right, he would need to get the device’s language.  I was just demo’ing having a variable with the language string in it.

And we do have a sample app that shows how to do all of this in SampleCode/GettingStarted/HelloWorldLocalized

Rob

Which you can view here: https://github.com/coronalabs/samples-coronasdk/blob/master/GettingStarted/HelloWorldLocalized/main.lua

Thank you very much! Everything is working now.