×
A new build of Corona SDK is now available to subscribers. Not a subscriber? Subscribe now.
CoronaSDK 2012.821 | Released: 23 May 2012, 2:01am | What's New | Download Now

system.getPreference()

Description:

Returns a preference value as a string.

Syntax:

1
system.getPreference( category, name )

Example:

print( system.getPreference( "locale", "country" ) )  -- print the country

Parameters:

category

Valid values of category are: "ui" and "locale"

name

Valid values of name for "ui" category is: "language"

Valid values of name for "locale" category is: "country", "identifier", and "language".

Returns:

String of parameter requested.

Remarks:
Supported on operating systems and platforms for build numbers shown:
  • Mac OS X:
    Corona SDK 1.0
  • Windows:
    Corona SDK 2.0
  • iOS:
    Corona SDK 1.0
  • Android:
    Corona SDK 2.0

Replies

altcode's picture
altcode
User offline. Last seen 1 day 19 hours ago. Offline
Joined: 9 Jul 2011

Please, add more info about parameters. For example, what values may be returned.

bpappin's picture
bpappin
User offline. Last seen 1 week 8 min ago. Offline
Joined: 19 Jan 2011

Fairly easy to find out yourself:

1
2
3
4
print("ui.language",system.getPreference( "ui", "language" ))
print("locale.country",system.getPreference( "locale", "country" ))
print("locale.identifier",system.getPreference( "locale", "identifier" ))
print("locale.language",system.getPreference( "locale", "language" ))

output:

1
2
3
4
ui.language             en
locale.country          CA
locale.identifier       en_CA
locale.language         en

radim.havrlant
User offline. Last seen 2 weeks 2 days ago. Offline
Joined: 13 Apr 2011

Ok, but what about other languages, locales? I need to prepare an application for potentially many localized resources. I would like to give to a localizator/translator exact locale/language parameter for example for Thailand.

Maybe there could be link to the some ISO standard?

bpappin's picture
bpappin
User offline. Last seen 1 week 8 min ago. Offline
Joined: 19 Jan 2011
radim.havrlant
User offline. Last seen 2 weeks 2 days ago. Offline
Joined: 13 Apr 2011

Actually I already use ISO 639-1. But since this is not mentioned in documentation, I have no guarantee, which result I can get. For example, if you call

1
system.getPreference( "ui", "language" )

on iOS platform, you will get something like "en". If you call it on Android, you will get something like "english". This should be reflected here.

Tom
User offline. Last seen 11 hours 5 min ago. Offline
Staff
Joined: 13 Jul 2010

The information returned by this API is the information received from the OS. For details of what is returned, refer to the OS (iOS or Android) documentation.

dev01
User offline. Last seen 3 hours 8 min ago. Offline
Joined: 20 Oct 2011

is there anybody can help me?

I couldn't get system.getPreference ("ui", "language")..
If I call it on Android, I expect to get something like "english" but "1042" is what I got..
do I need some kind of "android.permission" ?

bsdrago's picture
bsdrago
User offline. Last seen 3 days 17 hours ago. Offline
Joined: 16 Sep 2010

dev01,

system.getPreference ("ui", "language") get a language system generated by the system.

In iOS/Mac, you will receive something like "pt-BR" ou "en".

In Windows (simulator), you will receive something like 1046 or 1042. This is LCID code. Each country has it own code. You can find it here:
http://technet.microsoft.com/en-us/library/dd346950.aspx

In Android, depends: usually, you will receive the language name, as "english" or "português". I wrote "português" in portuguese, because you will receive the language name in portuguese (português), not in english (portuguese).

Sorry about my english.