Support Import/Export *.ts files for translations
Hi Alex,
thanks for your great work with LimeReports!
Translations feature is really good but it would be great to have *.ts files support for it. I have really complex reports (tens of pages) with support for several languages (at least 9 for now) so handling these translations exactly same as with our Qt app (*.ts files) would simplify handling translation side of the project.
From what I see now there's only way to handle them inside Translations tab of LimeReport designer so I would have to ship LimeReport to translators or maybe find a way to parse these strings to more convenient format.
As I'm on a short deadline I briefly implemented Import/Export *.ts inside XMLWriter and XMLReader classes and I connected them to 'Export TS' and 'Import TS' buttons in a place where you add/remove languages in LimeReport designer. I also added handling of the languages into console app as I have to generate them on a server and ARM embedded device.
I thought it would be a good idea to share my code with you and/or contribute it into your codebase. I would create Pull Request but I'm using GitLab ;)
Here's my branch: https://gitlab.com/jakub_motyczko/LimeReport/-/tree/1.5.61_export_ts
It still requires some tweaks but unfortunately I don't have too much time right now for them:
- use some existing BSD licensed header with country codes for file naming (Qt doesn't have it implemented afaik)
- split importTranslationsFromTsFiles into smaller methods
- split exportTranslationToTsFile into smaller methods
- improve error handling for more feedback on screen - now there's only dialog about error with 'please check logs for more feedback'
- add icons for Export and Import buttons - I wanted to use some CC3 icons but they require to put references into the app (maybe About->'CC3 icons' tab would be a good fit for it)
- mark document as dirty after importing *.ts file
Usage case for the changes:
- create report
- go into Translations tab
- add some languages
- press 'Export TS' and pick a dir where to put *.ts files
- open *.ts files with QtLinguist
- translate strings
- save *.ts files
- press 'Import TS' in LimeReport and pick translated *.ts files
- save report
Please let me know what you think.
Hi!
Please let me know what you think.
I think this is a good feature :)
use some existing BSD licensed header with country codes for file naming (Qt doesn't have it implemented afaik)
I think we can use language names instead of county codes because there are no one-to-one reflection languages to country codes. We can use something like this:
const QString languageName = QLocale::languageToString(reportTranslation->language());
instead of
const QString countryCode = contryCodes.value(reportTranslation->language(), QString());
add icons for Export and Import buttons - I wanted to use some CC3 icons but they require to put references into the app (maybe About->'CC3 icons' tab would be a good fit for it)
I think we can use the next icons:
Export TS -
Import TS -
Icons look good Mate ;)
file names can be QLocale::languageToString, but the problem is that TS needs country code so QtLinguist could automagically detect target translation:
rootElement.setAttribute("language", countryCode);
without that after each 'Export TS' you would have to pick languages when loading files inside QtLinguist
Oh, I did not consider this fact. However, if I am not mistaken, there is no way to map the language to the country code :( If we want to save it in the right way we should ask users what code it should be.
I think we could do the next trick:
const QString languageName = QLocale::languageToString(reportTranslation->language());
const QString countryCode = QLocale(reportTranslation->language()).name();
The languageName we can use for the file name and countryCode for the rootElement
However, if I am not mistaken, there is no way to map the language to the country code :(
Yes, to generate e.g. en_GB we would need language + country so it would require updating LanguageSelectDialog. Qt uses libicu so I guess we could use it directly or maybe some Qt private headers to make it work. LimeReport designer uses private headers anyways so I guess it could work.
Please let me know if you want me to make the changes on my GitLab repo or maybe you prefer to take over it now and adjust by yourself. I think I'll be able to do it this month.
QtLinguist needs languageCode_contryCode so I'm afraid this:
const QString countryCode = QLocale(reportTranslation->language()).name();
won't work.
I have checked it works :) at least for the Russian, English, German, Arabic :)
But users can be upset if they see the United States of America instead of Great Britain :). I don't know is it critical or not :).
But in the other case, we should ask what country code we should use for creating ts file.
awesome! I think it will be good enough :)
static QLatin1String QLocalePrivate::languageToCode(QLocale::Language language); static QLatin1String QLocalePrivate::countryToCode(QLocale::Country country); static QString Translator::makeLanguageCode(QLocale::Language language, QLocale::Country country);
so we could ask users for Language and Country and generate the languageCode_contryCode by ourselves.
but it's your call as it will require storing Language and Country codes in lrxml.
I think we have to try the easy way if someone will upset we can use a more complex way :)
sounds like a plan :)
Maybe we should also use the report name when generating ts file name?