void I18n_BindTextDomain(const char *domain, const char *lang, const char *catdir) { gchar *file; gchar *usrlang = NULL; MsgState *state = MsgGetState(); MsgCatalog *catalog; ASSERT(domain); /* * If the caller has asked for the default user language, detect it and * translate to our internal language string representation. */ if (lang == NULL || *lang == '\0') { usrlang = MsgGetUserLanguage(); lang = usrlang; } /* * XXX may want to handle a NULL 'catdir', and look in relative * to the installed location. */ g_debug("%s: user locale=%s\n", __FUNCTION__, lang); file = g_strdup_printf("%s%smessages%s%s%s%s.vmsg", catdir, DIRSEPS, DIRSEPS, lang, DIRSEPS, domain); if (!g_file_test(file, G_FILE_TEST_IS_REGULAR)) { /* * If we couldn't find the catalog file for the user's language, see if * we can find a more generic language (e.g., for "en_US", also try "en"). */ char *sep = strrchr(lang, '_'); if (sep != NULL) { if (usrlang == NULL) { usrlang = g_strdup(lang); } usrlang[sep - lang] = '\0'; g_free(file); file = g_strdup_printf("%s%smessages%s%s%s%s.vmsg", catdir, DIRSEPS, DIRSEPS, usrlang, DIRSEPS, domain); } } catalog = MsgLoadCatalog(file); if (catalog == NULL) { if (strncmp(lang, "en", 2)) { /* * Don't warn about english dictionary, which may not exist (it is the * default translation). */ g_message("Cannot load message catalog for domain '%s', language '%s', " "catalog dir '%s'.\n", domain, lang, catdir); } } else { g_static_mutex_lock(&state->lock); MsgSetCatalog(domain, catalog); g_static_mutex_unlock(&state->lock); } g_free(file); g_free(usrlang); }
void VMTools_BindTextDomain(const char *domain, const char *lang, const char *catdir) { char *dfltdir = NULL; gchar *file; gchar *usrlang = NULL; MsgState *state = MsgGetState(); MsgCatalog *catalog; ASSERT(domain); /* * If the caller has asked for the default user language, detect it and * translate to our internal language string representation. */ if (lang == NULL || *lang == '\0') { usrlang = MsgGetUserLanguage(); lang = usrlang; } g_debug("%s: user locale=%s\n", __FUNCTION__, lang); /* * Use the default install directory if none is provided. */ if (catdir == NULL) { #if defined(OPEN_VM_TOOLS) dfltdir = Util_SafeStrdup(VMTOOLS_DATA_DIR); #else dfltdir = GuestApp_GetInstallPath(); #endif catdir = (dfltdir) ? dfltdir : "."; } file = g_strdup_printf("%s%smessages%s%s%s%s.vmsg", catdir, DIRSEPS, DIRSEPS, lang, DIRSEPS, domain); if (!File_IsFile(file)) { /* * If we couldn't find the catalog file for the user's language, see if * we can find a more generic language (e.g., for "en_US", also try "en"). */ char *sep = Str_Strrchr(lang, '_'); if (sep != NULL) { if (usrlang == NULL) { usrlang = Util_SafeStrdup(lang); } usrlang[sep - lang] = '\0'; g_free(file); file = g_strdup_printf("%s%smessages%s%s%s%s.vmsg", catdir, DIRSEPS, DIRSEPS, usrlang, DIRSEPS, domain); } } catalog = MsgLoadCatalog(file); if (catalog == NULL) { if (Str_Strncmp(lang, "en", 2)) { /* * Don't warn about english dictionary, which may not exist (it is the * default translation). */ g_message("Cannot load message catalog for domain '%s', language '%s', " "catalog dir '%s'.\n", domain, lang, catdir); } } else { g_static_mutex_lock(&state->lock); MsgSetCatalog(domain, catalog); g_static_mutex_unlock(&state->lock); } g_free(file); free(dfltdir); g_free(usrlang); }