Skip to content

Commit 09a50d0

Browse files
sapierPilzAdam
sapier
authored andcommittedAug 17, 2013
Add translation for main menu
Add engine.gettext() and remove gettext() calls in guiFormspecMenu.cpp
1 parent 787b43b commit 09a50d0

13 files changed

+241
-224
lines changed
 

Diff for: ‎builtin/gamemgr.lua

+13-13
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ gamemgr = {}
2020
--------------------------------------------------------------------------------
2121
function gamemgr.dialog_new_game()
2222
local retval =
23-
"label[2,2;Game Name]"..
23+
"label[2,2;" .. fgettext("Game Name") .. "]"..
2424
"field[4.5,2.4;6,0.5;te_game_name;;]" ..
25-
"button[5,4.2;2.6,0.5;new_game_confirm;Create]" ..
26-
"button[7.5,4.2;2.8,0.5;new_game_cancel;Cancel]"
25+
"button[5,4.2;2.6,0.5;new_game_confirm;" .. fgettext("Create") .. "]" ..
26+
"button[7.5,4.2;2.8,0.5;new_game_cancel;" .. fgettext("Cancel") .. "]"
2727

2828
return retval
2929
end
@@ -114,8 +114,8 @@ function gamemgr.handle_edit_game_buttons(fields)
114114
local sourcepath = mod.path
115115

116116
if not gamemgr.add_mod(current_game,sourcepath) then
117-
gamedata.errormessage = "Gamemgr: Unable to copy mod: " ..
118-
mod.name .. " to game: " .. current_game.id
117+
gamedata.errormessage =
118+
fgettext("Gamemgr: Unable to copy mod \"$1\" to game \"$2\"", mod.name, current_game.id)
119119
end
120120
end
121121
end
@@ -200,8 +200,8 @@ function gamemgr.tab()
200200
end
201201

202202
local retval =
203-
"vertlabel[0,-0.25;GAMES]" ..
204-
"label[1,-0.25;Games:]" ..
203+
"vertlabel[0,-0.25;" .. fgettext("GAMES") .. "]" ..
204+
"label[1,-0.25;" .. fgettext("Games") .. ":]" ..
205205
"textlist[1,0.25;4.5,4.4;gamelist;" ..
206206
gamemgr.gamelist() ..
207207
";" .. gamemgr.selected_game .. "]"
@@ -217,11 +217,11 @@ function gamemgr.tab()
217217

218218
retval = retval ..
219219
"field[8,-0.25;6,2;;" .. current_game.name .. ";]"..
220-
"label[6,1.4;Mods:]" ..
221-
"button[9.7,1.5;2,0.2;btn_game_mgr_edit_game;edit game]" ..
220+
"label[6,1.4;" .. fgettext("Mods:") .."]" ..
221+
"button[9.7,1.5;2,0.2;btn_game_mgr_edit_game;" .. fgettext("edit game") .. "]" ..
222222
"textlist[6,2;5.5,3.3;game_mgr_modlist;"
223223
.. gamemgr.get_game_mods(current_game) ..";0]" ..
224-
"button[1,4.75;3.2,0.5;btn_game_mgr_new_game;new game]"
224+
"button[1,4.75;3.2,0.5;btn_game_mgr_new_game;" .. fgettext("new game") .. "]"
225225
end
226226
return retval
227227
end
@@ -231,7 +231,7 @@ function gamemgr.dialog_edit_game()
231231
local current_game = gamemgr.get_game(gamemgr.selected_game)
232232
if current_game ~= nil then
233233
local retval =
234-
"vertlabel[0,-0.25;EDIT GAME]" ..
234+
"vertlabel[0,-0.25;" .. fgettext("EDIT GAME") .."]" ..
235235
"label[0,-0.25;" .. current_game.name .. "]" ..
236236
"button[11.55,-0.2;0.75,0.5;btn_close_edit_game;x]"
237237

@@ -251,10 +251,10 @@ function gamemgr.dialog_edit_game()
251251
.. modmgr.render_modlist() .. ";0]"
252252

253253
retval = retval ..
254-
"button[0.55,4.95;4.7,0.5;btn_remove_mod_from_game;Remove selected mod]"
254+
"button[0.55,4.95;4.7,0.5;btn_remove_mod_from_game;" .. fgettext("Remove selected mod") .."]"
255255

256256
retval = retval ..
257-
"button[7.05,4.95;4.7,0.5;btn_add_mod_to_game;<<-- Add mod]"
257+
"button[7.05,4.95;4.7,0.5;btn_add_mod_to_game;" .. fgettext("<<-- Add mod") .."]"
258258

259259
return retval
260260
end

Diff for: ‎builtin/mainmenu.lua

+125-107
Large diffs are not rendered by default.

Diff for: ‎builtin/misc_helpers.lua

+34-2
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,24 @@ function string:split(sep)
8585
return fields
8686
end
8787

88+
--------------------------------------------------------------------------------
89+
function file_exists(filename)
90+
local f = io.open(filename, "r")
91+
if f==nil then
92+
return false
93+
else
94+
f:close()
95+
return true
96+
end
97+
end
98+
8899
--------------------------------------------------------------------------------
89100
function string:trim()
90101
return (self:gsub("^%s*(.-)%s*$", "%1"))
91102
end
92103

93104
assert(string.trim("\n \t\tfoo bar\t ") == "foo bar")
94105

95-
96-
97106
--------------------------------------------------------------------------------
98107
function math.hypot(x, y)
99108
local t
@@ -209,6 +218,29 @@ if engine ~= nil then
209218

210219
return nil
211220
end
221+
222+
function fgettext(text, ...)
223+
text = engine.gettext(text)
224+
local arg = {n=select('#', ...), ...}
225+
if arg.n >= 1 then
226+
-- Insert positional parameters ($1, $2, ...)
227+
result = ''
228+
pos = 1
229+
while pos <= text:len() do
230+
newpos = text:find('[$]', pos)
231+
if newpos == nil then
232+
result = result .. text:sub(pos)
233+
pos = text:len() + 1
234+
else
235+
paramindex = tonumber(text:sub(newpos+1, newpos+1))
236+
result = result .. text:sub(pos, newpos-1) .. tostring(arg[paramindex])
237+
pos = newpos + 2
238+
end
239+
end
240+
text = result
241+
end
242+
return engine.formspec_escape(text)
243+
end
212244
end
213245
--------------------------------------------------------------------------------
214246
-- core only fct

Diff for: ‎builtin/modmgr.lua

+41-38
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,15 @@ function modmgr.tab()
233233
end
234234

235235
local retval =
236-
"vertlabel[0,-0.25;MODS]" ..
237-
"label[0.8,-0.25;Installed Mods:]" ..
236+
"vertlabel[0,-0.25;".. fgettext("MODS") .. "]" ..
237+
"label[0.8,-0.25;".. fgettext("Installed Mods:") .. "]" ..
238238
"textlist[0.75,0.25;4.5,4.3;modlist;" ..
239239
modmgr.render_modlist(modmgr.global_mods) ..
240240
";" .. modmgr.selected_mod .. "]"
241241

242242
retval = retval ..
243-
"button[1,4.85;2,0.5;btn_mod_mgr_install_local;Install]" ..
244-
"button[3,4.85;2,0.5;btn_mod_mgr_download;Download]"
243+
"button[1,4.85;2,0.5;btn_mod_mgr_install_local;".. fgettext("Install") .. "]" ..
244+
"button[3,4.85;2,0.5;btn_mod_mgr_download;".. fgettext("Download") .. "]"
245245

246246
local selected_mod = nil
247247

@@ -251,11 +251,13 @@ function modmgr.tab()
251251

252252
if selected_mod ~= nil then
253253
if selected_mod.is_modpack then
254-
retval = retval .. "button[10,4.85;2,0.5;btn_mod_mgr_rename_modpack;Rename]"
254+
retval = retval
255+
.. "button[10,4.85;2,0.5;btn_mod_mgr_rename_modpack;" ..
256+
fgettext("Rename") .. "]"
255257
else
256258
--show dependencies
257259
retval = retval ..
258-
"label[6,1.9;Depends:]" ..
260+
"label[6,1.9;".. fgettext("Depends:") .. "]" ..
259261
"textlist[6,2.4;5.7,2;deplist;"
260262

261263
toadd = modmgr.get_dependencies(selected_mod.path)
@@ -265,7 +267,8 @@ function modmgr.tab()
265267
--TODO read modinfo
266268
end
267269
--show delete button
268-
retval = retval .. "button[8,4.85;2,0.5;btn_mod_mgr_delete_mod;Delete]"
270+
retval = retval .. "button[8,4.85;2,0.5;btn_mod_mgr_delete_mod;"
271+
.. fgettext("Delete") .. "]"
269272
end
270273
return retval
271274
end
@@ -276,12 +279,14 @@ function modmgr.dialog_rename_modpack()
276279
local mod = filterlist.get_list(modmgr.modlist)[modmgr.selected_mod]
277280

278281
local retval =
279-
"label[1.75,1;Rename Modpack:]"..
282+
"label[1.75,1;".. fgettext("Rename Modpack:") .. "]"..
280283
"field[4.5,1.4;6,0.5;te_modpack_name;;" ..
281284
mod.name ..
282285
"]" ..
283-
"button[5,4.2;2.6,0.5;dlg_rename_modpack_confirm;Accept]" ..
284-
"button[7.5,4.2;2.8,0.5;dlg_rename_modpack_cancel;Cancel]"
286+
"button[5,4.2;2.6,0.5;dlg_rename_modpack_confirm;"..
287+
fgettext("Accept") .. "]" ..
288+
"button[7.5,4.2;2.8,0.5;dlg_rename_modpack_cancel;"..
289+
fgettext("Cancel") .. "]"
285290

286291
return retval
287292
end
@@ -369,31 +374,32 @@ function modmgr.dialog_configure_world()
369374

370375
local retval =
371376
"size[11,6.5]" ..
372-
"label[1.5,-0.25;World: " .. worldspec.name .. "]"
377+
"label[0.5,-0.25;" .. fgettext("World:") .. "]" ..
378+
"label[1.75,-0.25;" .. worldspec.name .. "]"
373379

374380
if modmgr.hide_gamemods then
375-
retval = retval .. "checkbox[0,5.75;cb_hide_gamemods;Hide Game;true]"
381+
retval = retval .. "checkbox[0,5.75;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";true]"
376382
else
377-
retval = retval .. "checkbox[0,5.75;cb_hide_gamemods;Hide Game;false]"
383+
retval = retval .. "checkbox[0,5.75;cb_hide_gamemods;" .. fgettext("Hide Game") .. ";false]"
378384
end
379385

380386
if modmgr.hide_modpackcontents then
381-
retval = retval .. "checkbox[2,5.75;cb_hide_mpcontent;Hide mp content;true]"
387+
retval = retval .. "checkbox[2,5.75;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";true]"
382388
else
383-
retval = retval .. "checkbox[2,5.75;cb_hide_mpcontent;Hide mp content;false]"
389+
retval = retval .. "checkbox[2,5.75;cb_hide_mpcontent;" .. fgettext("Hide mp content") .. ";false]"
384390
end
385391

386392
if mod == nil then
387393
mod = {name=""}
388394
end
389395
retval = retval ..
390-
"label[0,0.45;Mod:]" ..
396+
"label[0,0.45;" .. fgettext("Mod:") .. "]" ..
391397
"label[0.75,0.45;" .. mod.name .. "]" ..
392-
"label[0,1;Depends:]" ..
398+
"label[0,1;" .. fgettext("Depends:") .. "]" ..
393399
"textlist[0,1.5;5,4.25;world_config_depends;" ..
394400
modmgr.get_dependencies(mod.path) .. ";0]" ..
395-
"button[9.25,6.35;2,0.5;btn_config_world_save;Save]" ..
396-
"button[7.4,6.35;2,0.5;btn_config_world_cancel;Cancel]"
401+
"button[9.25,6.35;2,0.5;btn_config_world_save;" .. fgettext("Save") .. "]" ..
402+
"button[7.4,6.35;2,0.5;btn_config_world_cancel;" .. fgettext("Cancel") .. "]"
397403

398404
if mod ~= nil and mod.name ~= "" then
399405
if mod.is_modpack then
@@ -409,22 +415,21 @@ function modmgr.dialog_configure_world()
409415
end
410416

411417
if all_enabled == false then
412-
retval = retval .. "button[5.5,-0.125;2,0.5;btn_mp_enable;Enable MP]"
418+
retval = retval .. "button[5.5,-0.125;2,0.5;btn_mp_enable;" .. fgettext("Enable MP") .. "]"
413419
else
414-
retval = retval .. "button[5.5,-0.125;2,0.5;btn_mp_disable;Disable MP]"
420+
retval = retval .. "button[5.5,-0.125;2,0.5;btn_mp_disable;" .. fgettext("Disable MP") .. "]"
415421
end
416422
else
417423
if mod.enabled then
418-
retval = retval .. "checkbox[5.5,-0.375;cb_mod_enable;enabled;true]"
424+
retval = retval .. "checkbox[5.5,-0.375;cb_mod_enable;" .. fgettext("enabled") .. ";true]"
419425
else
420-
retval = retval .. "checkbox[5.5,-0.375;cb_mod_enable;enabled;false]"
426+
retval = retval .. "checkbox[5.5,-0.375;cb_mod_enable;" .. fgettext("enabled") .. ";false]"
421427
end
422428
end
423-
424429
end
425430

426431
retval = retval ..
427-
"button[8.5,-0.125;2.5,0.5;btn_all_mods;Enable all]" ..
432+
"button[8.5,-0.125;2.5,0.5;btn_all_mods;" .. fgettext("Enable all") .. "]" ..
428433
"textlist[5.5,0.5;5.5,5.75;world_config_modlist;"
429434

430435
retval = retval .. modmgr.render_modlist(modmgr.modlist)
@@ -540,7 +545,7 @@ function modmgr.handle_modmgr_buttons(fields)
540545
end
541546

542547
if fields["btn_mod_mgr_install_local"] ~= nil then
543-
engine.show_file_open_dialog("mod_mgt_open_dlg","Select Mod File:")
548+
engine.show_file_open_dialog("mod_mgt_open_dlg",fgettext("Select Mod File:"))
544549
end
545550

546551
if fields["btn_mod_mgr_download"] ~= nil then
@@ -579,8 +584,8 @@ function modmgr.installmod(modfilename,basename)
579584
local modpath = modmgr.extract(modfile)
580585

581586
if modpath == nil then
582-
gamedata.errormessage = "Install Mod: file: " .. modfile.name ..
583-
"\nInstall Mod: unsupported filetype \"" .. modfile.type .. "\""
587+
gamedata.errormessage = fgettext("Install Mod: file: \"$1\"", modfile.name) ..
588+
fgettext("\nInstall Mod: unsupported filetype \"$1\"", modfile.type)
584589
return
585590
end
586591

@@ -601,11 +606,10 @@ function modmgr.installmod(modfilename,basename)
601606
if clean_path ~= nil then
602607
local targetpath = engine.get_modpath() .. DIR_DELIM .. clean_path
603608
if not engine.copy_dir(basefolder.path,targetpath) then
604-
gamedata.errormessage = "Failed to install " .. basename .. " to " .. targetpath
609+
gamedata.errormessage = fgettext("Failed to install $1 to $2", basename, targetpath)
605610
end
606611
else
607-
gamedata.errormessage = "Install Mod: unable to find suitable foldername for modpack "
608-
.. modfilename
612+
gamedata.errormessage = fgettext("Install Mod: unable to find suitable foldername for modpack $1", modfilename)
609613
end
610614
end
611615

@@ -625,8 +629,7 @@ function modmgr.installmod(modfilename,basename)
625629
local targetpath = engine.get_modpath() .. DIR_DELIM .. targetfolder
626630
engine.copy_dir(basefolder.path,targetpath)
627631
else
628-
gamedata.errormessage = "Install Mod: unable to find real modname for: "
629-
.. modfilename
632+
gamedata.errormessage = fgettext("Install Mod: unable to find real modname for: $1", modfilename)
630633
end
631634
end
632635

@@ -824,11 +827,11 @@ function modmgr.handle_delete_mod_buttons(fields)
824827
mod.path ~= "" and
825828
mod.path ~= engine.get_modpath() then
826829
if not engine.delete_dir(mod.path) then
827-
gamedata.errormessage ="Modmgr: failed to delete >" .. mod.path .. "<"
830+
gamedata.errormessage = fgettext("Modmgr: failed to delete \"$1\"", mod.path)
828831
end
829832
modmgr.refresh_globals()
830833
else
831-
gamedata.errormessage ="Modmgr: invalid modpath >" .. mod.path .. "<"
834+
gamedata.errormessage = fgettext("Modmgr: invalid modpath \"$1\"", mod.path)
832835
end
833836
end
834837

@@ -845,9 +848,9 @@ function modmgr.dialog_delete_mod()
845848
local mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
846849

847850
local retval =
848-
"field[1.75,1;10,3;;Are you sure you want to delete ".. mod.name .. "?;]"..
849-
"button[4,4.2;1,0.5;dlg_delete_mod_confirm;Yes]" ..
850-
"button[6.5,4.2;3,0.5;dlg_delete_mod_cancel;No of course not!]"
851+
"field[1.75,1;10,3;;" .. fgettext("Are you sure you want to delete \"$1\"?", mod.name) .. ";]"..
852+
"button[4,4.2;1,0.5;dlg_delete_mod_confirm;" .. fgettext("Yes") .. "]" ..
853+
"button[6.5,4.2;3,0.5;dlg_delete_mod_cancel;" .. fgettext("No of course not!") .. "]"
851854

852855
return retval
853856
end

Diff for: ‎builtin/modstore.lua

+5-5
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@ end
180180
--------------------------------------------------------------------------------
181181
function modstore.getmodlist(list)
182182
local retval = ""
183-
retval = retval .. "label[10,-0.4;Page " .. (list.page +1) ..
184-
" of " .. list.pagecount .. "]"
183+
retval = retval .. "label[10,-0.4;" .. fgettext("Page $1 of $2", list.page+1, list.pagecount) .. "]"
185184

186185
retval = retval .. "button[11.6,-0.1;0.5,0.5;btn_modstore_page_up;^]"
187186
retval = retval .. "box[11.6,0.35;0.28,8.6;000000]"
@@ -240,17 +239,18 @@ function modstore.getmodlist(list)
240239
engine.formspec_escape(details.description) .. ";]"
241240
--rating
242241
local ratingy = screenshot_ypos + 0.6
243-
retval = retval .."label[10.1," .. ratingy .. ";Rating: " .. details.rating .."]"
242+
retval = retval .."label[10.1," .. ratingy .. ";" ..
243+
fgettext("Rating") .. ": " .. details.rating .."]"
244244

245245
--install button
246246
local buttony = screenshot_ypos + 1.2
247247
local buttonnumber = (i - (list.page * modstore.modsperpage))
248248
retval = retval .."button[9.6," .. buttony .. ";2,0.5;btn_install_mod_" .. buttonnumber .. ";"
249249

250250
if modmgr.mod_exists(details.basename) then
251-
retval = retval .. "re-Install]"
251+
retval = retval .. fgettext("re-Install") .."]"
252252
else
253-
retval = retval .. "Install]"
253+
retval = retval .. fgettext("Install") .."]"
254254
end
255255
end
256256
end

Diff for: ‎doc/lua_api.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -1068,8 +1068,7 @@ minetest.pos_to_string({x=X,y=Y,z=Z}) -> "(X,Y,Z)"
10681068
^ Convert position to a printable string
10691069
minetest.string_to_pos(string) -> position
10701070
^ Same but in reverse
1071-
minetest.formspec_escape(string) -> string
1072-
^ escapes characters like [, ], and \ that can not be used in formspecs
1071+
^ escapes characters [ ] \ , ; that can not be used in formspecs
10731072

10741073
minetest namespace reference
10751074
-----------------------------

Diff for: ‎doc/menu_lua_api.txt

+7
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ engine.file_open_dialog(formname,caption)
167167
^ returns nil or selected file/folder
168168

169169
Helpers:
170+
engine.formspec_escape(string) -> string
171+
^ escapes characters [ ] \ , ; that can not be used in formspecs
172+
engine.gettext(string) -> string
173+
^ look up the translation of a string in the gettext message catalog
174+
fgettext(string, ...) -> string
175+
^ call engine.gettext(string), replace "$1"..."$9" with the given
176+
^ extra arguments, call engine.formspec_escape and return the result
170177
dump(obj, dumped={})
171178
^ Return object serialized as a string
172179
string:split(separator)

Diff for: ‎src/guiEngine.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ GUIEngine::GUIEngine( irr::IrrlichtDevice* dev,
136136
m_menu->lockSize(true,v2u32(800,600));
137137
m_menu->setFormSource(m_formspecgui);
138138
m_menu->setTextDest(m_buttonhandler);
139-
m_menu->useGettext(true);
140139

141140
// Initialize scripting
142141

Diff for: ‎src/guiFormSpecMenu.cpp

+1-50
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
4444
#include "util/numeric.h"
4545
#include "filesys.h"
4646
#include "gettime.h"
47-
4847
#include "gettext.h"
4948

50-
5149
#define MY_CHECKPOS(a,b) \
5250
if (v_pos.size() != 2) { \
5351
errorstream<< "Invalid pos for element " << a << "specified: \"" \
@@ -88,7 +86,6 @@ GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev,
8886
m_listbox_doubleclick(false),
8987
m_tooltip_element(NULL),
9088
m_allowclose(true),
91-
m_use_gettext(false),
9289
m_lock(false)
9390
{
9491
current_keys_pending.key_down = false;
@@ -379,9 +376,6 @@ void GUIFormSpecMenu::parseCheckbox(parserData* data,std::string element) {
379376

380377
std::wstring wlabel = narrow_to_wide(label.c_str());
381378

382-
if (m_use_gettext)
383-
wlabel = wstrgettext(label);
384-
385379
FieldSpec spec = FieldSpec(
386380
narrow_to_wide(name.c_str()),
387381
L"",
@@ -499,9 +493,6 @@ void GUIFormSpecMenu::parseButton(parserData* data,std::string element,std::stri
499493

500494
std::wstring wlabel = narrow_to_wide(label.c_str());
501495

502-
if (m_use_gettext)
503-
wlabel = wstrgettext(label);
504-
505496
FieldSpec spec = FieldSpec(
506497
narrow_to_wide(name.c_str()),
507498
wlabel,
@@ -609,7 +600,6 @@ void GUIFormSpecMenu::parseTextList(parserData* data,std::string element) {
609600
std::wstring toadd =
610601
narrow_to_wide(unescape_string(items[i]).c_str() + 7);
611602

612-
613603
e->addItem(toadd.c_str());
614604

615605
irr::video::SColor toset;
@@ -733,13 +723,6 @@ void GUIFormSpecMenu::parsePwdField(parserData* data,std::string element) {
733723

734724
std::wstring wlabel = narrow_to_wide(label.c_str());
735725

736-
if (m_use_gettext) {
737-
if (label.length() > 1)
738-
wlabel = wstrgettext(label);
739-
else
740-
wlabel = L"";
741-
}
742-
743726
FieldSpec spec = FieldSpec(
744727
narrow_to_wide(name.c_str()),
745728
wlabel,
@@ -812,13 +795,6 @@ void GUIFormSpecMenu::parseSimpleField(parserData* data,std::vector<std::string>
812795

813796
std::wstring wlabel = narrow_to_wide(label.c_str());
814797

815-
if (m_use_gettext) {
816-
if (label.length() > 1)
817-
wlabel = wstrgettext(label);
818-
else
819-
wlabel = L"";
820-
}
821-
822798
FieldSpec spec = FieldSpec(
823799
narrow_to_wide(name.c_str()),
824800
wlabel,
@@ -902,13 +878,6 @@ void GUIFormSpecMenu::parseTextArea(parserData* data,std::vector<std::string>& p
902878

903879
std::wstring wlabel = narrow_to_wide(label.c_str());
904880

905-
if (m_use_gettext) {
906-
if (label.length() > 1)
907-
wlabel = wstrgettext(label);
908-
else
909-
wlabel = L"";
910-
}
911-
912881
FieldSpec spec = FieldSpec(
913882
narrow_to_wide(name.c_str()),
914883
wlabel,
@@ -989,9 +958,6 @@ void GUIFormSpecMenu::parseLabel(parserData* data,std::string element) {
989958

990959
std::wstring wlabel = narrow_to_wide(text.c_str());
991960

992-
if (m_use_gettext)
993-
wlabel = wstrgettext(text);
994-
995961
FieldSpec spec = FieldSpec(
996962
L"",
997963
wlabel,
@@ -1026,12 +992,6 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data,std::string element) {
1026992
text = unescape_string(text);
1027993
std::string label = "";
1028994

1029-
if (m_use_gettext) {
1030-
const char* toset = gettext(text.c_str());
1031-
1032-
text = std::string(toset);
1033-
}
1034-
1035995
for (unsigned int i=0; i < text.length(); i++) {
1036996
label += text.c_str()[i];
1037997
label += "\n";
@@ -1098,9 +1058,6 @@ void GUIFormSpecMenu::parseImageButton(parserData* data,std::string element,std:
10981058

10991059
std::wstring wlabel = narrow_to_wide(label.c_str());
11001060

1101-
if (m_use_gettext)
1102-
wlabel = wstrgettext(label);
1103-
11041061
FieldSpec spec = FieldSpec(
11051062
narrow_to_wide(name.c_str()),
11061063
wlabel,
@@ -1194,15 +1151,9 @@ void GUIFormSpecMenu::parseTabHeader(parserData* data,std::string element) {
11941151
for (unsigned int i=0; i< buttons.size(); i++) {
11951152
wchar_t* wbutton = 0;
11961153

1197-
if (m_use_gettext)
1198-
wbutton = wgettext(buttons[i].c_str());
1199-
else
1200-
wbutton = (wchar_t*) narrow_to_wide(buttons[i].c_str()).c_str();
1154+
wbutton = (wchar_t*) narrow_to_wide(buttons[i].c_str()).c_str();
12011155

12021156
e->addTab(wbutton,-1);
1203-
1204-
if (m_use_gettext)
1205-
delete[] wbutton;
12061157
}
12071158

12081159
if ((tab_index >= 0) &&

Diff for: ‎src/guiFormSpecMenu.h

-5
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,6 @@ class GUIFormSpecMenu : public GUIModalMenu
206206
m_allowclose = value;
207207
}
208208

209-
void useGettext(bool value) {
210-
m_use_gettext = true;
211-
}
212-
213209
void lockSize(bool lock,v2u32 basescreensize=v2u32(0,0)) {
214210
m_lock = lock;
215211
m_lockscreensize = basescreensize;
@@ -282,7 +278,6 @@ class GUIFormSpecMenu : public GUIModalMenu
282278
gui::IGUIStaticText *m_tooltip_element;
283279

284280
bool m_allowclose;
285-
bool m_use_gettext;
286281
bool m_lock;
287282
v2u32 m_lockscreensize;
288283
private:

Diff for: ‎src/script/lua_api/l_mainmenu.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,16 @@ int ModApiMainMenu::l_download_file(lua_State *L)
980980
return 1;
981981
}
982982

983+
/******************************************************************************/
984+
int ModApiMainMenu::l_gettext(lua_State *L)
985+
{
986+
const char* str = luaL_checkstring(L, 1);
987+
str = gettext(str);
988+
lua_pushstring(L, str);
989+
990+
return 1;
991+
}
992+
983993
/******************************************************************************/
984994
void ModApiMainMenu::Initialize(lua_State *L, int top)
985995
{
@@ -1013,4 +1023,5 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
10131023
API_FCT(get_modstore_list);
10141024
API_FCT(sound_play);
10151025
API_FCT(sound_stop);
1026+
API_FCT(gettext);
10161027
}

Diff for: ‎src/script/lua_api/l_mainmenu.h

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class ModApiMainMenu : public ModApiBase {
8181

8282
static int l_sound_stop(lua_State *L);
8383

84+
static int l_gettext(lua_State *L);
85+
8486
//gui
8587

8688
static int l_show_keys_menu(lua_State *L);

Diff for: ‎util/updatepo.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ cd ..
4848
# directory at the top level. You a recent enough xgettext that supports
4949
# --package-name
5050
potfile=po/minetest.pot
51-
xgettext --package-name=minetest -kN_ -kwgettext -F -n -o $potfile src/*.cpp src/*.h
51+
xgettext --package-name=minetest -kN_ -kwgettext -kfgettext -F -n -o $potfile src/*.cpp src/*.h builtin/*.lua
5252

5353
# Now iterate on all languages and create the po file if missing, or update it
5454
# if it exists already

0 commit comments

Comments
 (0)
Please sign in to comment.