Skip to content

savolai/Merge-Qt-TS-files

Repository files navigation

Merge Qt .ts files

Sometimes you can end up in a situation where you have multiple little apps (Qt projects) as part of a bigger project. So you may have started out with multiple translation files, but really, you want a single common translation file between projects so they share a vocabulary. So how do you combine multiple translation files? This app makes it easy.

Note: There's a newer project with a more versatile UI for this at the following address. It was originally based on this project, then apparently rewritten. I haven't tested it though. This newer project makes it harder to know which imported language file is prioritized though, which is essential for me. https://github.com/aschet/linguistmerge

See also lconverter https://stackoverflow.com/questions/8513149/merge-translation-files-ts-with-existing-ts-files-using-qt-utilities-lconve Screenshot: This app allows you to combine multiple Qt .ts files into one

This is a Qt project. The easiest way to use it is to install Qt, download and open the project / CombineTranslationFiles.pro in Qt Creator, and then compile and run the project.

This also provides a simple, easily adaptable model GUI, as well as QXmlStreamReader/Writer code sample, for merging multiple files of any XML format. Just in case you don't like XSL.

For use as-is. Made for my own use. Pull requests welcome.

Usage:

  1. Open each source file by pressing "Browse source...". After doing that, click "Read in current source file translations". You will get a count of translations loaded into memory.
  2. Repeat step 1 for each file you want to combine
  3. After reading into memory all your translation data, select target file by pressing "Browse target...". After selecting filename to save to, press "Write translations to file".

This app is designed to preserve as much as possible of the information in the translation files.

When combining multiple translation files, this makes sure translations with empty content never override translations with existing content.

If multiple of your source files contain conflicting, nonempty, translations for the same translation units (i.e classname+source text content), make sure to load the file that has the translations you want, last.

Caveat: This tool does NOT currently include multiple elements if many exist in source translation units, only one of them is included for each translation. Mostly this never makes any difference, since a single run of lupdate project1.pro project2.pro -ts projects.ts (where projects.ts is the output file of this program) will put all the additional locations back again.

Background

This is useful when you have multiple applications

  1. that have language files of their own
  2. that statically link to common libraries that also have translations

In this situation, overlaps in translation files can cause strings not getting translated in the UI. Also, qt docs don't exactly wanr about this situation, and also it tends to creep up on you; I found myself in a situation with hundreds of translation spread across multiple translation files that should have been one. So I wrote this to fix it.

The solution is to produce a common translation file for all the apps. First run your ts files through this app, combining translations. Then run lupdate like below - this updates the location tags of the translations to point to the right place(s). After that, you can normally run lrelease on your ts file to produce .qm and load it from all your apps.

Thanks David Faure / @dfaure-kdab for pointing me to the right direction.

Other options that might help:

  1. When loading translation files into your app, first load the app specific language file and then on top of that, the translations for the common components. This occured to me too late. \o/ however, having all project translations in a single file tends to be a cleaner solution overall, as you will always know what has already been translated.
  2. Using an XML merging tool such as those mentioned in this StackOverflow post might also work, but I enjoyed making this and emh, now we have a GUI :)

About

Allows you to combine multiple Qt .ts files into one

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •