From 967ea267f537dfeb9a3e8eb8169899ac199e50d9 Mon Sep 17 00:00:00 2001 From: Wu Xiaotian Date: Sun, 9 Jun 2019 21:57:54 +0800 Subject: check both {$prefix,/usr}/share/locale dirs for translation --- libmate-desktop/mate-languages.c | 46 +++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/libmate-desktop/mate-languages.c b/libmate-desktop/mate-languages.c index 865c5ca..f6a4ff6 100644 --- a/libmate-desktop/mate-languages.c +++ b/libmate-desktop/mate-languages.c @@ -325,25 +325,12 @@ language_name_get_codeset_details (const char *language_name, setlocale (LC_CTYPE, old_locale); } -/** - * mate_language_has_translations: - * @code: an ISO 639 code string - * - * Returns %TRUE if there are translations for language @code. - * - * Return value: %TRUE if there are translations for language @code. - * - * Since: 1.22 - */ -gboolean -mate_language_has_translations (const char *code) +static gboolean +locale_dir_has_mo_files (const gchar* path) { GDir *dir; const char *name; gboolean has_translations; - g_autofree char *path = NULL; - - path = g_build_filename (MATELOCALEDIR, code, "LC_MESSAGES", NULL); has_translations = FALSE; dir = g_dir_open (path, 0, NULL); @@ -370,6 +357,35 @@ mate_language_has_translations (const char *code) return has_translations; } +/** + * mate_language_has_translations: + * @code: an ISO 639 code string + * + * Returns %TRUE if there are translations for language @code. + * + * Return value: %TRUE if there are translations for language @code. + * + * Since: 1.22 + */ +gboolean +mate_language_has_translations (const char *code) +{ + gboolean has_translations; + gchar *path = NULL; + + path = g_build_filename (MATELOCALEDIR, code, "LC_MESSAGES", NULL); + has_translations = locale_dir_has_mo_files (path); + + if (!has_translations) { + g_free(path); + path = g_build_filename ("/usr/share/locale", code, "LC_MESSAGES", NULL); + has_translations = locale_dir_has_mo_files (path); + } + + g_free(path); + return has_translations; +} + static gboolean add_locale (const char *language_name, gboolean utf8_only) -- cgit v1.2.1