Does it return the country which has been set in the phone settings?
If yes, is there any chance the user has not set country for his phone and in that case,what does that return ?
[import]uid: 64174 topic_id: 35030 reply_id: 335030[/import]
Does it return the country which has been set in the phone settings?
If yes, is there any chance the user has not set country for his phone and in that case,what does that return ?
[import]uid: 64174 topic_id: 35030 reply_id: 335030[/import]
You can test this API via sample app “Hardware/DeviceInfo” that is included with the Corona SDK.
When I run the above sample app on my Mac, I get “US” for country.
I also get “US” on my Galaxy Nexus device.
Both of the above machines are set up for a USA locale.
The country string is provided by the operating system. In my experience (so far), the returned strings have been consistent and appear to correspond with ISO 3166-1 two character country codes, as documented via the link below. I know for a fact that Android corresponds to this ISO standard, but Apple’s documentation does not specify.
http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
Anyways, it was a very good question. I hope this helps! [import]uid: 32256 topic_id: 35030 reply_id: 139369[/import]
Calling [lua]system.getPreference(“locale”, “language”)[/lua] in Lua was designed to return a language code on all platforms, not a localized language name.
On iOS, it calls NSLocale in Objective-C with constant NSLocaleLanguageCode.
On Android, it calls [java]Locale.getLanguage()[/java] in Java.
http://developer.android.com/reference/java/util/Locale.html#getLanguage()
Now, calling [lua]system.getPreference(“ui”, “language”)[/lua] in Lua is supposed to return a localized language name. The idea is it is something you can display in your UI to the end-user.
If what you are saying is true, then it sounds like Mac and iOS are the ones that are doing it wrong.
I ran our DeviceInfo sample project via our Corona Simulator on Mac and I see that it displays “en” for both ui language and locale language. That’s definitely not correct.
In any case, it sounds like we need to re-review our locale handling code, but it the mean-time, it looks like “locale” “language” is the combination you should use to receive the correct language code on all platforms.
[import]uid: 32256 topic_id: 35030 reply_id: 139398[/import]
Just updated my post above. The previous version wasn’t quite right. [import]uid: 135827 topic_id: 35030 reply_id: 139400[/import]
(note: I edited this post from the previously incorrect version)
This is how we’re doing it. I forget exactly why we needed to use system.getPreference( "ui", "language" ) on iOS, but system.getPreference( "locale", "language" ) wasn’t suitable for us.
local locale;
if system.getInfo( "platformName" ) ~= "Android" then
locale = system.getPreference( "ui", "language" ):upper()
-- split on '-'
else
locale = system.getPreference( "locale", "language" ):upper()
-- split on '\_'
end
Note that some language codes have two parts with a separator (ZH-HANT = Traditional Chinese) . On Android this separator is the _, on iOS the separator will be a -.
Locale will be set to a language code that is consistent between platforms. Japanese will be JA for example. For languages with dialects you will get two part language codes like “ZH-HANS” (iOS), android will be “ZH_HANS”. I recommend testing this out in the Android & iOS XCode Simulator to be sure (Make sure to test languages like Chinese).
This is currently the way we do it on our cross-platform application and our analytics confirm that the application language is getting correctly detected. [import]uid: 135827 topic_id: 35030 reply_id: 139394[/import]
Thanks for the update George. The info about the dash ‘-’ and underscore ‘_’ inconsistency is definitely good to know.
This is also the first time I’ve ever seen a language code contain a dash. Usually the dash is used to separate the language code from the country code. Now I know I can’t assume that. [import]uid: 32256 topic_id: 35030 reply_id: 139402[/import]
Thanks for all the info guys!
So language value might be in different formats, but the country code will always be the same, is that right?
The reason I am asking this is because, we have some ads which are to be shown only for a particular country’s users… hence I wanted to know how reliable this was…
Can you just confirm that it would ALWAYS RETURN some country… Or if it returns a nil or an empty string, please confirm that too…I can load some house ads in that case…
What I do not want is,the function to return some weird value meaning I would not be able to decipher that data, and hence resulting in showing no ads at all… [import]uid: 64174 topic_id: 35030 reply_id: 139410[/import]
I would have to say that I have had some not such great consistent results from this function.
local country = system.getPreference( “locale”, “country” )
With using a phone sitting in Australia I get the code for GB. Whereas I am expecting to get the code for AU naturally.
This is not a problem on all phones. In fact most phones give the expected correct result.
The only thing I could think of was that the phones with the problem were bought online and shipped from overseas.
[import]uid: 28534 topic_id: 35030 reply_id: 139416[/import]
Satheesh,
I’ve never seen this function return an empty/nil string for country code before. The country code string comes from operating system and the iOS/Android documentation does not say that it will return an empty/nil/null string. But that said, you may want to check for nil or empty string just in case and use a default language/locale if that should ever occur. That’s what I’d do. Might be a good idea in case your app is ran on a jail-broken or rooted device. [import]uid: 32256 topic_id: 35030 reply_id: 139425[/import]
You can test this API via sample app “Hardware/DeviceInfo” that is included with the Corona SDK.
When I run the above sample app on my Mac, I get “US” for country.
I also get “US” on my Galaxy Nexus device.
Both of the above machines are set up for a USA locale.
The country string is provided by the operating system. In my experience (so far), the returned strings have been consistent and appear to correspond with ISO 3166-1 two character country codes, as documented via the link below. I know for a fact that Android corresponds to this ISO standard, but Apple’s documentation does not specify.
http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
Anyways, it was a very good question. I hope this helps! [import]uid: 32256 topic_id: 35030 reply_id: 139369[/import]
Calling [lua]system.getPreference(“locale”, “language”)[/lua] in Lua was designed to return a language code on all platforms, not a localized language name.
On iOS, it calls NSLocale in Objective-C with constant NSLocaleLanguageCode.
On Android, it calls [java]Locale.getLanguage()[/java] in Java.
http://developer.android.com/reference/java/util/Locale.html#getLanguage()
Now, calling [lua]system.getPreference(“ui”, “language”)[/lua] in Lua is supposed to return a localized language name. The idea is it is something you can display in your UI to the end-user.
If what you are saying is true, then it sounds like Mac and iOS are the ones that are doing it wrong.
I ran our DeviceInfo sample project via our Corona Simulator on Mac and I see that it displays “en” for both ui language and locale language. That’s definitely not correct.
In any case, it sounds like we need to re-review our locale handling code, but it the mean-time, it looks like “locale” “language” is the combination you should use to receive the correct language code on all platforms.
[import]uid: 32256 topic_id: 35030 reply_id: 139398[/import]
Just updated my post above. The previous version wasn’t quite right. [import]uid: 135827 topic_id: 35030 reply_id: 139400[/import]
(note: I edited this post from the previously incorrect version)
This is how we’re doing it. I forget exactly why we needed to use system.getPreference( "ui", "language" ) on iOS, but system.getPreference( "locale", "language" ) wasn’t suitable for us.
local locale;
if system.getInfo( "platformName" ) ~= "Android" then
locale = system.getPreference( "ui", "language" ):upper()
-- split on '-'
else
locale = system.getPreference( "locale", "language" ):upper()
-- split on '\_'
end
Note that some language codes have two parts with a separator (ZH-HANT = Traditional Chinese) . On Android this separator is the _, on iOS the separator will be a -.
Locale will be set to a language code that is consistent between platforms. Japanese will be JA for example. For languages with dialects you will get two part language codes like “ZH-HANS” (iOS), android will be “ZH_HANS”. I recommend testing this out in the Android & iOS XCode Simulator to be sure (Make sure to test languages like Chinese).
This is currently the way we do it on our cross-platform application and our analytics confirm that the application language is getting correctly detected. [import]uid: 135827 topic_id: 35030 reply_id: 139394[/import]
Thanks for the update George. The info about the dash ‘-’ and underscore ‘_’ inconsistency is definitely good to know.
This is also the first time I’ve ever seen a language code contain a dash. Usually the dash is used to separate the language code from the country code. Now I know I can’t assume that. [import]uid: 32256 topic_id: 35030 reply_id: 139402[/import]
Thanks for all the info guys!
So language value might be in different formats, but the country code will always be the same, is that right?
The reason I am asking this is because, we have some ads which are to be shown only for a particular country’s users… hence I wanted to know how reliable this was…
Can you just confirm that it would ALWAYS RETURN some country… Or if it returns a nil or an empty string, please confirm that too…I can load some house ads in that case…
What I do not want is,the function to return some weird value meaning I would not be able to decipher that data, and hence resulting in showing no ads at all… [import]uid: 64174 topic_id: 35030 reply_id: 139410[/import]
I would have to say that I have had some not such great consistent results from this function.
local country = system.getPreference( “locale”, “country” )
With using a phone sitting in Australia I get the code for GB. Whereas I am expecting to get the code for AU naturally.
This is not a problem on all phones. In fact most phones give the expected correct result.
The only thing I could think of was that the phones with the problem were bought online and shipped from overseas.
[import]uid: 28534 topic_id: 35030 reply_id: 139416[/import]
Satheesh,
I’ve never seen this function return an empty/nil string for country code before. The country code string comes from operating system and the iOS/Android documentation does not say that it will return an empty/nil/null string. But that said, you may want to check for nil or empty string just in case and use a default language/locale if that should ever occur. That’s what I’d do. Might be a good idea in case your app is ran on a jail-broken or rooted device. [import]uid: 32256 topic_id: 35030 reply_id: 139425[/import]