Correct Current NSLocale on Android

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Correct Current NSLocale on Android

Stefan Pauwels
Hi

I am initializing GNUstep on Android as advised in the tools-android README, i.e. I am calling
[NSUserDefaults setUserLanguages:]
which seems to work for just setting the language, but when I try to rely on the currentLocale (for other information like region, metric system usage, etc.) I always get „en_US_POSIX“ as the locale.

Is there a way to manually init the locale correctly?

Best Regards
Stefan
Reply | Threaded
Open this post in threaded view
|

Re: Correct Current NSLocale on Android

Wolfgang Lux
Hi Stefan

> Am 16.09.2020 um 12:23 schrieb Stefan Pauwels <[hidden email]>:
>
> Hi
>
> I am initializing GNUstep on Android as advised in the tools-android README, i.e. I am calling
> [NSUserDefaults setUserLanguages:]
> which seems to work for just setting the language, but when I try to rely on the currentLocale (for other information like region, metric system usage, etc.) I always get „en_US_POSIX“ as the locale.
>
> Is there a way to manually init the locale correctly?

The user’s current locale is initialized from the user defaults. This should normally be modified by the defaults tool from the command line or by the SystemPreferences application.
To override that programmatically in your own application set the "Locale" default in the standard user defaults. You may also need to use autoupdatingCurrentLocale to see the effect of the change.

Wolfgang
Reply | Threaded
Open this post in threaded view
|

Re: Correct Current NSLocale on Android

Stefan Bidigaray
In reply to this post by Stefan Pauwels
On Wed, Sep 16, 2020, 05:23 Stefan Pauwels <[hidden email]> wrote:
Hi

I am initializing GNUstep on Android as advised in the tools-android README, i.e. I am calling
[NSUserDefaults setUserLanguages:]
which seems to work for just setting the language, but when I try to rely on the currentLocale (for other information like region, metric system usage, etc.) I always get „en_US_POSIX“ as the locale.

Is there a way to manually init the locale correctly?

Best Regards
Stefan

Hi Stefan,
The locale is set at the operating system or user level, either by using the $LANG shell variable (returned by +systemLocale) or Locale default (returned by +currentLocale).

It's been a long time since I wrote this code, but if I still remember correctly NSLocale falls back to whatever is specified in $LANG if the Locale default is unset. If $LANG is also unset, then it falls back to en_US_POSIX.

You could also also create your own NSLocale using +localeWithLocaleIdentifier:. This will not interfere with the system or current locales.

Stefan
Reply | Threaded
Open this post in threaded view
|

Re: Correct Current NSLocale on Android

Stefan Pauwels
In reply to this post by Wolfgang Lux
But how? Even if I do this:
[[NSUserDefaults standardUserDefaults] setObject:@"de_CH" forKey:@"Locale"];
I will always get „en_US_POSIX“ for
NSLog(@"Current Locale: %@", [NSLocale currentLocale]);


Am 16.09.2020 um 14:59 schrieb Wolfgang Lux <[hidden email]>:

Hi Stefan

Am 16.09.2020 um 12:23 schrieb Stefan Pauwels <[hidden email]>:

Hi

I am initializing GNUstep on Android as advised in the tools-android README, i.e. I am calling
[NSUserDefaults setUserLanguages:]
which seems to work for just setting the language, but when I try to rely on the currentLocale (for other information like region, metric system usage, etc.) I always get „en_US_POSIX“ as the locale.

Is there a way to manually init the locale correctly?

The user’s current locale is initialized from the user defaults. This should normally be modified by the defaults tool from the command line or by the SystemPreferences application.
To override that programmatically in your own application set the "Locale" default in the standard user defaults. You may also need to use autoupdatingCurrentLocale to see the effect of the change.

Wolfgang

Reply | Threaded
Open this post in threaded view
|

Re: Correct Current NSLocale on Android

Frederik Seiffert
Hi Stefan,

Can you try using -[NSLocale autoupdatingCurrentLocale] as suggested by Wolfgang?

I think currentLocale gets initialized once doesn’t change when updating the user default value.

Frederik


Am 16.09.2020 um 17:37 schrieb Stefan Pauwels <[hidden email]>:

But how? Even if I do this:
[[NSUserDefaults standardUserDefaults] setObject:@"de_CH" forKey:@"Locale"];
I will always get „en_US_POSIX“ for
NSLog(@"Current Locale: %@", [NSLocale currentLocale]);


Am 16.09.2020 um 14:59 schrieb Wolfgang Lux <[hidden email]>:

Hi Stefan

Am 16.09.2020 um 12:23 schrieb Stefan Pauwels <[hidden email]>:

Hi

I am initializing GNUstep on Android as advised in the tools-android README, i.e. I am calling
[NSUserDefaults setUserLanguages:]
which seems to work for just setting the language, but when I try to rely on the currentLocale (for other information like region, metric system usage, etc.) I always get „en_US_POSIX“ as the locale.

Is there a way to manually init the locale correctly?

The user’s current locale is initialized from the user defaults. This should normally be modified by the defaults tool from the command line or by the SystemPreferences application.
To override that programmatically in your own application set the "Locale" default in the standard user defaults. You may also need to use autoupdatingCurrentLocale to see the effect of the change.

Wolfgang


Reply | Threaded
Open this post in threaded view
|

Re: Correct Current NSLocale on Android

Stefan Pauwels
OK, -[NSLocale autoupdatingCurrentLocale] works, but only if I
[[NSUserDefaults standardUserDefaults] setObject:whateverCode forKey:@"Locale"]

So, firstly: Thanks a lot, this solves my problem!
But secondly I think for setting up GNUstep on Android it’s not enough to just [NSUserDefaults setUserLanguages:] as mentioned in https://github.com/gnustep/tools-android#status-and-known-issues and the sample app.

Stefan

Am 17.09.2020 um 10:41 schrieb Frederik Seiffert <[hidden email]>:

Hi Stefan,

Can you try using -[NSLocale autoupdatingCurrentLocale] as suggested by Wolfgang?

I think currentLocale gets initialized once doesn’t change when updating the user default value.

Frederik


Am 16.09.2020 um 17:37 schrieb Stefan Pauwels <[hidden email]>:

But how? Even if I do this:
[[NSUserDefaults standardUserDefaults] setObject:@"de_CH" forKey:@"Locale"];
I will always get „en_US_POSIX“ for
NSLog(@"Current Locale: %@", [NSLocale currentLocale]);


Am 16.09.2020 um 14:59 schrieb Wolfgang Lux <[hidden email]>:

Hi Stefan

Am 16.09.2020 um 12:23 schrieb Stefan Pauwels <[hidden email]>:

Hi

I am initializing GNUstep on Android as advised in the tools-android README, i.e. I am calling
[NSUserDefaults setUserLanguages:]
which seems to work for just setting the language, but when I try to rely on the currentLocale (for other information like region, metric system usage, etc.) I always get „en_US_POSIX“ as the locale.

Is there a way to manually init the locale correctly?

The user’s current locale is initialized from the user defaults. This should normally be modified by the defaults tool from the command line or by the SystemPreferences application.
To override that programmatically in your own application set the "Locale" default in the standard user defaults. You may also need to use autoupdatingCurrentLocale to see the effect of the change.

Wolfgang



Reply | Threaded
Open this post in threaded view
|

Re: Correct Current NSLocale on Android

Frederik Seiffert
Sounds good! I’ve added the following info to the list of known issues:

  • GNUstep Base will also currently not return the system locale as the current NSLocale on Android (the current locale will always default to en_US_POSIX). As a workaround, the app can manually set the system’s locale identifier for the key "Locale" in NSUserDefaults, and use -[NSLocale autoupdatingCurrentLocale] to retreive the locale.
Frederik


Am 18.09.2020 um 10:44 schrieb Stefan Pauwels <[hidden email]>:

OK, -[NSLocale autoupdatingCurrentLocale] works, but only if I
[[NSUserDefaults standardUserDefaults] setObject:whateverCode forKey:@"Locale"]

So, firstly: Thanks a lot, this solves my problem!
But secondly I think for setting up GNUstep on Android it’s not enough to just [NSUserDefaults setUserLanguages:] as mentioned in https://github.com/gnustep/tools-android#status-and-known-issues and the sample app.

Stefan

Am 17.09.2020 um 10:41 schrieb Frederik Seiffert <[hidden email]>:

Hi Stefan,

Can you try using -[NSLocale autoupdatingCurrentLocale] as suggested by Wolfgang?

I think currentLocale gets initialized once doesn’t change when updating the user default value.

Frederik


Am 16.09.2020 um 17:37 schrieb Stefan Pauwels <[hidden email]>:

But how? Even if I do this:
[[NSUserDefaults standardUserDefaults] setObject:@"de_CH" forKey:@"Locale"];
I will always get „en_US_POSIX“ for
NSLog(@"Current Locale: %@", [NSLocale currentLocale]);


Am 16.09.2020 um 14:59 schrieb Wolfgang Lux <[hidden email]>:

Hi Stefan

Am 16.09.2020 um 12:23 schrieb Stefan Pauwels <[hidden email]>:

Hi

I am initializing GNUstep on Android as advised in the tools-android README, i.e. I am calling
[NSUserDefaults setUserLanguages:]
which seems to work for just setting the language, but when I try to rely on the currentLocale (for other information like region, metric system usage, etc.) I always get „en_US_POSIX“ as the locale.

Is there a way to manually init the locale correctly?

The user’s current locale is initialized from the user defaults. This should normally be modified by the defaults tool from the command line or by the SystemPreferences application.
To override that programmatically in your own application set the "Locale" default in the standard user defaults. You may also need to use autoupdatingCurrentLocale to see the effect of the change.

Wolfgang