diff --git a/locale/mtimer.de.tr b/locale/mtimer.de.tr index 3db1c14..b0db167 100644 --- a/locale/mtimer.de.tr +++ b/locale/mtimer.de.tr @@ -99,7 +99,7 @@ Stop stop custom timer=Individuellen Timer anhalten Restart the custom timer=Individuellen Timer neu starten -# Custonm timer status messages +# Default custom timer status messages The custom timer is already running=Der individuelle Timer läuft bereits The custom timer is not running=Der individuelle Timer läuft nicht The custom timer was started=Der individuelle Timer wurde gestartet @@ -188,3 +188,10 @@ September=September Oktober=Oktober November=November December=Dezember + + +# Related to the meridiem indicator +Meridiem Indicator=Tageshälftenhinweis +am=vorm. +pm=nachm. +(ERROR)=(FEHLER) diff --git a/system/formspecs/formspec_creation.lua b/system/formspecs/formspec_creation.lua index 169a04c..9f4e499 100644 --- a/system/formspecs/formspec_creation.lua +++ b/system/formspecs/formspec_creation.lua @@ -54,14 +54,15 @@ mtimer.dialog.ingame_time_format = function (player_name) 'field_close_on_enter[format;false]', 'field[0,0;+contentWidth,0.5;format;;'..esc(time_data.format)..']', 'container[0,1.5]', - line(0, '', S('Variable'), S('Current Value')), + line(0, '', S('Variable'), S('Current Value')), line(1, '-'), - line(2, S('Hours (24h)'), '{24h}', time_data.hours_24), - line(3, S('Hours (12h)'), '{12h}', time_data.hours_12), - line(4, S('Minutes'), '{min}', time_data.minutes), - line(5, S('Ingame Timestamp'), '{its}', time_data.ingame_timestamp), - line(6, '-'), - line(7, S('Current Result'), esc(time_data.formatted), ''), + line(2, S('Hours (24h)'), '{24h}', time_data.hours_24), + line(3, S('Hours (12h)'), '{12h}', time_data.hours_12), + line(4, S('Minutes'), '{min}', time_data.minutes), + line(5, S('Meridiem Indicator'),'{mi}', time_data.indicator), + line(6, S('Ingame Timestamp'), '{its}', time_data.ingame_timestamp), + line(7, '-'), + line(8, S('Current Result'), esc(time_data.formatted), ''), 'container_end[]' } }) diff --git a/system/formspecs/real_time_universal.lua b/system/formspecs/real_time_universal.lua index 83e111d..42fbb08 100644 --- a/system/formspecs/real_time_universal.lua +++ b/system/formspecs/real_time_universal.lua @@ -22,30 +22,31 @@ mtimer.dialog.real_time_universal = function (player_name, config) mtimer.show_formspec(config.formspec_name, { title = config.title, show_to = player_name, - height = 8.75, + height = 9, formspec = { 'field_close_on_enter[format;false]', 'field[0,0;+contentWidth,0.5;format;;'..esc(time_data.format)..']', 'container[0,1.5]', - line(0, '', S('Variable'), S('Current Value')), + line(0, '', S('Variable'), S('Current Value')), line(1, '-'), - line(2, S('Hours (24h)'), '{24h}', vars.hours_24), - line(3, S('Hours (12h)'), '{12h}', vars.hours_12), - line(4, S('Minutes'), '{min}', vars.minutes), - line(5, S('Seconds'), '{sec}', vars.seconds), - line(6, '-'), - line(7, S('Day Name'), '{dname}', vars.dayname), - line(8, S('Month Name'), '{mname}', vars.monthname), - line(9, '-'), - line(10, S('Year'), '{year}', vars.year), - line(11, S('Month'), '{month}', vars.month), - line(12, S('Day'), '{day}', vars.day), - line(13, '-'), - line(14, S('ISO 8601 Date'), '{isodate}', vars.iso8601_date), - line(15, S('ISO 8601 Time'), '{isotime}', vars.iso8601_time), - line(16, S('Timestamp'), '{timestamp}', vars.timestamp), - line(17, '-'), - line(18, S('Current Result'), esc(time_data.formatted), ''), + line(2, S('Hours (24h)'), '{24h}', vars.hours_24), + line(3, S('Hours (12h)'), '{12h}', vars.hours_12), + line(4, S('Minutes'), '{min}', vars.minutes), + line(5, S('Seconds'), '{sec}', vars.seconds), + line(6, S('Meridiem Indicator'), '{mi}', vars.indicator), + line(7, '-'), + line(8, S('Day Name'), '{dname}', vars.dayname), + line(9, S('Month Name'), '{mname}', vars.monthname), + line(10, '-'), + line(11, S('Year'), '{year}', vars.year), + line(12, S('Month'), '{month}', vars.month), + line(13, S('Day'), '{day}', vars.day), + line(14, '-'), + line(15, S('ISO 8601 Date'), '{isodate}', vars.iso8601_date), + line(16, S('ISO 8601 Time'), '{isotime}', vars.iso8601_time), + line(17, S('Timestamp'), '{timestamp}', vars.timestamp), + line(18, '-'), + line(19, S('Current Result'), esc(time_data.formatted), ''), 'container_end[]' } }) diff --git a/system/get_times.lua b/system/get_times.lua index d962875..65a9cd2 100644 --- a/system/get_times.lua +++ b/system/get_times.lua @@ -3,6 +3,22 @@ local S = m.translator local ds = minetest.deserialize +-- Manually calculate am/pm +-- +-- Because %p returns am/pm or nothing depending on current locale it is not +-- reliable to use it. This function takes a 24h hours value and returns the +-- correct meridiem indicator. +-- +-- @param hour The hour to get the indicator for in 24h format +-- @return string The meridiem indicator for that hour +local get_mi = function (hour) + local s_hour = tonumber(hour) + if s_hour >= 0 and s_hour <= 11 then return S('am') end -- midnight->noon + if s_hour >= 12 and s_hour <= 23 then return S('pm') end -- noon->midnight + return S('(ERROR)') +end + + -- Get translated date names -- -- This helper function takes a table containing a numerical month and a @@ -111,6 +127,7 @@ local get_real_time_universal = function (player_name, time_type) hours_12 = os.date(force_utc..'%I', local_timestamp), minutes = os.date(force_utc..'%M', local_timestamp), seconds = os.date(force_utc..'%S', local_timestamp), + indicator = get_mi(os.date(force_utc..'%H', local_timestamp)), dayname = date_names.day, monthname = date_names.month, year = os.date(force_utc..'%Y', local_timestamp), @@ -128,6 +145,7 @@ local get_real_time_universal = function (player_name, time_type) ['{12h}'] = values.variables.hours_12, ['{min}'] = values.variables.minutes, ['{sec}'] = values.variables.seconds, + ['{mi}'] = values.variables.indicator, ['{dname}'] = values.variables.dayname, ['{mname}'] = values.variables.monthname, ['{year}'] = values.variables.year, @@ -182,6 +200,7 @@ local get_ingame_time = function (player_name) hours_24 = os.date('!%H', ingame_timestamp), hours_12 = os.date('!%I', ingame_timestamp), minutes = os.date('!%M', ingame_timestamp), + indicator = get_mi(os.date(os.date('!%H', ingame_timestamp))), ingame_timestamp = ingame_timestamp, format = format } @@ -190,6 +209,7 @@ local get_ingame_time = function (player_name) ['{24h}'] = values.hours_24, ['{12h}'] = values.hours_12, ['{min}'] = values.minutes, + ['{mi}'] = values.indicator, ['{its}'] = values.ingame_timestamp })