Skip to content

Commit

Permalink
Add support for translation of strings found in darktable styles.
Browse files Browse the repository at this point in the history
Remove the hack added in view/darkroom.c for two strings now
auto-generated.
  • Loading branch information
TurboGit committed Jan 21, 2025
1 parent e9df3b5 commit 227e5d1
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
1 change: 1 addition & 0 deletions po/POTFILES.in
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions src/views/darkroom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
47 changes: 47 additions & 0 deletions tools/generate_styles_string.sh
Original file line number Diff line number Diff line change
@@ -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 '<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="info">
<xsl:value-of select="name"/>
</xsl:template>
<xsl:template match="style"/>
</xsl:stylesheet>' ) $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

0 comments on commit 227e5d1

Please sign in to comment.