-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework in-source layout of plugin translations
Instead of copying all the plugin catalogs directly under 'i18n/po' with the language as part of the filename, copy them under a subdirectory for their language. This has few advantages: - there is no need to rename them when copying in the sources, and when compiling them - each language gets its own CMakeLists.txt (copied from a static template), so it is possible to glob for .po files, and use the standard GETTEXT_PROCESS_PO_FILES() macro of the Gettext cmake module - a lot of the current manual code to build translations, including renaming, custom targets, etc is removed - each .po file is always compiled, so there is no need to execute msgfmt first to get its statistics (thus the build is faster) The only behaviour change is that now all the shipped .po files are compiled and installed, no matter their completion status. The previous code used to not compile a .po file with less than 80% of translated messages; this is something that has not been generally done for many years in KDE, as the completion percentage does not say much about the actual usefulness of a translation. If something like this is needed again, then a better way is to simply not copy translations in the sources, rather than ignoring them.
- Loading branch information
Showing
4 changed files
with
20 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,5 @@ | ||
MACRO(RKHandlePO _PO_FILES) | ||
FOREACH(_poFile ${_PO_FILES}) | ||
GET_FILENAME_COMPONENT(_fullPoName ${_poFile} NAME) | ||
STRING(REPLACE "." ";" _nameParts ${_fullPoName}) | ||
LIST(LENGTH _nameParts _namePartsCount) | ||
LIST(GET _nameParts 0 _poid) | ||
LIST(GET _nameParts 1 _lang) # Remainder of _nameParts should be "po" | ||
# This can be used to allow temporary exceptions to our "translations must be at least 80% complete, as else, they are probably in bad shape"-rule. | ||
# NOTE: Could also be set only for specific ${_poid}s (e.g. recently added po files) | ||
# SET(ACCEPT_INCOMPLETE_PO "-DACCEPT_INCOMPLETE_PO=1") | ||
|
||
# Sort files into a proper tree layout during generation, so they can be installed using INSTALL(DIRECTORY ...) | ||
# INSTALL(FILES ... OPTIONAL) will leave empty directories, if file does not exist (was not generated) | ||
SET(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/plugins/${_lang}/LC_MESSAGES/${_poid}.mo) | ||
|
||
# making the gmo be re-built, when the po changes, but not every time is surprsingly difficult | ||
# (since the gmo file is only built for translations which are complete enough) | ||
SET(_stampFile ${CMAKE_CURRENT_BINARY_DIR}/${_poid}.${_lang}.stamp) | ||
ADD_CUSTOM_COMMAND(OUTPUT ${_stampFile} | ||
COMMAND ${CMAKE_COMMAND} "-D_poFile=${_poFile}" "-D_gmoFile=${_gmoFile}" "-DGETTEXT_MSGFMT_EXECUTABLE=${GETTEXT_MSGFMT_EXECUTABLE}" ${ACCEPT_INCOMPLETE_PO} -P ${CMAKE_CURRENT_SOURCE_DIR}/compile_po.cmake | ||
COMMAND ${CMAKE_COMMAND} -E touch ${_stampFile} | ||
COMMENT "Generating translation for language '${_lang}', catalog '${_poid}'" | ||
DEPENDS ${_poFile}) | ||
LIST(APPEND active_translations ${_stampFile}) | ||
ENDFOREACH(_poFile ${_PO_FILES}) | ||
ENDMACRO(RKHandlePO) | ||
|
||
|
||
FIND_PROGRAM(GETTEXT_MSGFMT_EXECUTABLE msgfmt) | ||
|
||
IF(NOT GETTEXT_MSGFMT_EXECUTABLE) | ||
MESSAGE( | ||
"------ | ||
NOTE: msgfmt not found. Translations will *not* be installed | ||
------") | ||
ELSE(NOT GETTEXT_MSGFMT_EXECUTABLE) | ||
IF(NOT TRANSLATION_SRC_DIR) | ||
SET(TRANSLATION_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/po/") | ||
ENDIF(NOT TRANSLATION_SRC_DIR) | ||
FILE(GLOB PO_FILES "${TRANSLATION_SRC_DIR}/*.po") | ||
RKHandlePO("${PO_FILES}") | ||
ADD_CUSTOM_TARGET(translations ALL DEPENDS ${active_translations}) | ||
IF(NOT PO_FILES) | ||
MESSAGE(WARNING | ||
"------ | ||
No translations found at ${TRANSLATION_SRC_DIR}. | ||
${TRANSLATION_SRC_DIR} was not found. This probably means that you are building from the development repository, and have not fetched translations. This is ok, if you want to run RKWard in English, only. Otherwise, to fetch translations, either | ||
scripts/import_translations.py XX | ||
where (XX is your language code, such as \"de\"; optionally specify several codes separated by spaces). In some cases (esp., if you want to build all existing translations), it is much faster to use: | ||
git clone git://anongit.kde.org/scratch/tfry/rkward-po-export i18n/po | ||
Should you have installed translations to a non-standard directory, you can specify that using | ||
cmake [...] -DTRANSLATION_SRC_DIR=/x/y/z | ||
------") | ||
ELSE(NOT PO_FILES) | ||
INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/plugins/ DESTINATION ${DATA_INSTALL_DIR}/rkward/po OPTIONAL) | ||
ENDIF(NOT PO_FILES) | ||
ENDIF(NOT GETTEXT_MSGFMT_EXECUTABLE) | ||
|
||
SET(TRANSLATION_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/po/") | ||
FILE(GLOB _dirs "${TRANSLATION_SRC_DIR}/*") | ||
FOREACH(_dir ${_dirs}) | ||
ADD_SUBDIRECTORY("${_dir}") | ||
ENDFOREACH() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
GET_FILENAME_COMPONENT(_lang "${CMAKE_CURRENT_SOURCE_DIR}" NAME) | ||
FILE(GLOB _poFiles "${CMAKE_CURRENT_SOURCE_DIR}/*.po") | ||
GETTEXT_PROCESS_PO_FILES(${_lang} ALL INSTALL_DESTINATION "${DATA_INSTALL_DIR}/rkward/po" PO_FILES ${_poFiles}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters