]> git.lizzy.rs Git - lmz_opening_hours.git/blobdiff - init.lua
client side translation
[lmz_opening_hours.git] / init.lua
index 85d91c24bd7ca5db174e686e1106939ba440a9ba..4918f61ffdfbef74e46c2679cd5ef2608ac33e5b 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -1,5 +1,6 @@
 local modname = minetest.get_current_modname()
 local storage = minetest.get_mod_storage()
+local S = minetest.get_translator("lmz_opening_hours")
 
 opening_hours = {}
 
@@ -147,7 +148,7 @@ local function tick(dtime)
        if 0 < minutes_remaining
        and minutes_remaining <= opening_hours.warn_offset then
                if warn_cooldown <= 0 then
-                       minetest.chat_send_all(minetest.colorize("#FF4D00", "Der Server schießt in " .. minutes_remaining .. " Minuten."))
+                       minetest.chat_send_all(minetest.colorize("#FF4D00", S("The server will close in @1 minutes.", minutes_remaining)))
                        warn_cooldown = tonumber(opening_hours.warn_interval) * 60
                else
                        warn_cooldown = warn_cooldown - dtime
@@ -156,7 +157,7 @@ local function tick(dtime)
                for _, player in pairs(minetest.get_connected_players()) do
                        local name = player:get_player_name()
                        if not minetest.check_player_privs(name, {server = true}) then
-                               minetest.kick_player(name, "Der Server schließt!")
+                               minetest.kick_player(name, S("The server is closing!"))
                        end
                end
        end
@@ -171,9 +172,9 @@ local function on_join(name)
        local now_time = d.hour * 60 + d.min
        local diff = start_time - now_time
        if diff > 0 then
-               return "Besuch erfolgte außerhalb der Öffnungszeiten. Der Server hat in " .. math.ceil(diff / 60) .. " Stunde(n) wieder geöffnet."
+               return S("You visited outside of the opening hours") .. ". " .. S("The server will open again in @1 hours", math.ceil(diff / 60)) .. "."
        elseif end_time <= now_time then
-               return "Besuch erfolgte außerhalb der Öffnungszeiten. Der Server hat bereits geschlossen und hat Morgen wieder geöffnet."
+               return S("You visited outside of the opening hours") .. ". " .. S("The server has already closed and will open again tomorrow") .. "."
        end
 end
 
@@ -190,41 +191,26 @@ local function show_gui(name)
        local minute_off = 0.04
        local to_off = 1.24
        local day_off = 3.6
-       local lab_day1_x = 0.1
-       local fld_day1_f_hour_x = 0.64
-       local fld_day1_f_minute_x = fld_day1_f_hour_x + fld_w - minute_off
-       local lab_day1_f_colon_x = fld_day1_f_minute_x - pre_colon_off
-       local fld_day1_t_hour_x = lab_day1_f_colon_x + to_off
-       local fld_day1_t_minute_x = fld_day1_t_hour_x + fld_w - minute_off
-       local lab_day1_t_colon_x = fld_day1_t_minute_x - pre_colon_off
-       local lab_day2_x = lab_day1_x + day_off
-       local fld_day2_f_hour_x = fld_day1_f_hour_x + day_off
-       local fld_day2_f_minute_x = fld_day1_f_minute_x + day_off
-       local lab_day2_f_colon_x = lab_day1_f_colon_x + day_off
-       local fld_day2_t_hour_x = fld_day1_t_hour_x + day_off
-       local fld_day2_t_minute_x = fld_day1_t_minute_x + day_off
-       local lab_day2_t_colon_x = lab_day1_t_colon_x + day_off
-       local lab_day3_x = lab_day2_x + day_off
-       local fld_day3_f_hour_x = fld_day2_f_hour_x + day_off
-       local fld_day3_f_minute_x = fld_day2_f_minute_x + day_off
-       local lab_day3_f_colon_x = lab_day2_f_colon_x + day_off
-       local fld_day3_t_hour_x = fld_day2_t_hour_x + day_off
-       local fld_day3_t_minute_x = fld_day2_t_minute_x + day_off
-       local lab_day3_t_colon_x = lab_day2_t_colon_x + day_off
-       local lab_day4_x = lab_day3_x + day_off
-       local fld_day4_f_hour_x = fld_day3_f_hour_x + day_off
-       local fld_day4_f_minute_x = fld_day3_f_minute_x + day_off
-       local lab_day4_f_colon_x = lab_day3_f_colon_x + day_off
-       local fld_day4_t_hour_x = fld_day3_t_hour_x + day_off
-       local fld_day4_t_minute_x = fld_day3_t_minute_x + day_off
-       local lab_day4_t_colon_x = lab_day3_t_colon_x + day_off
-       local lab_day5_x = lab_day4_x + day_off
-       local fld_day5_f_hour_x = fld_day4_f_hour_x + day_off
-       local fld_day5_f_minute_x = fld_day4_f_minute_x + day_off
-       local lab_day5_f_colon_x = lab_day4_f_colon_x + day_off
-       local fld_day5_t_hour_x = fld_day4_t_hour_x + day_off
-       local fld_day5_t_minute_x = fld_day4_t_minute_x + day_off
-       local lab_day5_t_colon_x = lab_day4_t_colon_x + day_off
+       local x = {
+               day1 = {}
+       }
+       x.day1.lab = 0.1
+       x.day1.fld_f_hour = 0.64
+       x.day1.fld_f_minute = x.day1.fld_f_hour + fld_w - minute_off
+       x.day1.lab_f_colon = x.day1.fld_f_minute - pre_colon_off
+       x.day1.fld_t_hour = x.day1.lab_f_colon + to_off
+       x.day1.fld_t_minute = x.day1.fld_t_hour + fld_w - minute_off
+       x.day1.lab_t_colon = x.day1.fld_t_minute - pre_colon_off
+       local last
+       for day = 1, 5, 1 do
+               if last then
+                       x["day" .. day] = {}
+                       for k, v in pairs(x["day" .. last]) do
+                               x["day" .. day][k] = v + day_off
+                       end
+               end
+               last = day
+       end
        local below_off = 1.1530125704378
        local lab_b_y = 0.28175119202427
        local fld_b_y = lab_b_y + below_off
@@ -236,93 +222,62 @@ local function show_gui(name)
        local fld_e_y = lab_e_y + below_off
        local lab_e_colon_y = fld_e_y - inline_off
        local o = opening_hours
-       local formspec_day1 = ""
-       .. "label[" .. lab_day1_x .. "," .. lab_b_y .. ";Mo.]"
-       .. "field[" .. fld_day1_f_hour_x .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day1_start_hour;von;" .. string.format("%02d", o.day1_start_hour) .. "]"
-       .. "label[" .. lab_day1_f_colon_x .. "," .. lab_b_colon_y .. ";:]"
-       .. "field[" .. fld_day1_f_minute_x .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day1_start_minute;;" .. string.format("%02d", o.day1_start_minute) .. "]"
-       .. "field[" .. fld_day1_t_hour_x .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day1_end_hour;bis;" .. string.format("%02d", o.day1_end_hour) .. "]"
-       .. "label[" .. lab_day1_t_colon_x .. "," .. lab_b_colon_y .. ";:]"
-       .. "field[" .. fld_day1_t_minute_x .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day1_end_minute;;" .. string.format("%02d", o.day1_end_minute) .. "]"
-       local formspec_day2 = ""
-       .. "label[" .. lab_day2_x .. "," .. lab_b_y .. ";Di.]"
-       .. "field[" .. fld_day2_f_hour_x .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day2_start_hour;von;" .. string.format("%02d", o.day2_start_hour) .. "]"
-       .. "label[" .. lab_day2_f_colon_x .. "," .. lab_b_colon_y .. ";:]"
-       .. "field[" .. fld_day2_f_minute_x .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day2_start_minute;;" .. string.format("%02d", o.day2_start_minute) .. "]"
-       .. "field[" .. fld_day2_t_hour_x .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day2_end_hour;bis;" .. string.format("%02d", o.day2_end_hour) .. "]"
-       .. "label[" .. lab_day2_t_colon_x .. "," .. lab_b_colon_y .. ";:]"
-       .. "field[" .. fld_day2_t_minute_x .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day2_end_minute;;" .. string.format("%02d", o.day2_end_minute) .. "]"
-       local formspec_day3 = ""
-       .. "label[" .. lab_day3_x .. "," .. lab_b_y .. ";Mi.]"
-       .. "field[" .. fld_day3_f_hour_x .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day3_start_hour;von;" .. string.format("%02d", o.day3_start_hour) .. "]"
-       .. "label[" .. lab_day3_f_colon_x .. "," .. lab_b_colon_y .. ";:]"
-       .. "field[" .. fld_day3_f_minute_x .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day3_start_minute;;" .. string.format("%02d", o.day3_start_minute) .. "]"
-       .. "field[" .. fld_day3_t_hour_x .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day3_end_hour;bis;" .. string.format("%02d", o.day3_end_hour) .. "]"
-       .. "label[" .. lab_day3_t_colon_x .. "," .. lab_b_colon_y .. ";:]"
-       .. "field[" .. fld_day3_t_minute_x .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day3_end_minute;;" .. string.format("%02d", o.day3_end_minute) .. "]"
-       local formspec_day4 = ""
-       .. "label[" .. lab_day4_x .. "," .. lab_b_y .. ";Do.]"
-       .. "field[" .. fld_day4_f_hour_x .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day4_start_hour;von;" .. string.format("%02d", o.day4_start_hour) .. "]"
-       .. "label[" .. lab_day4_f_colon_x .. "," .. lab_b_colon_y .. ";:]"
-       .. "field[" .. fld_day4_f_minute_x .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day4_start_minute;;" .. string.format("%02d", o.day4_start_minute) .. "]"
-       .. "field[" .. fld_day4_t_hour_x .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day4_end_hour;bis;" .. string.format("%02d", o.day4_end_hour) .. "]"
-       .. "label[" .. lab_day4_t_colon_x .. "," .. lab_b_colon_y .. ";:]"
-       .. "field[" .. fld_day4_t_minute_x .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day4_end_minute;;" .. string.format("%02d", o.day4_end_minute) .. "]"
-       local formspec_day5 = ""
-       .. "label[" .. lab_day5_x .. "," .. lab_b_y .. ";Fr.]"
-       .. "field[" .. fld_day5_f_hour_x .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day5_start_hour;von;" .. string.format("%02d", o.day5_start_hour) .. "]"
-       .. "label[" .. lab_day5_f_colon_x .. "," .. lab_b_colon_y .. ";:]"
-       .. "field[" .. fld_day5_f_minute_x .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day5_start_minute;;" .. string.format("%02d", o.day5_start_minute) .. "]"
-       .. "field[" .. fld_day5_t_hour_x .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day5_end_hour;bis;" .. string.format("%02d", o.day5_end_hour) .. "]"
-       .. "label[" .. lab_day5_t_colon_x .. "," .. lab_b_colon_y .. ";:]"
-       .. "field[" .. fld_day5_t_minute_x .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day5_end_minute;;" .. string.format("%02d", o.day5_end_minute) .. "]"
+       local day_abbreviations = {
+               [0] = S("Su."),
+               [1] = S("Mo."),
+               [2] = S("Tu."),
+               [3] = S("We."),
+               [4] = S("Th."),
+               [5] = S("Fr."),
+               [6] = S("Sa.")
+       }
        local formspec_business_days = ""
-       .. formspec_day1
-       .. formspec_day2
-       .. formspec_day3
-       .. formspec_day4
-       .. formspec_day5
-       local formspec_day6 = ""
-       .. "label[" .. lab_day1_x .. "," .. lab_w_y .. ";Sa.]"
-       .. "field[" .. fld_day1_f_hour_x .. "," .. fld_w_y .. ";" .. fld_sz .. ";fld_day6_start_hour;von;" .. string.format("%02d", o.day6_start_hour) .. "]"
-       .. "label[" .. lab_day1_f_colon_x .. "," .. lab_w_colon_y .. ";:]"
-       .. "field[" .. fld_day1_f_minute_x .. "," .. fld_w_y .. ";" .. fld_sz .. ";fld_day6_start_minute;;" .. string.format("%02d", o.day6_start_minute) .. "]"
-       .. "field[" .. fld_day1_t_hour_x .. "," .. fld_w_y .. ";" .. fld_sz .. ";fld_day6_end_hour;bis;" .. string.format("%02d", o.day6_end_hour) .. "]"
-       .. "label[" .. lab_day1_t_colon_x .. "," .. lab_w_colon_y .. ";:]"
-       .. "field[" .. fld_day1_t_minute_x .. "," .. fld_w_y .. ";" .. fld_sz .. ";fld_day6_end_minute;;" .. string.format("%02d", o.day6_end_minute) .. "]"
-       local formspec_day0 = ""
-       .. "label[" .. lab_day2_x .. "," .. lab_w_y .. ";So.]"
-       .. "field[" .. fld_day2_f_hour_x .. "," .. fld_w_y .. ";" .. fld_sz .. ";fld_day0_start_hour;von;" .. string.format("%02d", o.day0_start_hour) .. "]"
-       .. "label[" .. lab_day2_f_colon_x .. "," .. lab_w_colon_y .. ";:]"
-       .. "field[" .. fld_day2_f_minute_x .. "," .. fld_w_y .. ";" .. fld_sz .. ";fld_day0_start_minute;;" .. string.format("%02d", o.day0_start_minute) .. "]"
-       .. "field[" .. fld_day2_t_hour_x .. "," .. fld_w_y .. ";" .. fld_sz .. ";fld_day0_end_hour;bis;" .. string.format("%02d", o.day0_end_hour) .. "]"
-       .. "label[" .. lab_day2_t_colon_x .. "," .. lab_w_colon_y .. ";:]"
-       .. "field[" .. fld_day2_t_minute_x .. "," .. fld_w_y .. ";" .. fld_sz .. ";fld_day0_end_minute;;" .. string.format("%02d", o.day0_end_minute) .. "]"
+       for day = 1, 5, 1 do
+               formspec_business_days = formspec_business_days
+               .. "label[" .. x["day" .. day].lab .. "," .. lab_b_y .. ";" .. day_abbreviations[day] .. "]"
+               .. "field[" .. x["day" .. day].fld_f_hour .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day" .. day .. "_start_hour;" .. S("from") .. ";" .. string.format("%02d", o["day" .. day .. "_start_hour"]) .. "]"
+               .. "label[" .. x["day" .. day].lab_f_colon .. "," .. lab_b_colon_y .. ";:]"
+               .. "field[" .. x["day" .. day].fld_f_minute .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day" .. day .. "_start_minute;;" .. string.format("%02d", o["day" .. day .. "_start_minute"]) .. "]"
+               .. "field[" .. x["day" .. day].fld_t_hour .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day" .. day .. "_end_hour;" .. S("to") .. ";" .. string.format("%02d", o["day" .. day .. "_end_hour"]) .. "]"
+               .. "label[" .. x["day" .. day].lab_t_colon .. "," .. lab_b_colon_y .. ";:]"
+               .. "field[" .. x["day" .. day].fld_t_minute .. "," .. fld_b_y .. ";" .. fld_sz .. ";fld_day" .. day .. "_end_minute;;" .. string.format("%02d", o["day" .. day .. "_end_minute"]) .. "]"
+       end
+       local formspec_weekend = ""
+       for col = 1, 2, 1 do
+               day = (5 + col) % 7
+               formspec_weekend = formspec_weekend
+               .. "label[" .. x["day" .. col].lab .. "," .. lab_w_y .. ";" .. day_abbreviations[day] .. "]"
+               .. "field[" .. x["day" .. col].fld_f_hour .. "," .. fld_w_y .. ";" .. fld_sz .. ";fld_day" .. day .. "_start_hour;" .. S("from") .. ";" .. string.format("%02d", o["day" .. day .. "_start_hour"]) .. "]"
+               .. "label[" .. x["day" .. col].lab_f_colon .. "," .. lab_w_colon_y .. ";:]"
+               .. "field[" .. x["day" .. col].fld_f_minute .. "," .. fld_w_y .. ";" .. fld_sz .. ";fld_day" .. day .. "_start_minute;;" .. string.format("%02d", o["day" .. day .. "_start_minute"]) .. "]"
+               .. "field[" .. x["day" .. col].fld_t_hour .. "," .. fld_w_y .. ";" .. fld_sz .. ";fld_day" .. day .. "_end_hour;" .. S("to") .. ";" .. string.format("%02d", o["day" .. day .. "_end_hour"]) .. "]"
+               .. "label[" .. x["day" .. col].lab_t_colon .. "," .. lab_w_colon_y .. ";:]"
+               .. "field[" .. x["day" .. col].fld_t_minute .. "," .. fld_w_y .. ";" .. fld_sz .. ";fld_day" .. day .. "_end_minute;;" .. string.format("%02d", o["day" .. day .. "_end_minute"]) .. "]"
+       end
        local formspec_exception = (o.exception_today
                        and ""
-                               .. "label[" .. lab_day1_x .. "," .. lab_e_y .. ";Heute]"
-                               .. "field[" .. fld_day1_f_hour_x .. "," .. fld_e_y .. ";" .. fld_sz .. ";fld_exception_start_hour;von;" .. string.format("%02d", o.exception_start_hour) .. "]"
-                               .. "label[" .. lab_day1_f_colon_x .. "," .. lab_e_colon_y .. ";:]"
-                               .. "field[" .. fld_day1_f_minute_x .. "," .. fld_e_y .. ";" .. fld_sz .. ";fld_exception_start_minute;;" .. string.format("%02d", o.exception_start_minute) .. "]"
-                               .. "field[" .. fld_day1_t_hour_x .. "," .. fld_e_y .. ";" .. fld_sz .. ";fld_exception_end_hour;bis;" .. string.format("%02d", o.exception_end_hour) .. "]"
-                               .. "label[" .. lab_day1_t_colon_x .. "," .. lab_e_colon_y .. ";:]"
-                               .. "field[" .. fld_day1_t_minute_x .. "," .. fld_e_y .. ";" .. fld_sz .. ";fld_exception_end_minute;;" .. string.format("%02d", o.exception_end_minute) .. "]"
-                       or "image_button[0.34,4.5296922410056;4.205,0.7835;;add_exception;Ausnahmeregelung hinzufügen]"
+                               .. "label[" .. x.day1.lab .. "," .. lab_e_y .. ";" .. S("Today") .. "]"
+                               .. "field[" .. x.day1.fld_f_hour .. "," .. fld_e_y .. ";" .. fld_sz .. ";fld_exception_start_hour;" .. S("from") .. ";" .. string.format("%02d", o.exception_start_hour) .. "]"
+                               .. "label[" .. x.day1.lab_f_colon .. "," .. lab_e_colon_y .. ";:]"
+                               .. "field[" .. x.day1.fld_f_minute .. "," .. fld_e_y .. ";" .. fld_sz .. ";fld_exception_start_minute;;" .. string.format("%02d", o.exception_start_minute) .. "]"
+                               .. "field[" .. x.day1.fld_t_hour .. "," .. fld_e_y .. ";" .. fld_sz .. ";fld_exception_end_hour;" .. S("to") .. ";" .. string.format("%02d", o.exception_end_hour) .. "]"
+                               .. "label[" .. x.day1.lab_t_colon .. "," .. lab_e_colon_y .. ";:]"
+                               .. "field[" .. x.day1.fld_t_minute .. "," .. fld_e_y .. ";" .. fld_sz .. ";fld_exception_end_minute;;" .. string.format("%02d", o.exception_end_minute) .. "]"
+                       or "image_button[0.34,4.5296922410056;4.205,0.7835;;add_exception;" .. S("Add exception") .. "]"
                )
        local formspec = "size[18.01,7.9267895878525]"
-       .. "label[-0.14,-0.23840485478977;Öffnungszeiten]"
+       .. "label[-0.14,-0.23840485478977;" .. S("Opening hours") .. "]"
        .. formspec_business_days
-       .. formspec_day6
-       .. formspec_day0
+       .. formspec_weekend
        .. formspec_exception
-       .. "label[" .. lab_day1_x .. ",5.4833116601647;Einstellungen]"
+       .. "label[" .. x.day1.lab .. ",5.4833116601647;" .. S("Settings") .. "]"
        .. "label[0.34," .. lab_close_y .. ";Spieler ]"
        .. "field[1.6," .. fld_close_y .. ";" .. fld_sz .. ";fld_warn_offset;;" .. o.warn_offset .. "]"
        .. "label[2.18," .. lab_close_y .. ";Minuten vor Ablauf der Zeit alle]"
        .. "field[6.0," .. fld_close_y .. ";" .. fld_sz .. ";fld_warn_interval;;" .. o.warn_interval .. "]"
        .. "label[6.6," .. lab_close_y .. ";Minuten warnen.]"
-       .. "image_button[5.14,7.6072821846554;2.605,0.7835;;save;Speichern]"
-       .. "image_button_exit[7.62,7.6072821846554;2.605,0.7835;;close;Schließen]"
+       .. "image_button[5.14,7.6072821846554;2.605,0.7835;;save;" .. S("Save") .. "]"
+       .. "image_button_exit[7.62,7.6072821846554;2.605,0.7835;;close;" .. S("Close") .. "]"
        minetest.show_formspec(name, "lmz_opening_hours:gui", formspec)
 end
 
@@ -378,8 +333,22 @@ load_data()
 minetest.register_globalstep(tick)
 minetest.register_on_shutdown(save_data)
 minetest.register_on_prejoinplayer(on_join)
-minetest.register_chatcommand("opening_hours", {privs = {server = true}, description = "Die Öffnungszeiten konfigurieren", func = show_gui})
-minetest.register_chatcommand("öffnungszeiten", {privs = {server = true}, description = "Die Öffnungszeiten konfigurieren", func = show_gui})
+minetest.register_chatcommand(
+       "opening_hours",
+       {
+               privs = {server = true},
+               description = S("Configure the opening hours"),
+               func = show_gui
+       }
+)
+minetest.register_chatcommand(
+       "öffnungszeiten",
+       {
+               privs = {server = true},
+               description = S("Configure the opening hours"),
+               func = show_gui
+       }
+)
 minetest.register_on_player_receive_fields(progress_gui_input)