Improve locale search

This commit is contained in:
Igor Sharonov 2024-04-24 14:59:23 +03:00 committed by Maxim Logaev
parent 901883399f
commit cdabee7f20
4 changed files with 20 additions and 8 deletions

View file

@ -81,6 +81,8 @@ macro(set_path what val desc)
endif() endif()
endmacro(set_path) endmacro(set_path)
set(LOCALEDIR_NAME "share/locale")
string(REGEX REPLACE "^liblib" "lib" LIBDIR_NAME "lib${LIB_SUFFIX}") string(REGEX REPLACE "^liblib" "lib" LIBDIR_NAME "lib${LIB_SUFFIX}")
set_path(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" "Installation directory for architecture-independent files") set_path(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" "Installation directory for architecture-independent files")
set_path(EXEC_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" "Installation directory for architecture-dependent files") set_path(EXEC_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" "Installation directory for architecture-dependent files")
@ -94,7 +96,7 @@ set_path(SERVICE_FILE_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/dbus-1/services" "Ins
set_path(ICON_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/icons" "Installation directory for icons") 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(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(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(LOCALE_INSTALL_DIR "${EXEC_INSTALL_PREFIX}/${LOCALEDIR_NAME}" "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(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") set_path(VAPI_INSTALL_DIR "${SHARE_INSTALL_PREFIX}/vala/vapi" "Installation directory for Vala API files")

View file

@ -102,7 +102,8 @@ DEPENDS
${CMAKE_BINARY_DIR}/exports/dino_i18n.h ${CMAKE_BINARY_DIR}/exports/dino_i18n.h
) )
add_definitions(${VALA_CFLAGS} -DDINO_SYSTEM_PLUGIN_DIR="${PLUGIN_INSTALL_DIR}" -DDINO_SYSTEM_LIBDIR_NAME="${LIBDIR_NAME}" -DG_LOG_DOMAIN="libdino" -DDINO_VERSION=\"${PROJECT_VERSION}\") add_definitions(${VALA_CFLAGS} -DDINO_SYSTEM_PLUGIN_DIR="${PLUGIN_INSTALL_DIR}" -DDINO_SYSTEM_LIBDIR_NAME="${LIBDIR_NAME}" -DG_LOG_DOMAIN="libdino"
-DDINO_VERSION=\"${PROJECT_VERSION}\" -DDINO_SYSTEM_LOCALEDIR_NAME="${LOCALEDIR_NAME}")
add_library(libdino SHARED ${LIBDINO_VALA_C} ${CMAKE_BINARY_DIR}/exports/dino_i18n.h) add_library(libdino SHARED ${LIBDINO_VALA_C} ${CMAKE_BINARY_DIR}/exports/dino_i18n.h)
add_dependencies(libdino dino-vapi) add_dependencies(libdino dino-vapi)
target_link_libraries(libdino xmpp-vala qlite ${LIBDINO_PACKAGES} m) target_link_libraries(libdino xmpp-vala qlite ${LIBDINO_PACKAGES} m)

View file

@ -80,6 +80,7 @@ sources = files(
sources += [version_vala] sources += [version_vala]
c_args = [ c_args = [
'-DDINO_SYSTEM_LIBDIR_NAME="@0@"'.format(get_option('libdir')), '-DDINO_SYSTEM_LIBDIR_NAME="@0@"'.format(get_option('libdir')),
'-DDINO_SYSTEM_LOCALEDIR_NAME="@0@"'.format(get_option('localedir')),
'-DDINO_SYSTEM_PLUGIN_DIR="@0@"'.format(get_option('prefix') / get_option('libdir') / get_option('plugindir')), '-DDINO_SYSTEM_PLUGIN_DIR="@0@"'.format(get_option('prefix') / get_option('libdir') / get_option('plugindir')),
'-DG_LOG_DOMAIN="libdino"', '-DG_LOG_DOMAIN="libdino"',
] ]

View file

@ -2,6 +2,7 @@ namespace Dino {
private extern const string SYSTEM_LIBDIR_NAME; private extern const string SYSTEM_LIBDIR_NAME;
private extern const string SYSTEM_PLUGIN_DIR; private extern const string SYSTEM_PLUGIN_DIR;
private extern const string SYSTEM_LOCALEDIR_NAME;
public class SearchPathGenerator { public class SearchPathGenerator {
@ -12,14 +13,21 @@ public class SearchPathGenerator {
} }
public string get_locale_path(string gettext_package, string locale_install_dir) { public string get_locale_path(string gettext_package, string locale_install_dir) {
string? locale_dir = null; if (exec_path != null) {
if (Path.get_dirname(exec_path).contains("dino") || Path.get_dirname(exec_path) == "." || Path.get_dirname(exec_path).contains("build")) { var exec_dir = Path.get_dirname(exec_path);
string exec_locale = Path.build_filename(Path.get_dirname(exec_path), "locale"); string[] search_paths = new string[] {
if (FileUtils.test(Path.build_filename(exec_locale, "en", "LC_MESSAGES", gettext_package + ".mo"), FileTest.IS_REGULAR)) { Path.build_filename(exec_dir, "locale"),
locale_dir = exec_locale; Path.build_filename(Path.get_dirname(exec_dir), SYSTEM_LOCALEDIR_NAME)
};
foreach (var path in search_paths) {
if (FileUtils.test(Path.build_filename(path, "en", "LC_MESSAGES", gettext_package + ".mo"), FileTest.IS_REGULAR)) {
debug(@"Found locale $(gettext_package).mo in $(path)");
return path;
} }
} }
return locale_dir ?? locale_install_dir; }
return locale_install_dir;
} }
public string[] get_plugin_paths() { public string[] get_plugin_paths() {