static int lang_collate (gconstpointer a, gconstpointer b) { gboolean clean; Language *l1 = find_lang ((const char *)a, &clean); Language *l2 = find_lang ((const char *)b, &clean); /* paranoia */ if (l1 == NULL || l2 == NULL) return 0; if (l1->collate_key == NULL) { const char *name; name = strchr (_(l1->name), '|'); if (name != NULL) name++; else name = _(l1->name); l1->collate_key = g_utf8_collate_key (name, -1); } if (l2->collate_key == NULL) { const char *name; name = strchr (_(l2->name), '|'); if (name != NULL) name++; else name = _(l2->name); l2->collate_key = g_utf8_collate_key (name, -1); } return strcmp (l1->collate_key, l2->collate_key); }
char * mdm_lang_name (const char *language, gboolean never_encoding, gboolean no_group, gboolean untranslated, gboolean markup) { Language *lang; char *name; gboolean clean; const char *encoding; mdm_lang_init (); lang = find_lang (language, &clean); if (lang == NULL) return g_strdup (language); encoding = strchr (language, '.'); if (encoding == NULL) encoding = strchr (language, '@'); /* treat a modifier without a codeset as an encoding */ if (encoding != NULL) encoding++; /* if more then one language in the language file with this * locale, then hell, include the encoding to differentiate them */ if (lang->found > 1 && encoding != NULL && ! never_encoding) name = g_strdup_printf ("%s (%s)", _(lang->name), encoding); else name = g_strdup (_(lang->name)); if (lang->untranslated != NULL && untranslated) { char *full; full = g_strdup_printf ("%s (%s)", name, lang->untranslated); g_free (name); name = full; } if (no_group) { char *p = strchr (name, '|'); if (p != NULL) { p = g_strdup (p + 1); g_free (name); name = p; } } return name; }
/* NULL if not found */ char * mdm_lang_untranslated_name (const char *language, gboolean markup) { Language *lang; gboolean clean; mdm_lang_init (); lang = find_lang (language, &clean); if (lang == NULL) return NULL; return g_strdup (lang->untranslated); }
gboolean mdm_lang_name_translated (const char *language) { Language *lang; gboolean clean; mdm_lang_init (); lang = find_lang (language, &clean); if (lang == NULL) return FALSE; if (strcmp (lang->name, _(lang->name)) == 0) return FALSE; return TRUE; }
void get_langs(User *user) { struct lang *ptr; struct lang *lang; int vote, i, j; for(i = 0; i < user->watch_count; i++) { for(j = 0; j < user->watch[i]->lang_count; j++) { lang = user->watch[i]->langs + j; vote = lang->weight; /* If lang isn't in user list */ if((ptr = find_lang(lang->id, user->langs)) == NULL) { ptr = user->langs + user->lang_count; user->lang_count++; } ptr->weight += vote; ptr->id = lang->id; } } qsort(user->langs, LANGS, sizeof(struct lang), &compare_langs); }
GList * mdm_lang_read_locale_file (const char *locale_file) { FILE *langlist; char curline[256]; GList *langs = NULL; GHashTable *dupcheck; Language *language; gboolean clean; char *getsret; char *p; if (locale_file == NULL) return NULL; VE_IGNORE_EINTR (langlist = fopen (locale_file, "r")); if (langlist == NULL) return NULL; mdm_lang_init (); dupcheck = g_hash_table_new (g_str_hash, g_str_equal); for (;;) { char *name; char *lang; char **lang_list; int i; VE_IGNORE_EINTR (getsret = fgets (curline, sizeof (curline), langlist)); if (getsret == NULL) break; if (curline[0] <= ' ' || curline[0] == '#') continue; name = strtok (curline, " \t\r\n"); if (name == NULL) continue; lang = strtok (NULL, " \t\r\n"); if (lang == NULL) continue; lang_list = g_strsplit (lang, ",", -1); if (lang_list == NULL) continue; lang = NULL; for (i = 0; lang_list[i] != NULL; i++) { if (ve_locale_exists (lang_list[i])) { lang = lang_list[i]; break; } } if (lang == NULL || g_hash_table_lookup (dupcheck, lang) != NULL) { g_strfreev (lang_list); continue; } language = find_lang (lang, &clean); if (language != NULL) { language->found++; } else { language = g_new0 (Language, 1); language->found = 1; /* add a space before an open bracket to match the style used in the internal list. e.g. change "English(India)" to "English (India)" */ p = strchr (name, '('); if (p != NULL && p > name && *(p-1) != ' ') { *p = 0; language->name= g_strconcat (name, " (", p+1, NULL); } else language->name = g_strdup (name); /* only store the "lang_country" part of the locale code, so that we notice * if there is more than one encoding of this language. See bug 132629. */ p = strchr (lang, '.'); if (p == NULL) p = strchr (lang, '@'); if (p != NULL) language->code = g_strndup (lang, (p - lang)); else language->code = g_strdup (lang); language->untranslated = NULL; g_hash_table_insert (lang_names, language->code, language); } langs = g_list_prepend (langs, g_strdup (lang)); g_hash_table_insert (dupcheck, g_strdup (lang), GINT_TO_POINTER (1)); g_strfreev (lang_list); } g_hash_table_foreach (dupcheck, (GHFunc) g_free, NULL); g_hash_table_destroy (dupcheck); langs = g_list_sort (langs, lang_collate); VE_IGNORE_EINTR (fclose (langlist)); return langs; }
void QAbstractLangList::updateLangList() { ZDEBUG clear(); QString sysLang; #ifdef QAbstractLangList_QT4 sysLang=QLocale::system().name(); qDebug()<<"system language is: "+sysLang; #else # ifndef NO_EZX SETUP_SET_Manager mgr(d->cfg, false); sysLang=ZLanguage::getSystemLanguageCode(); # endif //NO_EZX qDebug("system language is: "+sysLang); #endif //QAbstractLangList_QT4 //QString qmPath=QDir::currentDirPath()+"/i18n"; QDir dir(d->qmDir);//Path); //filter #ifdef QAbstractLangList_QT4 d->qms = dir.entryList(QStringList(QString("%1-*.qm").arg(d->qmFilter))); //d->qms = d->qms.filter(QRegExp("^[^q][^l][^a][^n][^g][^c][^o][^m][^b][^o]")); #else # ifdef NO_EZX d->qms = dir.entryList(QString("%1-*.qm").arg(d->qmFilter)); # else d->qms = dir.entryList(QString("%1_*.qm").arg(d->qmFilter)); //zh_CN //d->qms = d->qms.grep(QRegExp("^[^q][^l][^a][^n][^g][^c][^o][^m][^b][^o]")); # endif //NO_EZX #endif QString sysLangQm; #ifdef NO_EZX QSettings settings(d->cfg,QSettings::NativeFormat); #endif //NO_EZX int i=0; // QTranslator translator(0); for (; i < (int)d->qms.count(); ++i) { //translator.load(d->qms[i], qmDir);//qmPath); QString locale = d->qms[i]; /* if(locale.contains("qabstractlanglist")) { #ifdef QAbstractLangList_QT4 d->qms.removeAt(i); #else d->qms.remove(d->qms[i]); #endif //QAbstractLangList_QT4 --i; continue; } */ //how to set item text if QAbstractLangList have been built into a library? #ifdef NO_EZX # ifdef QAbstractLangList_QT4 locale.remove(0, locale.indexOf('-') + 1); locale.chop(3); //locale=lc_cc, e.g. zh_CN //if(translator.load("qabstractlanglist-"+locale,d->thisQmDir)) qDebug("load succesful");; //QString language = translator.translate("Languages","TranslateMe"); // insertItem(i,tr("%1").arg(language)); # else locale = locale.mid(locale.find('-') + 1); locale.truncate(locale.find('.')); # endif //QAbstractLangList_QT4 settings.setValue(QString("Languages/Language-%1").arg(i),locale); QString language=QLocale::languageToString(QLocale(locale).language()); #else locale = locale.mid(locale.find('_') + 1); //locale=lc-cc, e.g. zh-cn locale.truncate(locale.find('.')); mgr.setSettingInfo("Languages", QString("Language-%1").arg(i),locale,true); QString language=locale; //if(translator.load("qabstractlanglist-"+locale,d->thisQmDir)) qDebug("load succesful");; //QTranslatorMessage message = translator.findMessage("Languages", "TranslateMe",""); //QString language = message.translation(); #endif //NO_EZX insertItem(i,find_lang(language),flag(locale)); if(sysLang==locale) { d->haveSysLangCode=true; sysLangQm=d->qms[i]; } } qDebug("qm total: %d\n ",d->qms.count()); if(d->haveSysLangCode) { d->qms<<sysLangQm; #ifdef NO_EZX settings.setValue(QString("Languages/Language-%1").arg(i),"sys");//sysLang); #else mgr.setSettingInfo("Languages", QString("Language-%1").arg(i),"sys",true);//sysLang,true); #endif //NO_EZX insertItem(i,find_syslang(sysLang),flag(sysLang)); } //2010-04-17; we need set currentIndex after setQmDir() d->langIndexOld=langIndex(d->languageCode); //if(translator.load(d->qms[d->langIndexOld], qmDir)) qDebug("load succesful");; setCurrentIndex(d->langIndexOld); }