Is this the correct way to generate translations with cmake?
-
Is this the correct way to generate translations with cmake?
set(translation_files translations/librum_en.ts translations/librum_de.ts translations/librum_ru.ts translations/librum_zh.ts ) # Translations for the application qt_add_translations(presentation TS_FILES ${translation_files}) add_dependencies(presentation presentation_lupdate) add_dependencies(presentation presentation_lrelease) add_dependencies(presentation update_translations)@Creaperdown the qt_add_translations() call looks straighforward. But why did you feel the need to add the manual add_dependencies?
add_dependencies(presentation presentation_lupdate)
This would mean that the source side of the .ts file is updated in every build by running lupdate. This is an unusual setup; you typically want to update the .ts files only at certain times (e.g. if you actually want to start updating the translation).
add_dependencies(presentation presentation_lrelease)
This should be unnecessary, as qt_add_translations adds such a dependency.
add_dependencies(presentation update_translations)
This is just the same as add_dependencies(presentation presentation_lupdate), as long as you don't add more qt_add_translations calls to other targets.
-
@Creaperdown the qt_add_translations() call looks straighforward. But why did you feel the need to add the manual add_dependencies?
add_dependencies(presentation presentation_lupdate)
This would mean that the source side of the .ts file is updated in every build by running lupdate. This is an unusual setup; you typically want to update the .ts files only at certain times (e.g. if you actually want to start updating the translation).
add_dependencies(presentation presentation_lrelease)
This should be unnecessary, as qt_add_translations adds such a dependency.
add_dependencies(presentation update_translations)
This is just the same as add_dependencies(presentation presentation_lupdate), as long as you don't add more qt_add_translations calls to other targets.
@kkoehne From what I understood:
add_dependencies(presentation presentation_lupdate)Is regenerating the ts files from my source code. Since I am doing quite a lot of changes to the front-end of my application, which includes adding new text, I thought that this would always keep my ts files up to date with my application. Or did I understand this incorrectly?
-
@kkoehne From what I understood:
add_dependencies(presentation presentation_lupdate)Is regenerating the ts files from my source code. Since I am doing quite a lot of changes to the front-end of my application, which includes adding new text, I thought that this would always keep my ts files up to date with my application. Or did I understand this incorrectly?
@Creaperdown said in Is this the correct way to generate translations with cmake?:
I thought that this would always keep my ts files up to date with my application. Or did I understand this incorrectly?
You're correct that you update your ts files on every compile run but what's the point of this - do you also update all your translations with linguist after each compile run?
-
@Creaperdown said in Is this the correct way to generate translations with cmake?:
I thought that this would always keep my ts files up to date with my application. Or did I understand this incorrectly?
You're correct that you update your ts files on every compile run but what's the point of this - do you also update all your translations with linguist after each compile run?
@Christian-Ehrlicher So your suggestion would be manually running lupdate whenever I change my translation and just changing my code to:
set(translation_files translations/librum_en.ts translations/librum_de.ts translations/librum_ru.ts translations/librum_zh.ts ) # Translations for the application qt_add_translations(presentation TS_FILES ${translation_files})?
-
@Christian-Ehrlicher So your suggestion would be manually running lupdate whenever I change my translation and just changing my code to:
set(translation_files translations/librum_en.ts translations/librum_de.ts translations/librum_ru.ts translations/librum_zh.ts ) # Translations for the application qt_add_translations(presentation TS_FILES ${translation_files})?
@Creaperdown Yes 🙂
Iirc there should also be a menu entry in QtCreator to update the translations -
@Creaperdown Yes 🙂
Iirc there should also be a menu entry in QtCreator to update the translations@Christian-Ehrlicher Even after reading the docs, I am not entirely sure what
qt_add_translationsdoes. Does it already generate the .qm files? I have removed all theadd_dependencies(...)stuff but my cmake output still shows me that the .qm files are generated. Does it also automatically update the .ts files? -
@Christian-Ehrlicher Even after reading the docs, I am not entirely sure what
qt_add_translationsdoes. Does it already generate the .qm files? I have removed all theadd_dependencies(...)stuff but my cmake output still shows me that the .qm files are generated. Does it also automatically update the .ts files?qt_add_translations() creates qm files out of the ts files and adds those ts files to the target (created with add_executable/add_library) so they are regenerated on every built of this target when needed (= when the ts files changed in some way). So as long as you don't touch the ts files the qm files should not be regenerated. If so we have to take a look on it.
Additionally this function creates ${target}_lrelease, update_translation which you can call manually to update the ts files. -
qt_add_translations() creates qm files out of the ts files and adds those ts files to the target (created with add_executable/add_library) so they are regenerated on every built of this target when needed (= when the ts files changed in some way). So as long as you don't touch the ts files the qm files should not be regenerated. If so we have to take a look on it.
Additionally this function creates ${target}_lrelease, update_translation which you can call manually to update the ts files.@Christian-Ehrlicher Ok, so in short it generates qm files out of the ts files, but doesn't automatically update the ts files when strings in the source code change?
-
@Christian-Ehrlicher Ok, so in short it generates qm files out of the ts files, but doesn't automatically update the ts files when strings in the source code change?
@Creaperdown Yes
-
@Christian-Ehrlicher Thanks! This answered all my questions, I'll close the issue.
-
C Creaperdown has marked this topic as solved on