From 227e5d1447e0095f9022059e267b87945aaeacc2 Mon Sep 17 00:00:00 2001 From: Pascal Obry Date: Tue, 21 Jan 2025 17:21:32 +0100 Subject: [PATCH] Add support for translation of strings found in darktable styles. Remove the hack added in view/darkroom.c for two strings now auto-generated. --- po/POTFILES.in | 1 + src/CMakeLists.txt | 14 ++++++++++ src/views/darkroom.c | 2 -- tools/generate_styles_string.sh | 47 +++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100755 tools/generate_styles_string.sh diff --git a/po/POTFILES.in b/po/POTFILES.in index 2ee8977ae638..4db60157f450 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,5 +1,6 @@ build/bin/conf_gen.h build/bin/preferences_gen.h +build/bin/styles_string.h build/bin/tools/darktable_authors.h build/lib/darktable/plugins/introspection_ashift.c build/lib/darktable/plugins/introspection_atrous.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6c4e4e4b1b23..988455c7ebba 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -919,6 +919,19 @@ else(NOT ${Xsltproc_BIN} STREQUAL "Xsltproc_BIN-NOTFOUND") endif(NOT ${Saxon_BIN} STREQUAL "Saxon_BIN-NOTFOUND") endif(NOT ${Xsltproc_BIN} STREQUAL "Xsltproc_BIN-NOTFOUND") +add_custom_command( + DEPENDS ${DARKTABLE_DATADIR}/styles/*.dtstyle + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/styles_string.h + COMMAND ${CMAKE_SOURCE_DIR}/tools/generate_styles_string.sh ${DARKTABLE_DATADIR}/styles ${CMAKE_CURRENT_BINARY_DIR}/styles_string.h + COMMENT "Generating styles strings for translation" +) + +add_custom_target( + generate_styles_string ALL + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/styles_string.h + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} +) + add_custom_target( generate_preferences ALL DEPENDS ${CMAKE_SOURCE_DIR}/tools/generate_prefs.xsl ${CMAKE_SOURCE_DIR}/data/darktableconfig.dtd ${DARKTABLE_DATADIR}/darktableconfig.xml ${CMAKE_CURRENT_BINARY_DIR}/preferences_gen.h @@ -942,6 +955,7 @@ add_library(lib_darktable SHARED ${DARKTABLE_BINDIR}/preferences_gen.h ${DARKTAB # since this isn't the same directory we do have to manually set it set_source_files_properties(${DARKTABLE_BINDIR}/version_gen.c PROPERTIES GENERATED TRUE) +add_dependencies(lib_darktable generate_styles_string) add_dependencies(lib_darktable generate_conf) add_dependencies(lib_darktable generate_version) add_dependencies(lib_darktable generate_preferences) diff --git a/src/views/darkroom.c b/src/views/darkroom.c index eb6f2fe4aa5f..fbaec3fd2c9d 100644 --- a/src/views/darkroom.c +++ b/src/views/darkroom.c @@ -2366,8 +2366,6 @@ void gui_init(dt_view_t *self) dt_gui_add_help_link(styles, "bottom_panel_styles"); dt_view_manager_view_toolbox_add(darktable.view_manager, styles, DT_VIEW_DARKROOM); /* ensure that we get strings from the style files shipped with darktable localized */ - (void)_("darktable camera styles"); - (void)_("generic"); /* create second window display button */ dev->second_wnd_button = dtgtk_togglebutton_new(dtgtk_cairo_paint_display2, 0, NULL); diff --git a/tools/generate_styles_string.sh b/tools/generate_styles_string.sh new file mode 100755 index 000000000000..0e367eeb3004 --- /dev/null +++ b/tools/generate_styles_string.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +STYLE_DIR=$1 +OUT=$2 + +# Get the l10n strings from styles. Such strings are prefixed by _l10n_ +function get-l10n() +{ + # 1. Get the "name" node value using xsltproc + # + # 2. Cut substrings separated with | and keep only those + # with _l10n_ prefix. + # + # 3. Remove all _l10n_ sentinel with sed + # + # 4. Finaly generates into the while loop the pseudo C code for + # the strings to be translated. + + xsltproc <( echo ' + + + + + + + + + ' ) $1 | + tr '|' '\n' | grep _l10n_ | sed 's/_l10n_//g' | + while read line; do + echo "_(\"$line\")" + done +} + +export IFS=$'\n' + +{ + echo "// Not to be compiled, generated for translation only" + echo + + # Ensure that we remove the duplicate strings + + ls $STYLE_DIR/*.dtstyle | while read file; do + get-l10n $file + done | sort | uniq +} > $OUT