From 9bc83539d124f9645dc92e9e39001cb0192dae61 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Fri, 7 Apr 2017 11:09:47 +0200 Subject: Gettext support --- CMakeLists.txt | 1 + cmake/FindGettext.cmake | 18 ++ cmake/UseGettext.cmake | 28 +++ libdino/CMakeLists.txt | 12 +- libdino/src/application.vala | 1 + libdino/src/dino_i18n.h | 8 + libdino/src/util.vala | 37 ++++ main/CMakeLists.txt | 11 +- main/data/add_conversation/add_contact_dialog.ui | 10 +- main/data/add_conversation/add_groupchat_dialog.ui | 12 +- .../conference_details_fragment.ui | 6 +- main/data/manage_accounts/add_account_dialog.ui | 6 +- main/data/manage_accounts/dialog.ui | 8 +- main/data/menu_app.ui | 6 +- main/data/settings_dialog.ui | 6 +- main/po/LINGUAS | 2 + main/po/POTFILES.in | 20 ++ main/po/de.po | 196 ++++++++++++++++++++ main/po/dino.pot | 205 +++++++++++++++++++++ main/po/en.po | 9 + main/src/main.vala | 10 +- main/src/ui/add_conversation/chat/dialog.vala | 6 +- .../conference/add_groupchat_dialog.vala | 4 +- .../src/ui/add_conversation/conference/dialog.vala | 8 +- main/src/ui/conversation_summary/message_item.vala | 2 +- main/src/ui/conversation_summary/view.vala | 4 +- .../src/ui/manage_accounts/add_account_dialog.vala | 2 +- main/src/ui/manage_accounts/dialog.vala | 18 +- main/src/ui/notifications.vala | 6 +- main/src/ui/occupant_menu/view.vala | 2 +- main/src/ui/unified_window.vala | 10 +- plugins/omemo/CMakeLists.txt | 9 +- plugins/omemo/po/LINGUAS | 2 + plugins/omemo/po/POTFILES.in | 1 + plugins/omemo/po/de.po | 22 +++ plugins/omemo/po/dino-omemo.pot | 22 +++ plugins/omemo/po/en.po | 9 + plugins/omemo/src/account_settings_widget.vala | 6 +- plugins/omemo/src/plugin.vala | 5 + plugins/openpgp/CMakeLists.txt | 10 +- plugins/openpgp/po/LINGUAS | 2 + plugins/openpgp/po/POTFILES.in | 1 + plugins/openpgp/po/de.po | 34 ++++ plugins/openpgp/po/dino-openpgp.pot | 34 ++++ plugins/openpgp/po/en.po | 9 + plugins/openpgp/src/account_settings_widget.vala | 10 +- plugins/openpgp/src/plugin.vala | 5 + 47 files changed, 780 insertions(+), 75 deletions(-) create mode 100644 cmake/FindGettext.cmake create mode 100644 cmake/UseGettext.cmake create mode 100644 libdino/src/dino_i18n.h create mode 100644 libdino/src/util.vala create mode 100644 main/po/LINGUAS create mode 100644 main/po/POTFILES.in create mode 100644 main/po/de.po create mode 100644 main/po/dino.pot create mode 100644 main/po/en.po create mode 100644 plugins/omemo/po/LINGUAS create mode 100644 plugins/omemo/po/POTFILES.in create mode 100644 plugins/omemo/po/de.po create mode 100644 plugins/omemo/po/dino-omemo.pot create mode 100644 plugins/omemo/po/en.po create mode 100644 plugins/openpgp/po/LINGUAS create mode 100644 plugins/openpgp/po/POTFILES.in create mode 100644 plugins/openpgp/po/de.po create mode 100644 plugins/openpgp/po/dino-openpgp.pot create mode 100644 plugins/openpgp/po/en.po diff --git a/CMakeLists.txt b/CMakeLists.txt index 449598ec..e6458065 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,7 @@ set_path(DESKTOP_FILE_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/applications" "Instal set_path(ICON_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/icons" "Installation directory for icons") set_path(INCLUDE_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/include" "Installation directory for C header files") set_path(LIB_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/${LIBDIR_NAME}" "Installation directory for object code libraries") +set_path(LOCALE_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/locale" "Installation directory for locale files") set_path(PLUGIN_INSTALL_DIR "${LIB_INSTALL_DIR}/dino/plugins" "Installation directory for dino plugin object code files") set_path(VAPI_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/vala/vapi" "Installation directory for Vala API files") diff --git a/cmake/FindGettext.cmake b/cmake/FindGettext.cmake new file mode 100644 index 00000000..7d2d260c --- /dev/null +++ b/cmake/FindGettext.cmake @@ -0,0 +1,18 @@ +find_program(XGETTEXT_EXECUTABLE xgettext) +find_program(MSGMERGE_EXECUTABLE msgmerge) +find_program(MSGFMT_EXECUTABLE msgfmt) +find_program(MSGCAT_EXECUTABLE msgcat) + +if(XGETTEXT_EXECUTABLE) + execute_process(COMMAND ${XGETTEXT_EXECUTABLE} "--version" + OUTPUT_VARIABLE GETTEXT_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) + string(REGEX REPLACE "xgettext \\(GNU gettext-tools\\) ([0-9\\.]*).*" "\\1" GETTEXT_VERSION "${GETTEXT_VERSION}") +endif(XGETTEXT_EXECUTABLE) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Gettext + REQUIRED_VARS XGETTEXT_EXECUTABLE MSGMERGE_EXECUTABLE MSGFMT_EXECUTABLE MSGCAT_EXECUTABLE + VERSION_VAR GETTEXT_VERSION) + +set(GETTEXT_USE_FILE "${CMAKE_CURRENT_LIST_DIR}/UseGettext.cmake") \ No newline at end of file diff --git a/cmake/UseGettext.cmake b/cmake/UseGettext.cmake new file mode 100644 index 00000000..3abf418e --- /dev/null +++ b/cmake/UseGettext.cmake @@ -0,0 +1,28 @@ +function(_gettext_mkdir_for_file file) + get_filename_component(dir "${file}" DIRECTORY) + file(MAKE_DIRECTORY "${dir}") +endfunction() + +function(gettext_compile project_name) + cmake_parse_arguments(ARGS "" "MO_FILES_NAME;TARGET_NAME;SOURCE_DIR;PROJECT_NAME" "" ${ARGN}) + + if(NOT ARGS_SOURCE_DIR) + set(ARGS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) + endif(NOT ARGS_SOURCE_DIR) + file(STRINGS "${ARGS_SOURCE_DIR}/LINGUAS" LINGUAS) + set(target_files) + foreach(lang ${LINGUAS}) + set(source_file ${ARGS_SOURCE_DIR}/${lang}.po) + set(target_file ${CMAKE_BINARY_DIR}/locale/${lang}/LC_MESSAGES/${project_name}.mo) + _gettext_mkdir_for_file(${target_file}) + list(APPEND target_files ${target_file}) + add_custom_command(OUTPUT ${target_file} COMMAND ${MSGFMT_EXECUTABLE} -o ${target_file} ${source_file} DEPENDS ${source_file}) + install(FILES ${target_file} DESTINATION ${LOCALE_INSTALL_DIR}/${lang}/LC_MESSAGES) + endforeach(lang) + if(ARGS_MO_FILES_NAME) + set(${ARGS_MO_FILES_NAME} ${target_files} PARENT_SCOPE) + endif(ARGS_MO_FILES_NAME) + if(ARGS_TARGET_NAME) + add_custom_target(${ARGS_TARGET_NAME} DEPENDS ${target_files}) + endif(ARGS_TARGET_NAME) +endfunction(gettext_compile) \ No newline at end of file diff --git a/libdino/CMakeLists.txt b/libdino/CMakeLists.txt index 0d1a9bf4..445f428a 100644 --- a/libdino/CMakeLists.txt +++ b/libdino/CMakeLists.txt @@ -42,6 +42,7 @@ SOURCES src/service/util.vala src/settings.vala + src/util.vala CUSTOM_VAPIS "${CMAKE_BINARY_DIR}/exports/xmpp-vala.vapi" "${CMAKE_BINARY_DIR}/exports/qlite.vapi" @@ -56,8 +57,17 @@ GENERATE_HEADER dino ) +add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/exports/dino_i18n.h" +COMMAND + cp "${CMAKE_CURRENT_SOURCE_DIR}/src/dino_i18n.h" "${CMAKE_BINARY_DIR}/exports/dino_i18n.h" +DEPENDS + "${CMAKE_CURRENT_SOURCE_DIR}/src/dino_i18n.h" +COMMENT + Copy header file dino_i18n.h +) + add_definitions(${VALA_CFLAGS} -DDINO_PLUGINS_SYSTEM_PLUGIN_DIR="${PLUGIN_INSTALL_DIR}" -DDINO_PLUGINS_SYSTEM_LIBDIR_NAME="${LIBDIR_NAME}") -add_library(libdino SHARED ${LIBDINO_VALA_C}) +add_library(libdino SHARED ${LIBDINO_VALA_C} ${CMAKE_BINARY_DIR}/exports/dino_i18n.h) add_dependencies(libdino xmpp-vala-vapi qlite-vapi) target_link_libraries(libdino xmpp-vala qlite ${LIBDINO_PACKAGES} m) set_target_properties(libdino PROPERTIES PREFIX "" VERSION 0.0 SOVERSION 0) diff --git a/libdino/src/application.vala b/libdino/src/application.vala index 37fbda8b..1ce0bca4 100644 --- a/libdino/src/application.vala +++ b/libdino/src/application.vala @@ -7,6 +7,7 @@ public class Dino.Application : Gtk.Application { public Database db; public StreamInteractor stream_interaction; public Plugins.Registry plugin_registry = new Plugins.Registry(); + public SearchPathGenerator? search_path_generator { get; set; } static string print_xmpp; diff --git a/libdino/src/dino_i18n.h b/libdino/src/dino_i18n.h new file mode 100644 index 00000000..e1a65f41 --- /dev/null +++ b/libdino/src/dino_i18n.h @@ -0,0 +1,8 @@ +#ifndef __DINO_I18N_H__ +#define __DINO_I18N_H__ + +#include + +#define dino_gettext(String) ((char *) dgettext (GETTEXT_PACKAGE, String)) + +#endif \ No newline at end of file diff --git a/libdino/src/util.vala b/libdino/src/util.vala new file mode 100644 index 00000000..29186aa0 --- /dev/null +++ b/libdino/src/util.vala @@ -0,0 +1,37 @@ +namespace Dino { + +public class SearchPathGenerator { + + public string? exec_path { get; private set; } + + public SearchPathGenerator(string? exec_path) { + this.exec_path = exec_path; + } + + public string get_locale_path(string gettext_package, string locale_install_dir) { + string? locale_dir = null; + if (Path.get_dirname(exec_path).contains("dino") || Path.get_dirname(exec_path) == "." || Path.get_dirname(exec_path).contains("build")) { + string exec_locale = Path.build_filename(Path.get_dirname(exec_path), "locale"); + if (FileUtils.test(Path.build_filename(exec_locale, "en", "LC_MESSAGES", gettext_package + ".mo"), FileTest.IS_REGULAR)) { + locale_dir = exec_locale; + } + } + return locale_dir ?? locale_install_dir; + } +} + +[CCode (cname = "dino_gettext", cheader_filename = "dino_i18n.h")] +public static extern unowned string _(string s); + +[CCode (cname = "bindtextdomain", cheader_filename = "libintl.h")] +private static extern unowned string? bindtextdomain(string domainname, string? dirname); + +[CCode (cname = "bind_textdomain_codeset", cheader_filename = "libintl.h")] +private static extern unowned string? bind_textdomain_codeset(string domainname, string? codeset); + +public static void internationalize(string gettext_package, string locales_dir) { + Intl.bind_textdomain_codeset(gettext_package, "UTF-8"); + Intl.bindtextdomain(gettext_package, locales_dir); +} + +} \ No newline at end of file diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 66362fbe..bada486c 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,3 +1,8 @@ +set(GETTEXT_PACKAGE "dino") +find_package(Gettext) +include(${GETTEXT_USE_FILE}) +gettext_compile(${GETTEXT_PACKAGE} SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/po TARGET_NAME ${GETTEXT_PACKAGE}-translations) + find_packages(MAIN_PACKAGES REQUIRED Gee GLib>=2.38 @@ -106,9 +111,9 @@ GRESOURCES ${MAIN_GRESOURCES_XML} ) -add_definitions(${VALA_CFLAGS}) +add_definitions(${VALA_CFLAGS} -DGETTEXT_PACKAGE=\"${GETTEXT_PACKAGE}\" -DLOCALE_INSTALL_DIR=\"${LOCALE_INSTALL_DIR}\") add_executable(dino ${MAIN_VALA_C} ${MAIN_GRESOURCES_TARGET}) -add_dependencies(dino dino-vapi dino-gsettings-schema-compiled) +add_dependencies(dino dino-vapi dino-gsettings-schema-compiled ${GETTEXT_PACKAGE}-translations) target_link_libraries(dino libdino ${MAIN_PACKAGES}) if(WIN32) @@ -129,4 +134,4 @@ install(FILES data/icons/dino-tick-symbolic.svg DESTINATION ${ICON_INSTALL_DIR}/hicolor/scalable/status -) +) \ No newline at end of file diff --git a/main/data/add_conversation/add_contact_dialog.ui b/main/data/add_conversation/add_contact_dialog.ui index 533591f5..3e99b2cc 100644 --- a/main/data/add_conversation/add_contact_dialog.ui +++ b/main/data/add_conversation/add_contact_dialog.ui @@ -8,7 +8,7 @@ True - Cancel + Cancel True True @@ -20,7 +20,7 @@ True True - Add + Add False True