therecipe / qt

Qt binding for Go (Golang) with support for Windows / macOS / Linux / FreeBSD / Android / iOS / Sailfish OS / Raspberry Pi / AsteroidOS / Ubuntu Touch / JavaScript / WebAssembly
GNU Lesser General Public License v3.0
10.48k stars 748 forks source link

i18n & translation #160

Open joeblew99 opened 7 years ago

joeblew99 commented 7 years ago

I am wondering how we want to handle translation

what resources are there ? https://appbus.wordpress.com/2016/04/28/howto-translations-i18n/

https://github.com/therecipe/qt/tree/master/internal/examples/quick/translate

I am more wondering about how i get others to make my translations via a third party web site of pumping each through google translate API. Looks for ideas, recommendations. Imagine you have a project with 5 languages (EN, DE, Spanish, Italian, Chinese). Keeping the code matches with the translations being machine translated and then checked by a person that knows each language can get hairy in terms of co-ordination.

Is there a web sites designed to handle the translation files that QT uses etc ? Really have no idea.

--

Qt Creator has lots of GUI tooling to help you. But in the golang worls there are some good tools to. https://github.com/go-playground/universal-translator

therecipe commented 7 years ago

When I created the quick/translate example, I used lupdate, the Qt Linguist application and lrelease.

IIRC it was basically just something like this:

  1. lupdate to create the .ts file from the .qml file.
  2. Qt Linguist to translate the .ts file (as this seems to be just xml, you can probably decode the .ts file, feed it to google translate or some other site and the encode it again)
  3. lrelease to create the .qm file from the .ts file.

Here is some additional information http://doc.qt.io/qt-5/linguist-manager.html

Keeping the code matches with the translations being machine translated and then checked by a person that knows each language can get hairy in terms of co-ordination.

Yes, I see what you mean.

Is there a web sites designed to handle the translation files that QT uses etc ?

I have no idea. A quick search didn't brought up anything. Maybe the already established translation services already accept *.ts files?

Qt Creator has lots of GUI tooling to help you. But in the golang worls there are some good tools to. https://github.com/go-playground/universal-translator

Seems promising, but it's probably better suited for the widgets than for qml?

I think it woudl not be hard to make tooling using golang that can interact with the standard QT translation files if we wanted.

As these are basically xml files, it shouldn't be to hard to properly decode/encode them.

joeblew99 commented 7 years ago

@therecipe thanks for taking the time to dig through my pretty open ended questions.

all makes sense now.

According to the web site (http://doc.qt.io/qt-5/linguist-manager.html) lupdate is able to do the xliff file format which is a standard. Also the GUI tool, Qt Linguist, can handle xliff files. This also means we can run it through Google translate cloud, and then give it to humans to check.

I dont want to boil the ocean on this though. How about if we start by just putting the bash commands you ran for the example ? Then we can make it work with Google Translate. See here, its pretty nice: https://github.com/maximilien/i18n4go/blob/master/cmds/create_translations.go#L104

https://github.com/maximilien/i18n4go BTW has nice tooling, check the cmd folder. I reckon that it will be easy to write cmds on top of theirs that are QT aware if we want later.

therecipe commented 7 years ago

I dont want to boil the ocean on this though. How about if we start by just putting the bash commands you ran for the example ?

Yes, that's a good idea. I will look into the example again and create a small script. And if possible include a link to the original source I used to create the example. I think there was some small tutorial how to use lupdate and lrelease, but I'm not really sure.

https://github.com/maximilien/i18n4go BTW has nice tooling, check the cmd folder. I reckon that it will be easy to write cmds on top of theirs that are QT aware if we want later.

Those look good, but I probably have to take a deep look at them first.

therecipe commented 7 years ago

I looked into the example again, and here is what I had to run inside the quick/translate folder to get the *.qm file

# create/update the *.ts file
/usr/local/Qt5.7.0/5.7/clang_64/bin/lupdate ./qml/translate.qml -ts ./qml/i18n/translation_fr.ts

# manually translate the word
open /usr/local/Qt5.7.0/5.7/clang_64/bin/Linguist.app

# create the *.qm file
/usr/local/Qt5.7.0/5.7/clang_64/bin/lrelease ./qml/i18n/translation_fr.ts

I also found another probably helpful tool called lconvert inside /usr/local/Qt5.7.0/5.7/clang_64/bin/, which can be used to convert different formats of translation files.

joeblew99 commented 7 years ago

so it all works for me on OSX; android and IOS.

Couple of ideas then.

  1. forget everything i said about golang and i18n :) It seems QT has everything needed. Sorry about that. i forgot the QT team seem to think of everything..

  2. Can we include a little golang CMD thingy that calls the correct tool for the workflow you described a few issues steps up (lupdate, lrelease) ? First steps is to get the right terminal programmes called and the qtLinguist GUI. 2nd step would be an example that shows the whole process working using those cmd. The idea is to show how to do it in a deterministic repeatable fashion for toooling.

  3. Then i am thinking about localiation of number formats.

    • currencies. Swedish uses the ",", instead of the ".".
  4. Hooking into google Translate then is pretty easy using the golang toolkits, if we want to do that here or probably in a side project.

therecipe commented 7 years ago

Can we include a little golang CMD thingy that calls the correct tool for the workflow you described a few issues steps up (lupdate, lrelease) ? First steps is to get the right terminal programmes called and the qtLinguist GUI. 2nd step would be an example that shows the whole process working using those cmd. The idea is to show how to do it in a deterministic repeatable fashion for toooling.

Yeah, wrapping the lupdateand lrelease tools will make the whole process a lot more convenient. I put it on my todo list and will take a look at it tommorow.

Then i am thinking about localiation of number formats.

I'm not sure if this is really necessary, I bet there is some option somewhere that does that for you already. I will investigate.

Hooking into google Translate then is pretty easy using the golang toolkits, if we want to do that here or probably in a side project.

Yeah, it's probably better to in-build such a feature later, once it's able to do the basic "important" stuff. Then there is always time to make it available through a flag or something.

Thanks for the input :)

joeblew99 commented 7 years ago

oh there is great QT support for number formats etc - no ned to use golang libs. I was more thinking that the demo should show it of thats all.

yes i have something basic working to do translate that is format independent that i can map into the CMD thingy we write for QT. Will dig it out and give it a try when ready.

thanks for putting this on the todo :)

On Mon, Mar 27, 2017 at 1:01 AM therecipe notifications@github.com wrote:

Can we include a little golang CMD thingy that calls the correct tool for the workflow you described a few issues steps up (lupdate, lrelease) ? First steps is to get the right terminal programmes called and the qtLinguist GUI. 2nd step would be an example that shows the whole process working using those cmd. The idea is to show how to do it in a deterministic repeatable fashion for toooling.

Yeah, wrapping the lupdateand lrelease tools will make the whole process a lot more convenient. I put it on my todo list and will take a look at it tommorow.

Then i am thinking about localiation of number formats.

I'm not sure if this is really necessary, I bet there is some option somewhere that does that for you already. I will investigate.

Hooking into google Translate then is pretty easy using the golang toolkits, if we want to do that here or probably in a side project.

Yeah, it's probably better to in-build such a feature later, once it's able to do the basic "important" stuff. Then there is always time to make it available through a flag or something.

Thanks for the input :)

— You are receiving this because you authored the thread.

Reply to this email directly, view it on GitHub https://github.com/therecipe/qt/issues/160#issuecomment-289320070, or mute the thread https://github.com/notifications/unsubscribe-auth/ALcac5QLYyeDOyt6aGB8MyI2zQcFl8Hvks5rpuDkgaJpZM4LVMv5 .

pioz commented 7 years ago

Any idea how to translate the menu bar and the buttons inside a QDialogButtonBox?

My try is this:

translator := core.NewQTranslator(nil)
translator.Load2(core.QLocale_System(), "qt_it", "", core.QLibraryInfo_Location(core.QLibraryInfo__TranslationsPath), ".qm")
app.InstallTranslator(translator)

These seems works, the button inside a QDialogButtonBox are translated in italian but the menubar appear without strings, like this https://i.imgur.com/OCK6caa.png

Also, any idea how to generate .ts file when the tr strings are inside a go source code file?

fmt.Println(core.QObject_Tr("Hello", "", -1))
jkumeboshi commented 3 years ago

I would like to abandon Python + Pysyde2 and try to migrate to golang. In this project I can't see the pyside2-lupdate tool equivalent, a tool that is able to collect translatable strings also in the source .py files. There is a similar tool to collect strings also in the .go files?

Translatable strings are marked in .py files using using any of following functions: tr("the string", "optional comment for the translator") translate("translation_context", "the string", "optional comment for the translator") self.tr("the string") # in any QWidget context