The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Any advances in the SDL locale API?
Ardillas del Monte
Guest

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
Any advances in the SDL locale API?
Sam Lantinga


Joined: 10 Sep 2009
Posts: 1765
As far as I know this hasn't been implemented.


On Thu, Jul 10, 2014 at 5:02 AM, Ardillas del Monte wrote:
Quote:
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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Any advances in the SDL locale API?
Ryan C. Gordon
Guest

On 7/10/14, 8:02 AM, Ardillas del Monte wrote:
Quote:
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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Any advances in the SDL locale API?
slvn


Joined: 06 Oct 2012
Posts: 88
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:
Quote:
On 7/10/14, 8:02 AM, Ardillas del Monte wrote:
Quote:

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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



--
Sylvain Becker
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Any advances in the SDL locale API?
Ardillas del Monte
Guest

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 wrote:
Quote:
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:
Quote:
On 7/10/14, 8:02 AM, Ardillas del Monte wrote:
Quote:

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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org





--
Sylvain Becker
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Any advances in the SDL locale API?
slvn


Joined: 06 Oct 2012
Posts: 88
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:
Quote:
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
wrote:
Quote:

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:
Quote:
On 7/10/14, 8:02 AM, Ardillas del Monte wrote:
Quote:

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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



--
Sylvain Becker
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org




--
Sylvain Becker
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Any advances in the SDL locale API?
Gabriele Greco
Guest

Quote:

       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
Any advances in the SDL locale API?
slvn


Joined: 06 Oct 2012
Posts: 88
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,
Sylvain

On Thu, Jul 17, 2014 at 4:05 PM, Gabriele Greco wrote:
Quote:

Quote:

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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org




--
Sylvain Becker
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Any advances in the SDL locale API?
Sik


Joined: 26 Nov 2011
Posts: 905
2014-07-25 13:00 GMT-03:00, Sylvain Becker:
Quote:
- 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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Any advances in the SDL locale API?
Daniel Bünzli
Guest

Le vendredi, 25 juillet 2014 à 21:12, Sik the hedgehog a écrit :
Quote:
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


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Any advances in the SDL locale API?
slvn


Joined: 06 Oct 2012
Posts: 88
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
wrote:
Quote:
2014-07-25 13:00 GMT-03:00, Sylvain Becker:
Quote:
- 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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



--
Sylvain Becker
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Any advances in the SDL locale API?
Robotic-Brain
Guest

Am 25.07.2014 22:12, schrieb Sik the hedgehog:
Quote:
2014-07-25 13:00 GMT-03:00, Sylvain Becker:

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.
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Any advances in the SDL locale API?
Ryan C. Gordon
Guest

Quote:
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.
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Re: Any advances in the SDL locale API?
ollika


Joined: 28 Nov 2013
Posts: 18
Ryan C. Gordon wrote:

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


What is the status on this?

Thanks.