Board index FlightGear Development Aircraft

User language

Questions and discussion about creating aircraft. Flight dynamics, 3d models, cockpits, systems, animation, textures.

User language

Postby Harald » Wed Aug 10, 2016 2:25 pm

Do we have a property that gives the current language of the user ?
What can I do to display a localized message or text in a dialog for a specific aircraft ?

hj.
Harald
 
Posts: 179
Joined: Fri Mar 02, 2007 5:30 pm
Location: Strasbourg, France
Version: nightly
OS: Windows 10

Re: User language

Postby erik » Thu Aug 11, 2016 11:09 pm

For the main program it's done by reading in a set of string-properties based on the specified language. The dialogs then use these properties to display the strings. I don't know from the top of my head if this can be extended to aircraft. I´ll try to look into that tomorrow.

Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2244
Joined: Thu Nov 01, 2007 2:41 pm

Re: User language

Postby erik » Fri Aug 12, 2016 8:02 am

It doesn't look like there is a way to easily integrate internationalization for aircraft specific dialogs at this point. The current language settings are not yet exposed in the property tree either. But it sounds like a useful addition to me.

Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2244
Joined: Thu Nov 01, 2007 2:41 pm

Re: User language

Postby Hooray » Fri Aug 12, 2016 8:53 pm

Note that any Canvas dialog can trivially support this use-case.

To accomplish the same thing for PUI dialog, you'd need to use dynamic (sprintf-based) "live" property labels and make those reference properties instead of static strings - at that point, you can also honor any language settings that you have and dynamically change the dialog contents (I have used this approach for other PUI dialogs that required dynamic contents).

Besides, as a workaround, you can use the default menubar to see if English is in use or not, and then use that for any other heuristics.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: User language

Postby Harald » Sat Aug 13, 2016 8:07 am

How is Canvas handling localization ? Can you show an example ?

What properties tell me what menubar is in use ?

hj.
Harald
 
Posts: 179
Joined: Fri Mar 02, 2007 5:30 pm
Location: Strasbourg, France
Version: nightly
OS: Windows 10

Re: User language

Postby Hooray » Sat Aug 13, 2016 12:10 pm

Canvas already uses osgText internally, and supports utf8.

That is why I mentioned the PUI workaround using sprintf-style format strings in conjunction with live properties - you can then simply use a hash map to emulate a multi-language dialog - in contrast, any Canvas element, including GUI widgets (labels) is a fully dynamic thing - thus, there is no workaround needed. All you need to do is to set up a hash with strings for each language you'd like to support, at that point you can simply set the value of the label by retrieving the correct string from the hash:

Code: Select all
var STRINGS = {
ENGLISH: {
hello: 'hello',
}, # end of english strings

FRENCH: {
hello: 'bonjour',
}, # end of french strings


SPANISH: {
hello: 'hola',
}, # end of spanish strings

};

var language = 'SPANISH';

print( STRINGS[language].hello );


Note that you could also add another layer of indirection/flexibility by using printf-style format strings here, and a vector with variables to be substituted

Obviously, instead of using print() here, you can use a .setText() call, e.g. see the example at: http://wiki.flightgear.org/Canvas_Snipp ... GUI_Labels
Image

Instead of settings the locale manually, you can refer to $FG_ROOT/Translations and the defaults used there to tell if another locale is in use, and then use for your heuristics.

So, no complicated changes are needed - however, if Erik is right, it would indeed make sense to expose the corresponding settings in the form of properties.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: User language

Postby Harald » Sun Aug 14, 2016 8:06 am

Hooray wrote in Sat Aug 13, 2016 12:10 pm:Instead of settings the locale manually, you can refer to $FG_ROOT/Translations and the defaults used there to tell if another locale is in use, and then use for your heuristics.

So, no complicated changes are needed - however, if Erik is right, it would indeed make sense to expose the corresponding settings in the form of properties.


I still don't understand that part. I found no property that contains the current menubar in use so I can not compare what is in use with some reference values.

hj.
Harald
 
Posts: 179
Joined: Fri Mar 02, 2007 5:30 pm
Location: Strasbourg, France
Version: nightly
OS: Windows 10

Re: User language

Postby Hooray » Sun Aug 14, 2016 11:12 am

$FG_ROOT/Translations contains references that are looked up by the menubar - so the menubar merely contains property references, not the strings - the translated strings are then looked up using those properties - e.g. see $FG_ROOT/Translations/en/menu.xml (?)

Next, check preferences.xml for the <intl> tag that includes Translations/locale.xml

At that point, you should understand how the existing scheme works, and how you can use the same mechanism to also localize Canvas dialogs accordingly, even without hard-coding any language into the code.

So, even if Erik is right (I haven't checked that), you can still look up the translations in $FG_ROOT/Translations and determine what locale/language is being used, even without using any C++
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: User language

Postby Harald » Sun Aug 14, 2016 2:24 pm

I already know all that.
The question is not how to do a translation but how to know what locale is used.

hj.
Harald
 
Posts: 179
Joined: Fri Mar 02, 2007 5:30 pm
Location: Strasbourg, France
Version: nightly
OS: Windows 10

Re: User language

Postby Hooray » Sun Aug 14, 2016 8:06 pm

like I said, there are several ways to skin that cat, but why don't you simply look at the translations available and do a reverse lookup using the data that is available ?
I mean, it's all loaded into the tree obviously - so you don't need any C++ code to do that - it's really as simple as doing a getprop call and checking the value of the key for something like "load-tape" (in the tree) and check its value against the default (English), i.e. "Load Flight Recorder Tape" - in other words, if the value is "Carica nastro registratore di volo", you have all you need to obtain the locale, even if you don't know any other way to do this using C++ code, i.e. the French translation reads "Charger la vidéo d'un vol!" - thus, you can also obtain the locale.

Equally, there is options.xml and other locale-based settings that you do for a reverse lookup to obtain the language setting - so you don't need much more than 20 lines of Nasal code to get a vector with files/directories from $FG_ROOT/Translations via the directory() API, and then use the io.read_properties() API to processs such files, and use the .getValues() method to obtain a corresponding hash that you can then traverse using a foreach() loop.



Anyway, if you think this is too complicated, just use the hash approach suggested previously.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: User language

Postby Harald » Mon Aug 15, 2016 7:30 am

There is no translated menu in the property tree. The only place where that is translated is in the PUI controls.

hj.
Harald
 
Posts: 179
Joined: Fri Mar 02, 2007 5:30 pm
Location: Strasbourg, France
Version: nightly
OS: Windows 10

Re: User language

Postby Hooray » Sat Aug 20, 2016 9:26 pm

Sorry for getting back to this so late - I haven't been following the forum much. Apart from that, I also haven't built/started fgfs in months, so you are obviously in a better position to check if my comments are true or not. Anyway, as far as I remember, there should be some kind of /sim/intl and /locale tree somewhere in the global tree, have you checked if that's the case or not?
There should also be a vector with <lang> nodes for each supported locale.

The whole locale handling stuff is fairly old code, but I do remember that most strings read during startup are mapped that way, which is why I suggested to do a reverse lookup to obtain the information that you need, i.e the translated strings should be also available there.

And even if something should be missing all those files are PropertyList files that can be read/processed using 10 lines of Nasal code (via io.read_properties)

Unfortunatetely, we don't seem to have any complete property tree dump (offline) available - other than executing fgfs, having some kind of database would be really useful some day.


Anyway, like I said, I don't have any direct way to actually build/run fgfs currently, but I would suggest to really review what's available in the property tree, I do remember having done something very similar a while ago, and I ended up using data that was already in the tree.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: User language

Postby wkitty42 » Sat Aug 20, 2016 9:41 pm

Hooray wrote in Sat Aug 20, 2016 9:26 pm:Anyway, as far as I remember, there should be some kind of /sim/intl and /locale tree somewhere in the global tree

FWIW: there is /sim/intl/locale/lang and /sim/intl/locale/lang[1] through lang[7] in my configuration which is english only... i don't have any way that i know of to switch languages and if i did, i wouldn't be able to do much with it as i can only read english these days so i don't know and can't find out what would change in this property area... i kinda suspect that this may be what harald may be looking for but that's only a guess based on the conversations and my own digging from a few weeks back just to see what i could see...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9146
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: User language

Postby Hooray » Sat Aug 20, 2016 10:10 pm

thank you, that makes sense to me, as far as I can remember, changing languages is a startup-only option - but everything else you said matches my previous recommendation to use the data in the tree to do a reverse lookup and obtain the locale/language in use.

Actually, it really should be all there - I think I was using it last year when I was toying with parsing the legacy UI/XML for the pui2canvas parser, and I didn't hit any major roadblocks as far I remember
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU


Return to Aircraft

Who is online

Users browsing this forum: No registered users and 11 guests