getting the system's language to do within-app translation.

Hi,

it’s now important to translate your app or game to targeted languages,

but is it possible to do it as following ? …:

let’s say that I have a “play_button.png” that has a “play” written in it in English, and I have another “play_btn2.png” that has a “play” written in it but in any other language for Arabic as an example.

what should I add to my code to make it choose “play_button.png” in English when the system is English, and “play_button2.png” in Arabic for when system is on Arabic ?

Hi @hammod-930,

I would suggest using the “system.getPreference()” function and using one of its provided values within a conditional block to display the proper language. It’s also probably a good idea to have a default (else) option just in case there’s not a match… maybe it could even be a graphical symbol like a “play” button, although that might not be possible for all of the button options you have in the app.

http://docs.coronalabs.com/api/library/system/getPreference.html

Hope this helps,

Brent

Hi Brent,

so should it go like this ?!..:

[lua]if (system.getPreference( “ui”, “English” )) then
–display english btn
elseif (system.getPreference( “ui”, “Arabic” )) then
–display arabic btn
else
–display chinese btn
end[/lua]

Hi @hammod-930,

Yeah, that’s basically the idea, as long as you’re OK with Chinese being the “default”. There’s a small percentage chance that the preference string won’t match exactly the same on every Android device in existence, so you need a reliable fallback case, and that should be what you believe most users will want (your overall target audience).

Brent

Hi @hammod-930,

I would suggest using the “system.getPreference()” function and using one of its provided values within a conditional block to display the proper language. It’s also probably a good idea to have a default (else) option just in case there’s not a match… maybe it could even be a graphical symbol like a “play” button, although that might not be possible for all of the button options you have in the app.

http://docs.coronalabs.com/api/library/system/getPreference.html

Hope this helps,

Brent

Hi Brent,

so should it go like this ?!..:

[lua]if (system.getPreference( “ui”, “English” )) then
–display english btn
elseif (system.getPreference( “ui”, “Arabic” )) then
–display arabic btn
else
–display chinese btn
end[/lua]

Hi @hammod-930,

Yeah, that’s basically the idea, as long as you’re OK with Chinese being the “default”. There’s a small percentage chance that the preference string won’t match exactly the same on every Android device in existence, so you need a reliable fallback case, and that should be what you believe most users will want (your overall target audience).

Brent