Multilingual application (without locales or internationalisation)

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Virja
In need of some credit
In need of some credit
Posts: 9
Joined: Fri Jun 07, 2019 8:45 pm
Location: I am Virchanza.
Contact:

Multilingual application (without locales or internationalisation)

Post by Virja » Thu Feb 06, 2020 4:06 pm

I have started making my Dynamo network analysis application multilingual. I have replaced all occurrences of "wxT" with "_". The application is written in English, and I have used POEdit to make German and Irish translations. This is working fine, except for when I switch language I get a message box saying:

Code: Select all

locale 'de_DE' cannot be set.
Even though I get this message, my program still changes language and it works just fine.

I want to make my application multilingual without getting caught up in the ideas of "locales" and "internationisation". I don't want my application to try to interact with the "system locale" in any way.

With regard to multi-lingualism, I only want my application to load a "*.mo" or "*.po" file of my choice, (for example de.mo for German, or ga.mo for Irish), and then to use the text from that file. I don't want any fancy stuff in the background. I don't want it trying to set the system local or anything like that.

I do realise that if I don't change locale, then if I use "wxMessageBox", it might have the wrong language for the OK button. To get around this I'll just make my own message boxes instead of using the built-in function "wxMessageBox".

Is it possible to minimalise the behaviour of wxLocale so that all it does it load a "*.mo" file to use with "gettext" ? Or do I need to code this myself?
This account was temporarily used by "Virchanza" for a few days in Spring 2020 after a 9-year absence from the forum.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2572
Joined: Sun Jan 03, 2010 5:45 pm

Re: Multilingual application (without locales or internationalisation)

Post by PB » Thu Feb 06, 2020 5:00 pm

I once had a similar idea, i.e., just allow the user to select the language of the UI, without affecting the application locale.

I wrote something like this, seemed to work on MSW

Code: Select all

bool MyApp::OnInit()
{
    ...
    wxLanguage lng = ...;
    wxTranslations* translations = new wxTranslations();

    translations->SetLanguage(lng);
    translations->AddStdCatalog();
    translations->AddCatalog("MyApp");
    wxTranslations::Set(translations);

    return true;
}
However, in the end I decided to stick to using wxLocale. Not only as you said the language of texts presented by the OS may not match the language of the application. More importantly, when you need to present some values to the user, it can get pretty confusing as they can be formatted using different language rules (ruled by the locale) than the language the user sees the text in. E.g., "100,123" (100 thousands and 123...) in English could be interpreted as "100.123" (one hundred point 123) in German. Similarly with dates, e.g. different order of month and day in the date.

I do not even remember why I wanted to avoid using wxLocale in the first place.

BTW, using wxLocale certainly does not affect the system (OS) locale.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4425
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Multilingual application (without locales or internationalisation)

Post by ONEEYEMAN » Thu Feb 06, 2020 6:37 pm

Hi,
Also, please remember that on *nix you will need to install the appropriate locales.
And on OSX - it is not recommended to switch to a different language at all.

So every system is different.

Thank you.

Virja
In need of some credit
In need of some credit
Posts: 9
Joined: Fri Jun 07, 2019 8:45 pm
Location: I am Virchanza.
Contact:

Re: Multilingual application (without locales or internationalisation)

Post by Virja » Fri Feb 07, 2020 10:37 am

PB wrote:
Thu Feb 06, 2020 5:00 pm
I once had a similar idea, i.e., just allow the user to select the language of the UI, without affecting the application locale.

I wrote something like this, seemed to work on MSW

I'm trying to get this working. I'm using my own user-defined language identifiers, like so:
English = wxLANGUAGE_USER_DEFINED + 1
German = wxLANGUAGE_USER_DEFINED + 2
Irish = wxLANGUAGE_USER_DEFINED + 3

Here's the code I run before I load the GUI:
wxFileTranslationsLoader::AddCatalogLookupPathPrefix(wxT("/opt/my_cool_program/langs"));
wxTranslations *const p = new wxTranslations;
p->SetLanguage( static_cast<wxLanguage>(wxLANGUAGE_USER_DEFINED + 2) );
p->AddCatalog("de");
wxTranslations::Set(p);
This code seems to succesfully load the German translation file but the GUI remains in English.

Any ideas?
This account was temporarily used by "Virchanza" for a few days in Spring 2020 after a 9-year absence from the forum.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2572
Joined: Sun Jan 03, 2010 5:45 pm

Re: Multilingual application (without locales or internationalisation)

Post by PB » Fri Feb 07, 2020 12:38 pm

Virja wrote:
Fri Feb 07, 2020 10:37 am
I'm trying to get this working. I'm using my own user-defined language identifiers, like so:
English = wxLANGUAGE_USER_DEFINED + 1
German = wxLANGUAGE_USER_DEFINED + 2
Irish = wxLANGUAGE_USER_DEFINED + 3
Why would you do that instead of using the predefined constants? How do you expect wxWidgets to match your custom language id to the folder name of the message catalog for that language?

Anyway, if you are debugging this, I would recommend calling before initializing translation stuff

Code: Select all

wxLog::AddTraceMask("i18n");
and observe the output in the debug log target (in MSVS it is output in the Output/Debug window). You will see detailed information on what is going on with catalog loading as well as when a translated string is not found by _().

Virja
In need of some credit
In need of some credit
Posts: 9
Joined: Fri Jun 07, 2019 8:45 pm
Location: I am Virchanza.
Contact:

Re: Multilingual application (without locales or internationalisation)

Post by Virja » Fri Feb 07, 2020 12:56 pm

PB wrote:
Fri Feb 07, 2020 12:38 pm

Code: Select all

wxLog::AddTraceMask("i18n");
Thanks, I was able to get it working by looking at the output from AddTraceMask.

This is where I had my MO files located:

Code: Select all

./langs/en/en.mo
./langs/de/de.mo
./langs/ga/ga.mo
In order to get this to work, I had to move these files to:

Code: Select all

./langs/en/en.mo
./langs/en/de.mo
./langs/en/ga.mo
This works fine for now but obviously it's not the proper way to do it.

Here's the output from AddTracemask:

Code: Select all

 looking for available translations of "ga" in search path:
     /opt/gitdir/dynamo/langs
     /usr/local/share/dynamo
     /usr/local/share/locale
     /usr/share/locale
 found en translation of "ga" in /opt/gitdir/dynamo/langs/en
 choosing best language for domain 'ga'
  - available translations: [en,en_US,en]
  - obtained best language from locale: en_GB
  => using language 'en_GB'
 adding 'en_GB' translation for domain 'ga' (msgid language 'en_US'
 looking for "ga.mo" in search path:
     /opt/gitdir/dynamo/langs/en_GB.UTF-8/LC_MESSAGES
     /opt/gitdir/dynamo/langs/en_GB.UTF-8
     
     /usr/local/share/dynamo/en_GB.UTF-8/LC_MESSAGES
     /usr/local/share/dynamo/en_GB.UTF-8
     
     /usr/local/share/locale/en_GB.UTF-8/LC_MESSAGES
     /usr/local/share/locale/en_GB.UTF-8
     
     /usr/share/locale/en_GB.UTF-8/LC_MESSAGES
     /usr/share/locale/en_GB.UTF-8
     
 looking for "ga.mo" in search path:
     /opt/gitdir/dynamo/langs/en_GB/LC_MESSAGES
     /opt/gitdir/dynamo/langs/en_GB
     
     /usr/local/share/dynamo/en_GB/LC_MESSAGES
     /usr/local/share/dynamo/en_GB
     
     /usr/local/share/locale/en_GB/LC_MESSAGES
     /usr/local/share/locale/en_GB
     
     /usr/share/locale/en_GB/LC_MESSAGES
     /usr/share/locale/en_GB
     
 looking for "ga.mo" in search path:
     /opt/gitdir/dynamo/langs/en/LC_MESSAGES
     /opt/gitdir/dynamo/langs/en
     
     /usr/local/share/dynamo/en/LC_MESSAGES
     /usr/local/share/dynamo/en
     
     /usr/local/share/locale/en/LC_MESSAGES
     /usr/local/share/locale/en
     
     /usr/share/locale/en/LC_MESSAGES
     /usr/share/locale/en
     
 Using catalog "/opt/gitdir/dynamo/langs/en/ga.mo".
It seems that I'm using the name of the laguage, e.g. "ga", instead of the name of my application, i.e. "dynamo".

What I really really really want to do is just specify the path of an MO file, for example "/tmp/ga.mo" and to get rid of all that system stuff like "/usr/share/locale".

By the way, it looks like my application knows that I've written it in English... or maybe it's just reading the system locale as "en" and that's why it's looking in the folder "./langs/en". Again I don't want any of this stuff, I just want to specify a path to a catalogue file to load.
This account was temporarily used by "Virchanza" for a few days in Spring 2020 after a 9-year absence from the forum.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2572
Joined: Sun Jan 03, 2010 5:45 pm

Re: Multilingual application (without locales or internationalisation)

Post by PB » Fri Feb 07, 2020 1:02 pm

Virja wrote:
Fri Feb 07, 2020 12:56 pm
What I really really really want to do is just specify the path of an MO file, for example "/tmp/ga.mo" and to get rid of all that system stuff like "/usr/share/locale".
Why? There must be a reason why it is done like this. Also, you will need to add at least the standard catalog as well, which contains all wxWidgets texts translated.

But if you still want to go against the grain, my guess is you need to write and use a custom wxTranslationsLoader, probably derived from / based on wxFileTranslationsLoader.

I also know nothing about Linux, so ...

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4425
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Multilingual application (without locales or internationalisation)

Post by ONEEYEMAN » Fri Feb 07, 2020 3:12 pm

Hi,
What is the purpose of dropping the locale support?
Remember people in Germany would be very surprised when they will see a word translated in Austrian and vice versa.
On top of that - how you will handle locale difference in the number representation - "." vs "," and difference in date representation - "01/01/2020" vs "01 January 2020" vs whatever else will be used by that country.

People will be very surprised when they see all the strings translated, but not the stuf I mentioned above. Because those will be based on the system locale (which not always the same as the user preferred one).

Thank you.

To give you an example - I am from Ukraine living in US. For me it is very weird to see the date written as "mm/dd/YYYY", because I'm used to " dd/MM/YYY". So if I would get yo software the very first question I'd ask is - why your application is half-baked. Why I see translated text but not an appropriate date format? Then I'd file a high-priority bug against it and wil wait for the fix deleting it in the meantime.
But that's just me. ;-)

Virchanza
Experienced Solver
Experienced Solver
Posts: 78
Joined: Sun Jul 19, 2009 6:12 am

Re: Multilingual application (without locales or internationalisation)

Post by Virchanza » Fri Feb 07, 2020 3:22 pm

There isn't anything locale-dependent in my Dynamo application. It is a network analysis tool.

IP addresses are shown in dotted decimal notation everywhere in the world.

MAC addresses are shown in "hexbyte colon hexbyte colon hexbyte colon" formation everywhere in the world.

If my application needed locale support then I'd look into it. It doesn't and so I want to get rid of all that extra stuff because it can create problems.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2572
Joined: Sun Jan 03, 2010 5:45 pm

Re: Multilingual application (without locales or internationalisation)

Post by PB » Fri Feb 07, 2020 3:33 pm

Virchanza wrote:
Fri Feb 07, 2020 3:22 pm
If my application needed locale support then I'd look into it. It doesn't and so I want to get rid of all that extra stuff because it can create problems.
Just curious, what problems could using a correct locale create? I cannot think of any...

I do not know what your application does, but at least in some network analysis ones, using locale can be useful. For example, I prefer to see large numbers (e.g., the number of bytes/packets transferred) presented using the thousand separator, which makes them more readable. If non-integers are used (e.g., 25.5 MB transferred), I would like them to use the same decimal separator as the language of the UI uses.

Anyway, the problems I pointed out in my previous post still remain to be dealt with.

Virchanza
Experienced Solver
Experienced Solver
Posts: 78
Joined: Sun Jul 19, 2009 6:12 am

Re: Multilingual application (without locales or internationalisation)

Post by Virchanza » Fri Feb 07, 2020 3:35 pm

I want my program to be useful in a "warehouse situation", where you could have four Polish guys, a Russian guy, a Lithuanian guy and two Welsh guys moving around the place and periodically checking the computer. So the Russian guy walks over, clicks the flag and selects Russian and does what he wants. Then the Welsh guy comes over and selects English and does what he wants. No need to involve the operating system in that.

Virchanza
Experienced Solver
Experienced Solver
Posts: 78
Joined: Sun Jul 19, 2009 6:12 am

Re: Multilingual application (without locales or internationalisation)

Post by Virchanza » Fri Feb 07, 2020 3:36 pm

PB wrote:
Fri Feb 07, 2020 3:33 pm
Just curious, what problems could using a correct locale create? I cannot think of any...
I was getting message box errors on Ubuntu saying it failed to load the "de" or "ga" locale. That's enough grief for me to cut it out if I don't need it.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2572
Joined: Sun Jan 03, 2010 5:45 pm

Re: Multilingual application (without locales or internationalisation)

Post by PB » Fri Feb 07, 2020 3:39 pm

Virchanza wrote:
Fri Feb 07, 2020 3:36 pm
I was getting message box errors on Ubuntu saying it failed to load the "de" or "ga" locale. That's enough grief for me to cut it out if I don't need it.
But that is on your app, trying to load a locale not supported by the system, isn't it? This should be dealt with in your application, e.g., if the error comes from wxLog, you can easily suppress this just as any other error message you do not want the user to see with wxLogNull.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4425
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Multilingual application (without locales or internationalisation)

Post by ONEEYEMAN » Fri Feb 07, 2020 3:42 pm

Hi,
The most obvious reason for that is because the locale was not generated or was generated incorrectly.
Check the "Ubuntu" documentation about generating locale, follow the instructins and everything will work.

Also, please check my previous reply about same language from different countries.

Just remember that "de_DE" will contain German German translations and "de_SWITZERLAND" (sorry don't know the country code on top of my head) will contain German Swiss translations.

How will you program will differentiate between them?

And finally - the number presentation. How do you read the number "123.560"? I would "One hundred twenty three and fifty six hundredth". But in some other country it can be read as "One hundred thousands twenty three Five hundred sixty". Guess what - you program will produce faulty results, brcause user enters "wrong number" according to his/her locale.
And you packet analyzer produces some very weird output based on the wrong locale. Simple as that. A P1 bug.

Thank you.

Virchanza
Experienced Solver
Experienced Solver
Posts: 78
Joined: Sun Jul 19, 2009 6:12 am

Re: Multilingual application (without locales or internationalisation)

Post by Virchanza » Fri Feb 07, 2020 3:57 pm

ONEEYEMAN wrote:
Fri Feb 07, 2020 3:42 pm
And finally - the number presentation. How do you read the number "123.560"? I would "One hundred twenty three and fifty six hundredth". But in some other country it can be read as "One hundred thousands twenty three Five hundred sixty". Guess what - you program will produce faulty results, brcause user enters "wrong number" according to his/her locale.
This doesn't happen in my program. I don't take punctuated numbers from the user.
And you packet analyzer produces some very weird output based on the wrong locale. Simple as that. A P1 bug.
Again, this doesn't happen in my program. I don't display or save any punctuated numbers.

Post Reply