static void json_keyword(cJSON *json, struct locale *lang) { cJSON *child; if (json->type != cJSON_Object) { log_error("keywords for locale `%s` not a json object: %d", locale_name(lang), json->type); return; } for (child = json->child; child; child = child->next) { keyword_t kwd = findkeyword(child->string); if (kwd != NOKEYWORD) { if (child->type == cJSON_String) { init_keyword(lang, kwd, child->valuestring); locale_setstring(lang, mkname("keyword", keywords[kwd]), child->valuestring); } else if (child->type == cJSON_Array) { cJSON *entry; for (entry = child->child; entry; entry = entry->next) { init_keyword(lang, kwd, entry->valuestring); if (entry == child->child) { locale_setstring(lang, mkname("keyword", keywords[kwd]), entry->valuestring); } } } else { log_error("invalid type %d for keyword `%s`", child->type, child->string); } } else { log_error("unknown keyword `%s` for locale `%s`", child->string, locale_name(lang)); } } }
static void json_skill(cJSON *json, struct locale *lang) { cJSON *child; if (json->type != cJSON_Object) { log_error("skill for locale `%s` not a json object: %d", locale_name(lang), json->type); return; } for (child = json->child; child; child = child->next) { skill_t sk = findskill(child->string); if (sk != NOSKILL) { if (child->type == cJSON_String) { init_skill(lang, sk, child->valuestring); locale_setstring(lang, mkname("skill", skillnames[sk]), child->valuestring); } else if (child->type == cJSON_Array) { cJSON *entry; for (entry = child->child; entry; entry = entry->next) { init_skill(lang, sk, entry->valuestring); if (entry == child->child) { locale_setstring(lang, mkname("skill", skillnames[sk]), entry->valuestring); } } } else { log_error("invalid type %d for skill `%s`", child->type, child->string); } } else { log_error("unknown skill `%s` for locale `%s`", child->string, locale_name(lang)); } } }
nrmessage_type *nrt_find(const struct locale * lang, const struct message_type * mtype) { nrmessage_type *found = NULL; unsigned int hash = hashstring(mtype->name) % NRT_MAXHASH; nrmessage_type *type = nrtypes[hash]; while (type) { if (type->mtype == mtype) { if (found == NULL) found = type; else if (type->lang == NULL) found = type; if (lang == type->lang) { found = type; break; } } type = type->next; } if (!found) { log_warning("could not find nr-type %s for locale %s\n", mtype->name, locale_name(lang)); } if (lang && found && found->lang != lang) { log_warning("could not find nr-type %s for locale %s, using %s\n", mtype->name, locale_name(lang), locale_name(found->lang)); } return found; }
void GeneralPage::openTranslationFileDialog() { Settings& settings = Settings::getInstance(); const QString translation_file_key(settings.getSettingPath(Settings::General_TranslationFile)); const QString language_key(settings.getSettingPath(Settings::General_Language)); QString current_filename(settings.getSetting(Settings::General_Language).toString()); if (changes.contains(translation_file_key)) current_filename = changes[translation_file_key].toString(); QString filename = QFileDialog::getOpenFileName(this, tr("Open translation"), current_filename, tr("Translation files (*.qm)")); if (!filename.isNull()) { QString locale_name(TranslationUtil::localeNameForFile(filename)); if (locale_name.isEmpty()) { QMessageBox::critical(this, tr("Open translation"), tr("The selected file is not a valid translation.") ); } else { QLocale locale(locale_name); changes.insert(translation_file_key, filename); changes.insert(language_key, locale.language()); } } updateLanguageBox(); }
// slot void GeneralSettingsPage::openTranslationFileDialog() { QString filename = translation_file; if (filename.isEmpty()) filename = getSetting(Settings::General_TranslationFile).toString(); filename = QFileDialog::getOpenFileName(this, tr("Open translation"), filename, tr("Translation files (*.qm)")); if (!filename.isNull()) { QString locale_name(TranslationUtil::localeNameForFile(filename)); if (locale_name.isEmpty()) { QMessageBox::critical(this, tr("Open translation"), tr("The selected file is not a valid translation.") ); } else { translation_file = filename; updateLanguageBox(QLocale(locale_name).language()); } } }
static void json_direction(cJSON *json, struct locale *lang) { cJSON *child; if (json->type!=cJSON_Object) { log_error("directions for locale `%s` not a json object: %d", locale_name(lang), json->type); return; } for (child=json->child;child;child=child->next) { direction_t dir = finddirection(child->string); if (dir!=NODIRECTION) { if (child->type==cJSON_String) { init_direction(lang, dir, child->valuestring); } else if (child->type==cJSON_Array) { cJSON *entry; for (entry=child->child;entry;entry=entry->next) { init_direction(lang, dir, entry->valuestring); } } else { log_error("invalid type %d for direction `%s`", child->type, child->string); } } } }
void register_special_direction(struct locale *lang, const char *name) { const char *token = locale_string(lang, name, false); if (token) { void **tokens = get_translations(lang, UT_SPECDIR); variant var; char *str = strdup(name); var.v = str; addtoken((struct tnode **)tokens, token, var); if (lang == locales) { dir_lookup *dl = malloc(sizeof(dir_lookup)); dl->name = str; dl->oldname = token; dl->next = dir_name_lookup; dir_name_lookup = dl; } } else { log_debug("no translation for spec_direction '%s' in locale '%s'\n", name, locale_name(lang)); } }
static Variant get_icu_value(const String &locale, LocaleTag tag, bool fromParseLocale = false) { String locale_name(locale); if (tag != LOC_CANONICALIZE) { if (getGrandfatheredOffset(locale) >= 0) { if (tag == LOC_LANG) { return locale; } return false; } if (fromParseLocale) { auto localecstr = locale.c_str(); if (tag == LOC_LANG && locale.size() > 1 && isIDPrefix(localecstr)) { return locale; } int pos = singleton_pos(locale); if (pos == 0) { return null_string; } else if (pos > 0) { locale_name = f_substr(locale, 0, pos - 1); } } } int32_t (*ulocfunc)(const char *loc, char *val, int32_t len, UErrorCode *err); switch (tag) { case LOC_SCRIPT: ulocfunc = uloc_getScript; break; case LOC_LANG: ulocfunc = uloc_getLanguage; break; case LOC_REGION: ulocfunc = uloc_getCountry; break; case LOC_VARIANT: ulocfunc = uloc_getVariant; break; case LOC_CANONICALIZE: ulocfunc = uloc_canonicalize; break; default: assert(false); return false; } String buf(64, ReserveString); do { UErrorCode error = U_ZERO_ERROR; int32_t len = ulocfunc(locale_name.c_str(), buf->mutableData(), buf->capacity(), &error); if (error != U_BUFFER_OVERFLOW_ERROR && error != U_STRING_NOT_TERMINATED_WARNING) { if (U_FAILURE(error)) { s_intl_error->setError(error, "unable to get locale info"); return false; } buf.setSize(len); return buf; } if (len <= buf->capacity()) { // Avoid infinite loop s_intl_error->setError(U_INTERNAL_PROGRAM_ERROR, "Got invalid response from ICU"); return false; } buf = String(len, ReserveString); } while (true); not_reached(); return false; }
void report_summary(summary * s, summary * o, bool full) { FILE *F = NULL; int i, newplayers = 0; faction *f; char zText[MAX_PATH]; if (full) { sprintf(zText, "%s/parteien.full", basepath()); } else { sprintf(zText, "%s/parteien", basepath()); } F = fopen(zText, "w"); if (!F) { perror(zText); return; } #ifdef SUMMARY_BOM else { const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 }; fwrite(utf8_bom, 1, 3, F); } #endif log_info("writing summary to file: parteien.\n"); fprintf(F, "%s\n%s\n\n", game_name(), gamedate2(default_locale)); fprintf(F, "Auswertung Nr: %d\n\n", turn); fprintf(F, "Parteien: %s\n", pcomp(s->factions, o->factions)); fprintf(F, "Einheiten: %s\n", pcomp(s->nunits, o->nunits)); fprintf(F, "Spielerpopulation: %s\n", pcomp(s->playerpop, o->playerpop)); fprintf(F, " davon bewaffnet: %s\n", pcomp(s->armed_men, o->armed_men)); fprintf(F, " Helden: %s\n", pcomp(s->heroes, o->heroes)); if (full) { fprintf(F, "Regionen: %d\n", listlen(regions)); fprintf(F, "Bewohnte Regionen: %d\n", s->inhabitedregions); fprintf(F, "Landregionen: %d\n", s->landregionen); fprintf(F, "Spielerregionen: %d\n", s->regionen_mit_spielern); fprintf(F, "Landspielerregionen: %d\n", s->landregionen_mit_spielern); fprintf(F, "Orkifizierte Regionen: %d\n", s->orkifizierte_regionen); fprintf(F, "Inaktive Vulkane: %d\n", s->inactive_volcanos); fprintf(F, "Aktive Vulkane: %d\n\n", s->active_volcanos); } for (i = 0; i < MAXRACES; i++) { if (i != RC_TEMPLATE && i != RC_CLONE && s->factionrace[i]) { const race *rc = get_race(i); if (rc && playerrace(rc)) { fprintf(F, "%13s%s: %s\n", LOC(default_locale, rc_name(rc, NAME_CATEGORY)), LOC(default_locale, "stat_tribe_p"), pcomp(s->factionrace[i], o->factionrace[i])); } } } if (full) { fprintf(F, "\n"); { struct language *plang = s->languages; while (plang != NULL) { struct language *olang = o->languages; int nold = 0; while (olang && olang->locale != plang->locale) olang = olang->next; if (olang) nold = olang->number; fprintf(F, "Sprache %12s: %s\n", locale_name(plang->locale), rcomp(plang->number, nold)); plang = plang->next; } } } fprintf(F, "\n"); if (full) { for (i = 0; i < MAXRACES; i++) { if (s->poprace[i]) { const race *rc = get_race(i); fprintf(F, "%20s: %s\n", LOC(default_locale, rc_name(rc, NAME_PLURAL)), rcomp(s->poprace[i], o->poprace[i])); } } } else { for (i = 0; i < MAXRACES; i++) { if (i != RC_TEMPLATE && i != RC_CLONE && s->poprace[i]) { const race *rc = get_race(i); if (playerrace(rc)) { fprintf(F, "%20s: %s\n", LOC(default_locale, rc_name(rc, NAME_PLURAL)), rcomp(s->poprace[i], o->poprace[i])); } } } } if (full) { fprintf(F, "\nWaffen: %s\n", pcomp(s->waffen, o->waffen)); fprintf(F, "Ruestungen: %s\n", pcomp(s->ruestungen, o->ruestungen)); fprintf(F, "ungezaehmte Pferde: %s\n", pcomp(s->pferde, o->pferde)); fprintf(F, "gezaehmte Pferde: %s\n", pcomp(s->spielerpferde, o->spielerpferde)); fprintf(F, "Schiffe: %s\n", pcomp(s->schiffe, o->schiffe)); fprintf(F, "Gebaeude: %s\n", pcomp(s->gebaeude, o->gebaeude)); fprintf(F, "\nBauernpopulation: %s\n", pcomp(s->peasants, o->peasants)); fprintf(F, "Population gesamt: %d\n\n", s->playerpop + s->peasants); fprintf(F, "Reichtum Spieler: %s Silber\n", pcomp(s->playermoney, o->playermoney)); fprintf(F, "Reichtum Bauern: %s Silber\n", pcomp(s->peasantmoney, o->peasantmoney)); fprintf(F, "Reichtum gesamt: %s Silber\n\n", pcomp(s->playermoney + s->peasantmoney, o->playermoney + o->peasantmoney)); } fprintf(F, "\n\n"); newplayers = update_nmrs(); for (i = 0; i <= NMRTimeout(); ++i) { if (i == NMRTimeout()) { fprintf(F, "+ NMR:\t\t %d\n", nmrs[i]); } else { fprintf(F, "%d NMR:\t\t %d\n", i, nmrs[i]); } } if (age) { if (age[2] != 0) { fprintf(F, "Erstabgaben:\t %d%%\n", 100 - (dropouts[0] * 100 / age[2])); } if (age[3] != 0) { fprintf(F, "Zweitabgaben:\t %d%%\n", 100 - (dropouts[1] * 100 / age[3])); } } fprintf(F, "Neue Spieler:\t %d\n", newplayers); if (full) { if (factions) fprintf(F, "\nParteien:\n\n"); for (f = factions; f; f = f->next) { out_faction(F, f); } if (NMRTimeout() && full) { fprintf(F, "\n\nFactions with NMRs:\n"); for (i = NMRTimeout(); i > 0; --i) { for (f = factions; f; f = f->next) { if (i == NMRTimeout()) { if (turn - f->lastorders >= i) { out_faction(F, f); } } else { if (turn - f->lastorders == i) { out_faction(F, f); } } } } } } fclose(F); if (full) { log_info("writing date & turn\n"); writeturn(); } free(nmrs); nmrs = NULL; }
static int tolua_faction_get_locale(lua_State * L) { faction *self = (faction *)tolua_tousertype(L, 1, 0); tolua_pushstring(L, locale_name(self->locale)); return 1; }
void report_summary(const summary * s, bool full) { FILE *F = NULL; int newplayers = 0; faction *f; char zText[4096]; int timeout = NMRTimeout(); if (full) { path_join(basepath(), "parteien.full", zText, sizeof(zText)); } else { path_join(basepath(), "parteien", zText, sizeof(zText)); } F = fopen(zText, "w"); if (!F) { perror(zText); return; } #ifdef SUMMARY_BOM else { const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 }; fwrite(utf8_bom, 1, 3, F); } #endif log_info("writing summary to file: parteien.\n"); fprintf(F, "%s\n%s\n\n", game_name(), gamedate2(default_locale)); fprintf(F, "Auswertung Nr: %8d\n\n", turn); fprintf(F, "Parteien: %8d\n", s->factions); fprintf(F, "Einheiten: %8d\n", s->nunits); fprintf(F, "Spielerpopulation: %8d\n", s->playerpop); fprintf(F, " davon bewaffnet: %8d\n", s->armed_men); fprintf(F, " Helden: %8d\n", s->heroes); if (full) { fprintf(F, "Regionen: %8d\n", (int)listlen(regions)); fprintf(F, "Bewohnte Regionen: %8d\n", s->inhabitedregions); fprintf(F, "Landregionen: %8d\n", s->landregionen); fprintf(F, "Spielerregionen: %8d\n", s->regionen_mit_spielern); fprintf(F, "Landspielerregionen: %8d\n", s->landregionen_mit_spielern); fprintf(F, "Inaktive Vulkane: %8d\n", s->inactive_volcanos); fprintf(F, "Aktive Vulkane: %8d\n\n", s->active_volcanos); } summarize_players(s, F); if (full) { fprintf(F, "\n"); { struct language *plang = s->languages; while (plang != NULL) { fprintf(F, "Sprache %2s: %8d\n", locale_name(plang->locale), plang->number); plang = plang->next; } } } fprintf(F, "\n"); summarize_races(s, F, full); if (full) { fprintf(F, "\nWaffen: %8d\n", s->waffen); fprintf(F, "Ruestungen: %8d\n", s->ruestungen); fprintf(F, "ungezaehmte Pferde: %8d\n", s->pferde); fprintf(F, "gezaehmte Pferde: %8d\n", s->spielerpferde); fprintf(F, "Schiffe: %8d\n", s->schiffe); fprintf(F, "Gebaeude: %8d\n", s->gebaeude); fprintf(F, "\nBauernpopulation: %8d\n", s->peasants); fprintf(F, "Population gesamt: %8d\n\n", s->playerpop + s->peasants); fprintf(F, "Reichtum Spieler: %12lld Silber\n", s->playermoney); fprintf(F, "Reichtum Bauern: %12lld Silber\n", s->peasantmoney); fprintf(F, "Reichtum gesamt: %12lld Silber\n\n", s->playermoney + s->peasantmoney); } fprintf(F, "\n"); newplayers = update_nmrs(); if (nmrs) { int i; for (i = 0; i <= timeout; ++i) { if (i == timeout) { fprintf(F, "+ NMR: %3d\n", nmrs[i]); } else { fprintf(F, "%d NMR: %3d\n", i, nmrs[i]); } } } if (age) { if (age[2] != 0) { fprintf(F, "Erstabgaben: %3d%%\n", 100 - (dropouts[0] * 100 / age[2])); } if (age[3] != 0) { fprintf(F, "Zweitabgaben: %3d%%\n", 100 - (dropouts[1] * 100 / age[3])); } } fprintf(F, "Neue Spieler: %d\n", newplayers); if (full) { if (factions) { fprintf(F, "\nParteien:\n\n"); for (f = factions; f; f = f->next) { out_faction(F, f); } } if (timeout>0 && full) { int i; fprintf(F, "\n\nFactions with NMRs:\n"); for (i = timeout; i > 0; --i) { for (f = factions; f; f = f->next) { if (i == timeout) { if (turn - f->lastorders >= i) { out_faction(F, f); } } else { if (turn - f->lastorders == i) { out_faction(F, f); } } } } } } fclose(F); if (full) { log_info("writing date & turn\n"); writeturn(); } free(nmrs); nmrs = NULL; }