Forcing a Locale

  1. 6 weeks ago

    Andy B

    Jan 9 Airdrie, AB, Canada

    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.

  2. Norman P

    Jan 9 Pre-Release Testers, Xojo Pro outside listening to the silen...

    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

  3. Andy B

    Jan 9 Airdrie, AB, Canada

    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.

  4. Norman P

    Jan 9 Pre-Release Testers, Xojo Pro outside listening to the silen...
    Edited 6 weeks ago

    no such equivalent in Xojo

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

  5. Andy B

    Jan 9 Airdrie, AB, Canada

    @Norman P no such equivalent in Xojo

    Yikes.

  6. Norman P

    Jan 9 Pre-Release Testers, Xojo Pro outside listening to the silen...
    Edited 6 weeks ago

    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

  7. Andy B

    Jan 9 Airdrie, AB, Canada

    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?

  8. Andy B

    Jan 9 Airdrie, AB, Canada

    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.

  9. Norman P

    Jan 9 Pre-Release Testers, Xojo Pro outside listening to the silen...
    Edited 6 weeks ago

    @Andy B Seems like quite the oversight especially for those testing a multi-locale program...

    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

    @Andy B 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?

    pretty much

    @Andy B 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.

    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 :)

    EDIT : Feedback Case #58797

  10. Andy B

    Jan 9 Airdrie, AB, Canada

    "override that format with a locale" - example?

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

    What's App.RegionCode?

  11. James D

    Jan 9 Pre-Release Testers, Xojo Pro Europe (Switzerland)

    @Andy B 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.

    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.

  12. James D

    Jan 9 Pre-Release Testers, Xojo Pro Europe (Switzerland)

    @Andy B Seems like quite the oversight especially for those testing a multi-locale program...

    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.

  13. Andy B

    Jan 9 Airdrie, AB, Canada

    @James D 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.

    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.

  14. Markus R

    Jan 9 Pre-Release Testers, Xojo Pro Europe / Germany
    Edited 6 weeks ago

    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.

  15. Andy B

    Jan 9 Airdrie, AB, Canada

    @Markus R 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.

    And what is Application.RegionCode?

  16. Markus R

    Jan 9 Pre-Release Testers, Xojo Pro Europe / Germany

    @Andy B 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.
    docs.xojo.com/Application.RegionCode

  17. Emile S

    Jan 9 Europe (France, Strasbourg)

    @Andy B This is what the customer wants, so no point in having a philosophical discussion about it.

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

    The rules are clear.

  18. Markus R

    Jan 9 Pre-Release Testers, Xojo Pro Europe / Germany
    Edited 6 weeks ago

    @Andy B How do I set my application to be in a particular Locale, overriding the user's system default?

    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

    Dim s As String
    s = kHello("fr") // s = "Bonjour"
    s = kHello("en") // s = "Hello"
    s = kHello("en_UK") // s = "Welcome"

  19. 5 weeks ago

    Norman P

    Jan 9 Pre-Release Testers, Xojo Pro outside listening to the silen...

    @Markus R 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.
    docs.xojo.com/Application.RegionCode

    And I cannot find a setting in any inspector field for it

  20. Norman P

    Jan 9 Pre-Release Testers, Xojo Pro outside listening to the silen...

    @Markus R 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.

    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/

  21. Newer ›

or Sign Up to reply!