Forcing a Locale

How do I set my application to be in a particular Locale, overriding the user’s system default?
This is a single-locale program that needs to not change locales when used in other countries.

Seems like Xojo.Core.Locale.Current is read-only.

it is

basically you could, at app startup, create whatever locale you need from its identifier and then everywhere a locale is used just refer to that global

but you sure you want this ?
that means numbers wont show up properly localized, time may be set to the wrong locale and show as offset by however many hours etc etc

I don’t want this, but my customer does.

In VS, There’s a global setting. Makes it really easy to test your application without changing your computer’s locale.

Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

That’s what I’m looking for.

no such equivalent in Xojo

trying to write VS code in Xojo wont work well and will make you upset :slight_smile:

Yikes.

No yikes
Just Xojo’s framework doesnt let you override the default runtime locale in the same way
But most API’s that you might need a locale for (date format, time format, number format) accept one

Seems like quite the oversight especially for those testing a multi-locale program…

Ok, well, I guess I have to start editing all the formats then. What things does Xojo change “on it’s own”? I assume just anything with a mask or format?

How would I go about setting a Locale in a text field’s format method?

TextField.Format = “#.00”

I see you’ve written some blogs on the subject, I’m just having trouble figuring out what needs to be “set” and how to set it in my code. There’s no text changes needed, just formatting of numbers in textfields and listbox cells.

[quote=470778:@Andy Broughton]Seems like quite the oversight especially for those testing a multi-locale program…
[/quote]
Since the framework has evolved over the last 20+ years I’m not surprised.
If there was a “App.DefaultLocale” or something like (Runtime.DefaultLocale maybe ?) that we could assume would be set at app startup OR we could set it ourselves that would suffice (I swear I put in feature request for something like this once upon a time )
But there’s a lot of other mechanics to make this work since things like textfields and other controls that have built in mechanisms for masking would need to be updated to look at that locale for how they should operate and not just fetch it from the OS on their own

pretty much

[quote=470784:@Andy Broughton]How would I go about setting a Locale in a text field’s format method?
TextField.Format = “#.00”
I see you’ve written some blogs on the subject, I’m just having trouble figuring out what needs to be “set” and how to set it in my code. There’s no text changes needed, just formatting of numbers in textfields and listbox cells.[/quote]

You may not be able to override that format with a locale - its not parameterized at all - so it gets it from the system
If its JUST for output you could use the format function (or whatever its new equivalent is and provide a locale)
If you have to accept input it gets more fun :slight_smile:

EDIT : <https://xojo.com/issue/58797>

“override that format with a locale” - example?

I do accept input, but it would be in NA locale.

What’s App.RegionCode?

[quote=470773:@Andy Broughton]I don’t want this, but my customer does.

In VS, There’s a global setting. Makes it really easy to test your application without changing your computer’s locale.

Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

That’s what I’m looking for.[/quote]

If that is what you were doing, then you misunderstood what InvariantCulture does… it simply makes something parsable nothing more regardless of the locale. The value returned could be complete garbage, but at least you won’t get a parse error.

You can’t test a an application the must support multiple locales in .Net by using invariantCulture. I spent 20 years writing this kind of software in .Net and the only way you can be sure it will work is to respect the local locale and test it. And you should do the same with XOJO.

Well, I could have used North America as the Culture, but Invariant worked, so that’s what I went with. I don’t doubt that I misunderstood it, but when under a time crunch, you do what works.

Anyway, back to the real problem: “How do I modify my program so it ignores the locale and uses North American standards everywhere”
This is what the customer wants, so no point in having a philosophical discussion about it.

what is the meaning of build settings at shared build language?
i remember i had test my app in english and german but now/today it did not change the ui language at runtime.

[quote=470802:@Markus Rauch]what is the meaning of build settings at shared build language?
i remember i had test my app in english and german but now it did not change the ui language at runtime.[/quote]

And what is Application.RegionCode?

i don’t know but the docu wrote:
This Application property can only be set in the Inspector and is not available in code.
The Region Code of the application, corresponding to the version information.
Not supported on Windows. This property can be set only in the IDE.
documentation.xojo.com/api/deprecated/application.html#application-regioncode

So, do not put your name in it (if you do that as is).

The rules are clear.

i agree it should be possible that the app set the ui language by selection.

i made some test, if the constant is not localized (this switch) then the language at build settings is used.
for build and debug the exe at runtime it show the language you selected in the combobox at build.
but that means the app did not care the user account language.
if you have a german and english user u end up in 2 exe.

or this is possible

[quote]Dim s As String
s = kHello(“fr”) // s = “Bonjour”
s = kHello(“en”) // s = “Hello”
s = kHello(“en_UK”) // s = “Welcome”[/quote]

[quote=470806:@Markus Rauch]i don’t know but the docu wrote:
This Application property can only be set in the Inspector and is not available in code.
The Region Code of the application, corresponding to the version information.
Not supported on Windows. This property can be set only in the IDE.
documentation.xojo.com/api/deprecated/application.html#application-regioncode[/quote]
And I cannot find a setting in any inspector field for it

[quote=470802:@Markus Rauch]what is the meaning of build settings at shared build language?
i remember i had test my app in english and german but now/today it did not change the ui language at runtime.[/quote]
The language is NOT a locale - just a language
Basically its the language the app was built in and it the very last fallback to use when trying to look up localized strings
Say you have an app with localized strings in French, German, and Italian
But you built it using English as the default
Then any default values in localized strings are “English” (regarldess of what you actually put in there)
see https://blog.xojo.com/2013/12/17/how-os-x-chooses-a-language/