Any advances in the SDL locale API?

I found a thread talking about a proposed SDL_PreferredLocales() API, from
2012. Has it been implemented somewhere?

I ask this because I need to get the current locale on both iOS and Android
(for choosing my app strings accordingly), and I couldn’t find support for
it on SDL.

I can do it myself on Cocoa (quite straightforward), but I’ve no clue for
Android with NDK, because if I’m reading the web correctly, the NDK doesn’t
have access to locale info (and, honestly, I’ll never use java, it’s
against my principles).

ardi

As far as I know this hasn’t been implemented.On Thu, Jul 10, 2014 at 5:02 AM, Ardillas del Monte < ardillasdelmonte at gmail.com> wrote:

I found a thread talking about a proposed SDL_PreferredLocales() API, from
2012. Has it been implemented somewhere?

I ask this because I need to get the current locale on both iOS and
Android (for choosing my app strings accordingly), and I couldn’t find
support for it on SDL.

I can do it myself on Cocoa (quite straightforward), but I’ve no clue for
Android with NDK, because if I’m reading the web correctly, the NDK doesn’t
have access to locale info (and, honestly, I’ll never use java, it’s
against my principles).

ardi


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

This stalled out, but it’s still something I’d like to get into SDL. I
actually needed this API for two separate games recently, so I’ll
probably revisit this soon.

–ryan.On 7/10/14, 8:02 AM, Ardillas del Monte wrote:

I found a thread talking about a proposed SDL_PreferredLocales() API,
from 2012. Has it been implemented somewhere?

Hi,

I have some code to obtain the current language for a few
architectures (IOS, Win8, Android).
And it seems to me it works correctly, so I will share it.

This ticket already exist.
https://bugzilla.libsdl.org/show_bug.cgi?id=2131

And I attached my code there …
Cheers,

SylvainOn Mon, Jul 14, 2014 at 3:57 AM, Ryan C. Gordon wrote:

On 7/10/14, 8:02 AM, Ardillas del Monte wrote:

I found a thread talking about a proposed SDL_PreferredLocales() API,
from 2012. Has it been implemented somewhere?

This stalled out, but it’s still something I’d like to get into SDL. I
actually needed this API for two separate games recently, so I’ll probably
revisit this soon.

–ryan.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Sylvain Becker

Thanks a lot, Sylvain.

Btw, regarding Android, I don’t fully understand your code. I suppose you
propose two options, but, are they better than the original code submitted
by Julien?

ardiOn Tue, Jul 15, 2014 at 9:10 PM, Sylvain Becker <sylvain.becker at gmail.com> wrote:

Hi,

I have some code to obtain the current language for a few
architectures (IOS, Win8, Android).
And it seems to me it works correctly, so I will share it.

This ticket already exist.
https://bugzilla.libsdl.org/show_bug.cgi?id=2131

And I attached my code there …
Cheers,

Sylvain

On Mon, Jul 14, 2014 at 3:57 AM, Ryan C. Gordon wrote:

On 7/10/14, 8:02 AM, Ardillas del Monte wrote:

I found a thread talking about a proposed SDL_PreferredLocales() API,
from 2012. Has it been implemented somewhere?

This stalled out, but it’s still something I’d like to get into SDL. I
actually needed this API for two separate games recently, so I’ll
probably
revisit this soon.

–ryan.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Sylvain Becker


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

This is not a patch, only part of code to retrieve to locale on Android/Ios/Win

Don’t put to much attention to the jni part as there are a few macros
not defined, and this is different than what should be done for sdl
code (this should be understandable anyway).

I think this is equivalent to what Julien propose.
Maybe, the Java part is slighly different :

   getContext().getResources().getConfiguration().locale.toString();

and
String lang = new String(Locale.getDefault().getLanguage());
if (Locale.getDefault().getCountry().length() > 0)
{
lang = lang + “_” + Locale.getDefault().getCountry();
}
( The autor of this code is probably Pelya
(https://github.com/pelya/commandergenius/blob/sdl_android/project/java/Settings.java#L604)
)On Wed, Jul 16, 2014 at 2:31 PM, Ardillas del Monte wrote:

Thanks a lot, Sylvain.

Btw, regarding Android, I don’t fully understand your code. I suppose you
propose two options, but, are they better than the original code submitted
by Julien?

ardi

On Tue, Jul 15, 2014 at 9:10 PM, Sylvain Becker <@Sylvain_Becker> wrote:

Hi,

I have some code to obtain the current language for a few
architectures (IOS, Win8, Android).
And it seems to me it works correctly, so I will share it.

This ticket already exist.
https://bugzilla.libsdl.org/show_bug.cgi?id=2131

And I attached my code there …
Cheers,

Sylvain

On Mon, Jul 14, 2014 at 3:57 AM, Ryan C. Gordon wrote:

On 7/10/14, 8:02 AM, Ardillas del Monte wrote:

I found a thread talking about a proposed SDL_PreferredLocales() API,
from 2012. Has it been implemented somewhere?

This stalled out, but it’s still something I’d like to get into SDL. I
actually needed this API for two separate games recently, so I’ll
probably
revisit this soon.

–ryan.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Sylvain Becker


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Sylvain Becker

   getContext().getResources().getConfiguration().locale.toString();

and
String lang = new String(Locale.getDefault().getLanguage());
if (Locale.getDefault().getCountry().length() > 0)
{
lang = lang + “_” + Locale.getDefault().getCountry();
}
( The autor of this code is probably Pelya
(
https://github.com/pelya/commandergenius/blob/sdl_android/project/java/Settings.java#L604
)
)

In my game I did it without having a java bridge in full native code:

const char *get_lang_id()
{
AConfiguration *cfg = AConfiguration_new();
AConfiguration_fromAssetManager(cfg, asset_mgr);

static char language[4];
memset(language, 0, sizeof(language));
AConfiguration_getLanguage(cfg, language);
AConfiguration_delete(cfg);

if (*language) return language;

return NULL;
}

The only thing you need to do this is a pointer to the asset manager.

The values returned in “language” are strings like “it”, “de”, “fr”…

You can get the exact same result on iOS with this:

const char *get_lang_id()
{
NSString * language = [[NSLocale preferredLanguages] objectAtIndex:0];
return [language UTF8String];
}–
Bye,
Gabry

I have updated the Ryan’s patch SDL_PreferredLocales to fit the trunk,
and I also added the parts :

  • Android : with the “AConfiguration” choice, but that may be an error
    because it also requires a JNI to get the assetMgr. so it’s increasing
    the scope of dependencies.
  • WinRT/WindowPhones : code working, but not tested in SDL.
  • some code I was using : to convert a locale to an enum/language. I
    believe this is more convenient to handle translations, but feel free
    to modify it !

https://bugzilla.libsdl.org/show_bug.cgi?id=2131

Cheers,
SylvainOn Thu, Jul 17, 2014 at 4:05 PM, Gabriele Greco <gabriele.greco at darts.it> wrote:

   getContext().getResources().getConfiguration().locale.toString();

and
String lang = new String(Locale.getDefault().getLanguage());
if (Locale.getDefault().getCountry().length() > 0)
{
lang = lang + “_” + Locale.getDefault().getCountry();
}
( The autor of this code is probably Pelya

(https://github.com/pelya/commandergenius/blob/sdl_android/project/java/Settings.java#L604)
)

In my game I did it without having a java bridge in full native code:

const char *get_lang_id()
{
AConfiguration *cfg = AConfiguration_new();
AConfiguration_fromAssetManager(cfg, asset_mgr);

static char language[4];
memset(language, 0, sizeof(language));
AConfiguration_getLanguage(cfg, language);
AConfiguration_delete(cfg);

if (*language) return language;

return NULL;
}

The only thing you need to do this is a pointer to the asset manager.

The values returned in “language” are strings like “it”, “de”, “fr”…

You can get the exact same result on iOS with this:

const char *get_lang_id()
{
NSString * language = [[NSLocale preferredLanguages] objectAtIndex:0];
return [language UTF8String];
}


Bye,
Gabry


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Sylvain Becker

2014-07-25 13:00 GMT-03:00, Sylvain Becker <sylvain.becker at gmail.com>:

  • some code I was using : to convert a locale to an enum/language. I
    believe this is more convenient to handle translations, but feel free
    to modify it !

I believe we have agreed long ago that returning a language string was
better than a language number (especially since it’s likely you’ll end
up using a string anyway). Any comments on this?

Le vendredi, 25 juillet 2014 ? 21:12, Sik the hedgehog a ?crit :

I believe we have agreed long ago that returning a language string was
better than a language number (especially since it’s likely you’ll end
up using a string anyway). Any comments on this?

I agree an enum is useless here, best would be to return BCP 47 language identifiers [1,2], nowadays it is the standard (and precise) way for specifying languages.

Best,

Daniel

[1] http://en.wikipedia.org/wiki/IETF_language_tag
[2] http://www.rfc-editor.org/rfc/bcp/bcp47.txt

Sorry for the confusion, SDL_GetPreferedLocales() is still using
string like the initial code. I refreshed the patch, and added android
/ winrt.
This is an attempt not to see this patch lost for the next 6 months.

In addition, I put some code to convert a locale to an enum. I believe
that essentially the only use-able thing. but feel free to discard /
adapt it.

(as you can guess, I don’t even need this patch myself).On Fri, Jul 25, 2014 at 10:12 PM, Sik the hedgehog <sik.the.hedgehog at gmail.com> wrote:

2014-07-25 13:00 GMT-03:00, Sylvain Becker <@Sylvain_Becker>:

  • some code I was using : to convert a locale to an enum/language. I
    believe this is more convenient to handle translations, but feel free
    to modify it !

I believe we have agreed long ago that returning a language string was
better than a language number (especially since it’s likely you’ll end
up using a string anyway). Any comments on this?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Sylvain Becker

2014-07-25 13:00 GMT-03:00, Sylvain Becker <sylvain.becker at gmail.com>:

I believe we have agreed long ago that returning a language string was
better than a language number (especially since it’s likely you’ll end
up using a string anyway). Any comments on this?

Enums are completely useless for languages, since there are just so many
of them.
In your code you don’t care what the actual language is anyways and just
load the appropriate lang-file.
Plus you would need a recompiled version of SDL every time the set of
"supported" languages changes. This is just ridiculous for a middle-ware
library, that doesn’t even display/handle text.Am 25.07.2014 22:12, schrieb Sik the hedgehog:

This is an attempt not to see this patch lost for the next 6 months.

We’ll likely apply some version of this right after 2.0.4 ships (unless Sam says he wants it for 2.0.4).

–ryan.