Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows translation bundling alternative #10807

Merged
merged 1 commit into from Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -169,6 +183,10 @@ if (WIN32 AND NOT BUILD_MSYS2_INSTALL)
list(APPEND CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS ${TMP_SYSTEM_RUNTIME_LIBS})
endif()

# 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 @@ -219,6 +237,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 @@ -265,17 +284,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