From 60a4aa95129e30c512d4f36e249d451865aa1503 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Sun, 16 Jan 2011 22:21:41 +0100 Subject: [PATCH] more preparations --- qcsrc/menu/menu.qc | 6 +++--- qcsrc/menu/stringfilelist.txt | 13 +------------ qcsrc/menu/xonotic/credits.c | 2 +- qcsrc/menu/xonotic/keybinder.c | 2 +- qcsrc/menu/xonotic/mainwindow.c | 4 ++-- qcsrc/menu/xonotic/maplist.c | 8 +++++--- qcsrc/menu/xonotic/playermodel.c | 10 +++++----- qcsrc/menu/xonotic/rootdialog.c | 2 +- qcsrc/menu/xonotic/serverlist.c | 14 +++++++------- qcsrc/menu/xonotic/skinlist.c | 8 ++++---- qcsrc/menu/xonotic/slider_decibels.c | 6 +++--- qcsrc/menu/xonotic/slider_resolution.c | 2 +- qcsrc/menu/xonotic/util.qc | 15 +++++++++++++++ qcsrc/menu/xonotic/util.qh | 2 ++ 14 files changed, 51 insertions(+), 43 deletions(-) diff --git a/qcsrc/menu/menu.qc b/qcsrc/menu/menu.qc index c4797019f..2a8a7a11f 100644 --- a/qcsrc/menu/menu.qc +++ b/qcsrc/menu/menu.qc @@ -115,18 +115,18 @@ void() m_init_delayed = if(cvar_string("menu_skin") != "") { draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin")); - fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ); + fh = fopen(language_file(strcat(draw_currentSkin, "/skinvalues.txt")), FILE_READ); } if(fh < 0) if(cvar_defstring("menu_skin") != "") { draw_currentSkin = strcat("gfx/menu/", cvar_defstring("menu_skin")); - fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ); + fh = fopen(language_file(strcat(draw_currentSkin, "/skinvalues.txt")), FILE_READ); } if(fh < 0) { draw_currentSkin = "gfx/menu/default"; - fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ); + fh = fopen(language_file(strcat(draw_currentSkin, "/skinvalues.txt")), FILE_READ); } draw_currentSkin = strzone(draw_currentSkin); while((s = fgets(fh))) diff --git a/qcsrc/menu/stringfilelist.txt b/qcsrc/menu/stringfilelist.txt index a33e2ac22..f04fe0568 100644 --- a/qcsrc/menu/stringfilelist.txt +++ b/qcsrc/menu/stringfilelist.txt @@ -5,8 +5,7 @@ Guideline: unless in developer-only functions (e.g. *dumptree*) - mark translatable strings with _() - if a translatable string is a strcat monster, change it to sprintf -- if code loads files with text, allow loading - .cvar_string("prvm_language") in preference +- if code loads files with text, use language_filename() - test by: find . -type f -not -name \*.po | xgettext -LC -k_ -f- gamecommand.qc - interesting vi macros: @@ -15,16 +14,6 @@ Guideline: List of files to do: -./xonotic/inputbox.c -./xonotic/keybinder.c -./xonotic/mainwindow.c -./xonotic/maplist.c -./xonotic/playerlist.c -./xonotic/playermodel.c -./xonotic/radiobutton.c -./xonotic/rootdialog.c -./xonotic/serverlist.c -./xonotic/skinlist.c ./xonotic/slider_decibels.c ./xonotic/slider_picmip.c ./xonotic/slider_resolution.c diff --git a/qcsrc/menu/xonotic/credits.c b/qcsrc/menu/xonotic/credits.c index d0131b3fa..daf4d22f9 100644 --- a/qcsrc/menu/xonotic/credits.c +++ b/qcsrc/menu/xonotic/credits.c @@ -30,7 +30,7 @@ void XonoticCreditsList_configureXonoticCreditsList(entity me) { me.configureXonoticListBox(me); // load the file - me.bufferIndex = buf_load(strcat("xonotic-credits.txt.", cvar_string("prvm_language"))); + me.bufferIndex = buf_load(language_filename("xonotic-credits.txt")); if(me.bufferIndex < 0) me.bufferIndex = buf_load("xonotic-credits.txt"); me.nItems = buf_getsize(me.bufferIndex); diff --git a/qcsrc/menu/xonotic/keybinder.c b/qcsrc/menu/xonotic/keybinder.c index 87273b24c..f4a6c5a3e 100644 --- a/qcsrc/menu/xonotic/keybinder.c +++ b/qcsrc/menu/xonotic/keybinder.c @@ -47,7 +47,7 @@ void Xonotic_KeyBinds_Read() string s; Xonotic_KeyBinds_Count = 0; - fh = fopen("keybinds.txt", FILE_READ); + fh = fopen(language_filename("keybinds.txt"), FILE_READ); if(fh < 0) return; while((s = fgets(fh))) diff --git a/qcsrc/menu/xonotic/mainwindow.c b/qcsrc/menu/xonotic/mainwindow.c index 72e5faac3..18fdcf5c0 100644 --- a/qcsrc/menu/xonotic/mainwindow.c +++ b/qcsrc/menu/xonotic/mainwindow.c @@ -19,10 +19,10 @@ ENDCLASS(MainWindow) void DemoButton_Click(entity me, entity other) { - if(me.text == "Do not press this button again!") + if(me.text == _("Do not press this button again!")) DialogOpenButton_Click(me, other); else - me.setText(me, "Do not press this button again!"); + me.setText(me, _("Do not press this button again!")); } void MainWindow_configureMainWindow(entity me) diff --git a/qcsrc/menu/xonotic/maplist.c b/qcsrc/menu/xonotic/maplist.c index 8b5ce6d6a..1390ff3b1 100644 --- a/qcsrc/menu/xonotic/maplist.c +++ b/qcsrc/menu/xonotic/maplist.c @@ -275,20 +275,22 @@ void MapList_LoadMap(entity btn, entity me) m = MapInfo_BSPName_ByID(i); if not(m) { - print("Huh? Can't play this (m is NULL). Refiltering so this won't happen again.\n"); + print(_("Huh? Can't play this (m is NULL). Refiltering so this won't happen again.\n")); + me.refilter(me); return; } if(MapInfo_CheckMap(m)) { localcmd("\nmenu_loadmap_prepare\n"); if(cvar("menu_use_default_hostname")) - localcmd("hostname \"", strdecolorize(cvar_string("_cl_name")), "'s Xonotic server\"\n"); + localcmd("hostname \"", sprintf(_("%s's Xonotic Server"), strdecolorize(cvar_string("_cl_name"))), "\"\n"); MapInfo_LoadMap(m); } else { - print("Huh? Can't play this (invalid game type). Refiltering so this won't happen again.\n"); + print(_("Huh? Can't play this (invalid game type). Refiltering so this won't happen again.\n")); me.refilter(me); + return; } } diff --git a/qcsrc/menu/xonotic/playermodel.c b/qcsrc/menu/xonotic/playermodel.c index bbef3a6b1..ef02224df 100644 --- a/qcsrc/menu/xonotic/playermodel.c +++ b/qcsrc/menu/xonotic/playermodel.c @@ -47,7 +47,7 @@ void XonoticPlayerModelSelector_configureXonoticPlayerModelSelector(entity me) float sortbuf, glob, i; string fn; - glob = search_begin(get_model_datafilename(string_null, -1, "txt"), TRUE, TRUE); + glob = search_begin(language_filename(get_model_datafilename(string_null, -1, "txt")), TRUE, TRUE); if (glob < 0) return; @@ -77,11 +77,11 @@ void XonoticPlayerModelSelector_configureXonoticPlayerModelSelector(entity me) bufstr_set(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_SKIN, ftos(get_model_parameters_modelskin)); get_model_parameters_desc = strcat(get_model_parameters_desc, "\n"); if(get_model_parameters_sex) - get_model_parameters_desc = strcat(get_model_parameters_desc, "\nSex: ", get_model_parameters_sex); + get_model_parameters_desc = strcat(get_model_parameters_desc, sprintf("\nSex: %s", get_model_parameters_sex)); if(get_model_parameters_weight) - get_model_parameters_desc = strcat(get_model_parameters_desc, "\nWeight: ", ftos(get_model_parameters_weight), " kg"); + get_model_parameters_desc = strcat(get_model_parameters_desc, sprintf("\nWeight: %g kg", get_model_parameters_weight)); if(get_model_parameters_age) - get_model_parameters_desc = strcat(get_model_parameters_desc, "\nAge: ", ftos(get_model_parameters_age)); + get_model_parameters_desc = strcat(get_model_parameters_desc, sprintf("\nAge: %g", get_model_parameters_age)); while(substring(get_model_parameters_desc, -1, 1) == "\n") get_model_parameters_desc = substring(get_model_parameters_desc, 0, -2); bufstr_set(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_DESC, get_model_parameters_desc); @@ -171,7 +171,7 @@ void XonoticPlayerModelSelector_draw(entity me) if (me.numModels <= 0) { - draw_CenterText('0.5 0.5 0', "", me.realFontSize, '1 1 1', 0.6, FALSE); + draw_CenterText('0.5 0.5 0', _(""), me.realFontSize, '1 1 1', 0.6, FALSE); return; } diff --git a/qcsrc/menu/xonotic/rootdialog.c b/qcsrc/menu/xonotic/rootdialog.c index efc00822d..e8c9db364 100644 --- a/qcsrc/menu/xonotic/rootdialog.c +++ b/qcsrc/menu/xonotic/rootdialog.c @@ -3,7 +3,7 @@ CLASS(XonoticRootDialog) EXTENDS(XonoticDialog) // still to be customized by user /* ATTRIB(XonoticDialog, closable, float, 1) - ATTRIB(XonoticDialog, title, string, "Form1") // ;) + ATTRIB(XonoticDialog, title, string, _("Form1")) // ;) ATTRIB(XonoticDialog, color, vector, '1 0.5 1') ATTRIB(XonoticDialog, intendedWidth, float, 0) ATTRIB(XonoticDialog, rows, float, 3) diff --git a/qcsrc/menu/xonotic/serverlist.c b/qcsrc/menu/xonotic/serverlist.c index 412893579..3cd3338bc 100644 --- a/qcsrc/menu/xonotic/serverlist.c +++ b/qcsrc/menu/xonotic/serverlist.c @@ -354,9 +354,9 @@ void XonoticServerList_draw(entity me) if(me.ipAddressBox.focused || me.ipAddressBoxFocused < 0) { if(IsFavorite(me.ipAddressBox.text)) - me.favoriteButton.setText(me.favoriteButton, "Remove"); + me.favoriteButton.setText(me.favoriteButton, _("Remove")); else - me.favoriteButton.setText(me.favoriteButton, "Bookmark"); + me.favoriteButton.setText(me.favoriteButton, _("Bookmark")); } me.ipAddressBoxFocused = me.ipAddressBox.focused; } @@ -512,11 +512,11 @@ void XonoticServerList_resizeNotify(entity me, vector relOrigin, vector relSize, me.columnTypeOrigin = me.columnMapOrigin + me.columnMapSize + me.realFontSize_x; me.columnPlayersOrigin = me.columnTypeOrigin + me.columnTypeSize + me.realFontSize_x; - me.positionSortButton(me, me.sortButton1, me.columnPingOrigin, me.columnPingSize, "Ping", ServerList_PingSort_Click); - me.positionSortButton(me, me.sortButton2, me.columnNameOrigin, me.columnNameSize, "Host name", ServerList_NameSort_Click); - me.positionSortButton(me, me.sortButton3, me.columnMapOrigin, me.columnMapSize, "Map", ServerList_MapSort_Click); - me.positionSortButton(me, me.sortButton4, me.columnTypeOrigin, me.columnTypeSize, "Type", ServerList_TypeSort_Click); - me.positionSortButton(me, me.sortButton5, me.columnPlayersOrigin, me.columnPlayersSize, "Players", ServerList_PlayerSort_Click); + me.positionSortButton(me, me.sortButton1, me.columnPingOrigin, me.columnPingSize, _("Ping"), ServerList_PingSort_Click); + me.positionSortButton(me, me.sortButton2, me.columnNameOrigin, me.columnNameSize, _("Host name"), ServerList_NameSort_Click); + me.positionSortButton(me, me.sortButton3, me.columnMapOrigin, me.columnMapSize, _("Map"), ServerList_MapSort_Click); + me.positionSortButton(me, me.sortButton4, me.columnTypeOrigin, me.columnTypeSize, _("Type"), ServerList_TypeSort_Click); + me.positionSortButton(me, me.sortButton5, me.columnPlayersOrigin, me.columnPlayersSize, _("Players"), ServerList_PlayerSort_Click); float f; f = me.currentSortField; diff --git a/qcsrc/menu/xonotic/skinlist.c b/qcsrc/menu/xonotic/skinlist.c index 864b3054a..a4f733cf5 100644 --- a/qcsrc/menu/xonotic/skinlist.c +++ b/qcsrc/menu/xonotic/skinlist.c @@ -102,10 +102,10 @@ void XonoticSkinList_getSkins(entity me) { s = search_getfilename(glob, i); bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_NAME, substring(s, 9, strlen(s) - 24)); // the * part - bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_TITLE, ""); - bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_AUTHOR, "<AUTHOR>"); + bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_TITLE, _("<TITLE>")); + bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_AUTHOR, _("<AUTHOR>")); bufstr_set(buf, i * SKINPARM_COUNT + SKINPARM_PREVIEW, strcat("/gfx/menu/", substring(s, 9, strlen(s) - 24), "/skinpreview")); - fh = fopen(s, FILE_READ); + fh = fopen(language_file(s), FILE_READ); if(fh < 0) { print("Warning: can't open skinvalues.txt file\n"); @@ -160,7 +160,7 @@ void XonoticSkinList_drawListBoxItem(entity me, float i, vector absSize, float i draw_Picture(me.columnPreviewOrigin * eX, s, me.columnPreviewSize * eX + eY, '1 1 1', 1); s = me.skinParameter(me, i, SKINPARM_NAME); - s = strcat(s, ": ", me.skinParameter(me, i, SKINPARM_TITLE)); + s = sprintf(_("%s: %s"), s, me.skinParameter(me, i, SKINPARM_TITLE)); s = draw_TextShortenToWidth(s, me.columnNameSize, 0, me.realFontSize); draw_Text(me.realUpperMargin1 * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, SKINCOLOR_SKINLIST_TITLE, SKINALPHA_TEXT, 0); diff --git a/qcsrc/menu/xonotic/slider_decibels.c b/qcsrc/menu/xonotic/slider_decibels.c index 0e4b4e372..6ee8ca7c4 100644 --- a/qcsrc/menu/xonotic/slider_decibels.c +++ b/qcsrc/menu/xonotic/slider_decibels.c @@ -47,10 +47,10 @@ void XonoticDecibelsSlider_saveCvars(entity me) string XonoticDecibelsSlider_valueToText(entity me, float v) { if(v < -33) - return "OFF"; + return _("OFF"); else if(v >= -0.1) - return "MAX"; - return strcat(SUPER(XonoticDecibelsSlider).valueToText(me, v), " dB"); + return _("MAX"); + return sprintf(_("%s dB"), SUPER(XonoticDecibelsSlider).valueToText(me, v)); } #endif diff --git a/qcsrc/menu/xonotic/slider_resolution.c b/qcsrc/menu/xonotic/slider_resolution.c index 0cfa6ad2a..7049f0f3c 100644 --- a/qcsrc/menu/xonotic/slider_resolution.c +++ b/qcsrc/menu/xonotic/slider_resolution.c @@ -62,7 +62,7 @@ entity makeXonoticResolutionSlider() } void XonoticResolutionSlider_addResolution(entity me, float w, float h, float pixelheight) { - me.addValue(me, strzone(strcat(ftos(w), "x", ftos(h))), strzone(strcat(ftos(w), " ", ftos(h), " ", ftos(pixelheight)))); + me.addValue(me, strzone(sprintf(_("%dx%d"), w, h)), strzone(strcat(ftos(w), " ", ftos(h), " ", ftos(pixelheight)))); // FIXME (in case you ever want to dynamically instantiate this): THIS IS NEVER FREED } void XonoticResolutionSlider_configureXonoticResolutionSlider(entity me) diff --git a/qcsrc/menu/xonotic/util.qc b/qcsrc/menu/xonotic/util.qc index 91572fdf9..1bb9a0132 100644 --- a/qcsrc/menu/xonotic/util.qc +++ b/qcsrc/menu/xonotic/util.qc @@ -567,3 +567,18 @@ float GameType_GetCount() return i; } +string language_filename(string s) +{ + string fn; + float fh; + fn = cvar_string("prvm_language"); + if(fn == "" || fn == "dump") + return s; + fn = strcat(s, ".", fn); + if((fh = fopen(fn, FILE_READ)) >= 0) + { + fclose(fh); + return fn; + } + return s; +} diff --git a/qcsrc/menu/xonotic/util.qh b/qcsrc/menu/xonotic/util.qh index df1287ac0..fea001f1d 100644 --- a/qcsrc/menu/xonotic/util.qh +++ b/qcsrc/menu/xonotic/util.qh @@ -98,3 +98,5 @@ float GameType_GetCount(); me.TR(me); \ me.TD(me, 1, 3, e = makeXonoticCheckBox(0, strzone(strcat("hud_panel_", hudpanel)), _("Enable panel"))); \ DIALOG_HUDPANEL_COMMON_NOTOGGLE() + +string language_filename(string s); -- 2.39.2