Skip to content

Commit

Permalink
Windows translation bundling alternative
Browse files Browse the repository at this point in the history
  • Loading branch information
kmilos committed Feb 11, 2022
1 parent d9e582d commit 8fb4a03
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
31 changes: 20 additions & 11 deletions cmake/windows-macros.cmake
Expand Up @@ -44,6 +44,20 @@ function(_copy_required_library target library)
endfunction()


#-------------------------------------------------------------------------------
# _install_translations(<catalog> <src_localedir>)
#
# Helper macro to install all available translations for a given catalog.
#-------------------------------------------------------------------------------
macro(_install_translations catalog src_localedir)
file(GLOB MO_FILES RELATIVE "${src_localedir}" "${src_localedir}/*/LC_MESSAGES/${catalog}.mo")
foreach(MO ${MO_FILES})
get_filename_component(MO_TARGET_DIR "${MO}" DIRECTORY)
install(FILES "${src_localedir}/${MO}" DESTINATION "share/locale/${MO_TARGET_DIR}" COMPONENT DTApplication)
endforeach()
endmacro()


function(InstallDependencyFiles)

if (WIN32 AND NOT BUILD_MSYS2_INSTALL)
Expand Down Expand Up @@ -171,6 +185,10 @@ if (WIN32 AND NOT BUILD_MSYS2_INSTALL)

install(PROGRAMS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} DESTINATION bin COMPONENT DTApplication)

# Add GLib and GTK translations
_install_translations(glib20 ${MINGW_PATH}/../share/locale)
_install_translations(gtk30 ${MINGW_PATH}/../share/locale)

# TODO: Add auxiliary files for openssl?

# Add pixbuf loader libraries
Expand Down Expand Up @@ -211,6 +229,7 @@ if (WIN32 AND NOT BUILD_MSYS2_INSTALL)
DESTINATION lib/
COMPONENT DTApplication
PATTERN "*.a" EXCLUDE)
_install_translations(libgphoto2-6 ${MINGW_PATH}/../share/locale)

install(DIRECTORY
"${MINGW_PATH}/../lib/libgphoto2_port"
Expand Down Expand Up @@ -256,17 +275,7 @@ if (WIN32 AND NOT BUILD_MSYS2_INSTALL)
DESTINATION share/iso-codes/json/
COMPONENT DTApplication
)
file(GLOB IsoCodes_MO_FILES RELATIVE "${IsoCodes_LOCALEDIR}" "${IsoCodes_LOCALEDIR}/*/LC_MESSAGES/iso_639.mo")
foreach(MO ${IsoCodes_MO_FILES})
string(REPLACE "iso_639.mo" "" MO_TARGET_DIR "${MO}")
install(FILES "${IsoCodes_LOCALEDIR}/${MO}" DESTINATION "share/locale/${MO_TARGET_DIR}" COMPONENT DTApplication)
file(GLOB mofiles "${IsoCodes_LOCALEDIR}/${MO_TARGET_DIR}/*")
foreach(sysfile ${mofiles})
install(FILES ${sysfile}
DESTINATION ${CMAKE_INSTALL_LOCALEDIR}/${MO_TARGET_DIR}
COMPONENT DTApplication)
endforeach(sysfile)
endforeach()
_install_translations(iso_639-2 ${IsoCodes_LOCALEDIR})
endif(IsoCodes_FOUND)

# Add ca-cert for curl
Expand Down
2 changes: 1 addition & 1 deletion packaging/macosx/darktable.bundle
Expand Up @@ -27,7 +27,7 @@
<translations name="libgphoto2-6">${prefix}/share/locale</translations>
<translations name="gtk30">${prefix}/share/locale</translations>
<translations name="gtk-mac-integration">${prefix}/share/locale</translations>
<translations name="iso_639">${prefix}/share/locale</translations>
<translations name="iso_639-2">${prefix}/share/locale</translations>
<translations name="darktable">${prefix:dt}/share/locale</translations>
<data>${prefix:dt}/share/darktable</data>
<data>${prefix}/share/glib-2.0/schemas/org.gtk.Settings.*.gschema.xml</data>
Expand Down
12 changes: 6 additions & 6 deletions src/common/l10n.c
Expand Up @@ -145,21 +145,21 @@ static void get_language_names(GList *languages)
// on windows we are shipping the translations of iso-codes along ours
char localedir[PATH_MAX] = { 0 };
dt_loc_get_localedir(localedir, sizeof(localedir));
bindtextdomain("iso_639", localedir);
bindtextdomain("iso_639-2", localedir);
#else
#ifdef __APPLE__
if(res_path)
{
char localedir[PATH_MAX] = { 0 };
dt_loc_get_localedir(localedir, sizeof(localedir));
bindtextdomain("iso_639", localedir);
bindtextdomain("iso_639-2", localedir);
}
else
#endif
bindtextdomain("iso_639", ISO_CODES_LOCALEDIR);
bindtextdomain("iso_639-2", ISO_CODES_LOCALEDIR);
#endif

bind_textdomain_codeset("iso_639", "UTF-8");
bind_textdomain_codeset("iso_639-2", "UTF-8");

parser = json_parser_new();
if(!json_parser_load_from_file(parser, filename, &error))
Expand Down Expand Up @@ -229,7 +229,7 @@ static void get_language_names(GList *languages)
g_setenv("LANGUAGE", language->code, TRUE);
setlocale (LC_ALL, language->code);

char *localized_name = g_strdup(dgettext("iso_639", name));
char *localized_name = g_strdup(dgettext("iso_639-2", name));

/* If original and localized names are the same for other than English,
* maybe localization failed. Try now in the main dialect. */
Expand All @@ -241,7 +241,7 @@ static void get_language_names(GList *languages)
g_setenv("LANGUAGE", language->base_code, TRUE);
setlocale (LC_ALL, language->base_code);

localized_name = g_strdup(dgettext("iso_639", name));
localized_name = g_strdup(dgettext("iso_639-2", name));
}

/* there might be several language names; use the first one */
Expand Down

0 comments on commit 8fb4a03

Please sign in to comment.