Skip to content
This repository has been archived by the owner on Dec 17, 2017. It is now read-only.

Translation for developers

amoskvin edited this page Oct 11, 2012 · 3 revisions

Imagine that we have a small project - razor-foo. It contains main.cpp, foo.h, foo.cpp, and the form foo.ui. CMakeList.txt looks like:

project(razor-foo)

set(razor-foo_H_FILES
    foo.h
)

set(razor-foo_MOC_FILES
    foo.h
)

set(razor-foo_CPP_FILES
    main.cpp
    foo.cpp
)

set(razor-foo_UI_FILES
    foo.ui
)

...

qt4_wrap_cpp(razor-foo_MOC_SOURCES ${razor-foo_MOC_FILES})
qt4_wrap_ui(razor-foo_UI_HEADERS ${razor-foo_UI_FILES})

add_executable(razor-foo 
    ${razor-foo_CPP_FILES} 
    ${razor-foo_UI_FILES} 
    ${razor-foo_MOC_SOURCES}
)
install(TARGETS razor-foo RUNTIME DESTINATION bin)

Adding translations to cmake.

The first is you need is to check that the CMakeList has a project(razor-foo) directive.

In order to do the translation, cmake must have the following information:

  • What files contains lines that require translation (usually all .h, .cpp and .ui files).
  • Where the .ts files can be found.
  • What the name of the result .qm file, and in what directory it copied during installation.

For this you should use the razor_translate_ts. The full signature of it:

razor_translate_ts(
  OUT_QM_FILES_LIST             result, list of the .qm files.  

  SOURCES file1 file2 ...       list of all translatable files (required)

  TRANSLATION_DIR dir_name      path to directory with .ts files, 
                                   by default is ./translations

  INSTALLATION_DIR              directory for .qm files, 
                                   by default is ${CMAKE_INSTALL_PREFIX}/share/razor/${PROJECT_NAME}

  TS_SRC_FILE                   ts files with original lines, 
                                   by default is {_translationDir}/${PROJECT_NAME}.ts.src 
)

For the last three parameters we are using the default values, so we will add to CMakeList.txt the next block:

include(RazorTranslate)
razor_translate_ts(razor-foo_QM_FILES 
    SOURCES
        ${azor-foo_H_FILES}
        ${razor-foo_CPP_FILES} 
        ${razor-foo_UI_FILES}
)

Now let's say cmake that it should use the QM files when builds the programm.

add_executable(
    razor-foo ${razor-foo_CPP_FILES} 
    ${razor-foo_UI_FILES} 
    ${razor-foo_MOC_SOURCES} 
    ${razor-foo_QM_FILES}
)

Creating TS.SRC file

We need to create translations/foo.ts.src file. It contains the all translatable string. We will upload this file on transifex server later.

cd build;
cmake .. && make UpdateTsFiles

In the future, you can use 'make UpdateTsFiles' command for update the all .ts files, after the sources was changed.

Updating .tx/config file

The server uses a configuration file .tx/config. We need to update it. Run the command:

make UpdateTxFile

Uploading TS.SRC on transifex

Now we can upload files to transifex.com

tx push -s -r razor-qt.razor-foo

for only razor-foo, or

tx push -s 

fo all sources files. See tx help push for more information.

Update translation files.

Time passes, and translations for your program is ready. Now we have to download them to the source tree.

tx pull -a -r razor-qt.razor-foo 

for only razor-foo, or

tx pull -a 

for all translation files.

Note: Since tx uses timestamps to determine when to fetch translation files, in some cases translations could be missed (for example, if the git repository was checked out after the translation was made). To ensure that all translation files really get fetched, use:

tx pull -a -f

Now when you run the make && make install, the .qm files will be installed in the /usr/share/razor/razor-foo directory.