From cff7fffe92fb47de8d3afa54c587b8e55c896bfa Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Tue, 23 Oct 2018 13:26:34 +0300 Subject: [PATCH] [New] Added 'Today' and 'Yesterday' to locale Affected issues: #734 --- .../plan/system/locale/lang/GenericLang.java | 4 +++- .../plan/utilities/formatting/Formatters.java | 13 +++++++------ .../utilities/formatting/time/ClockFormatter.java | 6 ++++-- .../utilities/formatting/time/DateFormatter.java | 15 ++++++++++----- .../utilities/formatting/time/DayFormatter.java | 5 +++-- .../formatting/time/ISO8601NoClockFormatter.java | 5 +++-- .../formatting/time/SecondFormatter.java | 6 ++++-- .../utilities/formatting/time/YearFormatter.java | 5 +++-- Plan/src/main/resources/locale/locale_CN.txt | 4 +++- Plan/src/main/resources/locale/locale_CZ.txt | 2 ++ Plan/src/main/resources/locale/locale_DE.txt | 2 ++ Plan/src/main/resources/locale/locale_EN.txt | 2 ++ Plan/src/main/resources/locale/locale_FI.txt | 2 ++ Plan/src/main/resources/locale/locale_FR.txt | 2 ++ Plan/src/main/resources/locale/locale_GA.txt | 2 ++ Plan/src/main/resources/locale/locale_IT.txt | 2 ++ Plan/src/main/resources/locale/locale_NL.txt | 2 ++ Plan/src/main/resources/locale/locale_NO.txt | 2 ++ Plan/src/main/resources/locale/locale_PL.txt | 2 ++ Plan/src/main/resources/locale/locale_PT.txt | 2 ++ 20 files changed, 62 insertions(+), 23 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/system/locale/lang/GenericLang.java b/Plan/src/main/java/com/djrapitops/plan/system/locale/lang/GenericLang.java index b6ef6a87e..634d2296e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/locale/lang/GenericLang.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/locale/lang/GenericLang.java @@ -8,7 +8,9 @@ package com.djrapitops.plan.system.locale.lang; public enum GenericLang implements Lang { YES("Positive", "Yes"), NO("Negative", "No"), - UNKNOWN("Unknown", "Unknown"); + UNKNOWN("Unknown", "Unknown"), + TODAY("Today", "'Today'"), + YESTERDAY("Yesterday", "'Yesterday'"); private final String identifier; private final String defaultValue; diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/Formatters.java b/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/Formatters.java index 1f74196e4..787782f15 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/Formatters.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/Formatters.java @@ -1,6 +1,7 @@ package com.djrapitops.plan.utilities.formatting; import com.djrapitops.plan.data.store.objects.DateHolder; +import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.settings.config.PlanConfig; import com.djrapitops.plan.utilities.formatting.time.*; @@ -33,12 +34,12 @@ public class Formatters { private final PercentageFormatter percentageFormatter; @Inject - public Formatters(PlanConfig config) { - yearLongFormatter = new YearFormatter(config); - dayLongFormatter = new DayFormatter(config); - clockLongFormatter = new ClockFormatter(config); - secondLongFormatter = new SecondFormatter(config); - iso8601NoClockLongFormatter = new ISO8601NoClockFormatter(config); + public Formatters(PlanConfig config, Locale locale) { + yearLongFormatter = new YearFormatter(config, locale); + dayLongFormatter = new DayFormatter(config, locale); + clockLongFormatter = new ClockFormatter(config, locale); + secondLongFormatter = new SecondFormatter(config, locale); + iso8601NoClockLongFormatter = new ISO8601NoClockFormatter(config, locale); yearFormatter = new DateHolderFormatter(yearLongFormatter); dayFormatter = new DateHolderFormatter(dayLongFormatter); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/ClockFormatter.java b/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/ClockFormatter.java index 8bf88b8e6..84b88b07a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/ClockFormatter.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/ClockFormatter.java @@ -1,8 +1,10 @@ package com.djrapitops.plan.utilities.formatting.time; +import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.config.PlanConfig; + /** * Formatter for a timestamp that only includes a clock. * @@ -10,8 +12,8 @@ import com.djrapitops.plan.system.settings.config.PlanConfig; */ public class ClockFormatter extends DateFormatter { - public ClockFormatter(PlanConfig config) { - super(config); + public ClockFormatter(PlanConfig config, Locale locale) { + super(config, locale); } @Override diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/DateFormatter.java b/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/DateFormatter.java index 3db3c9228..80fbb917f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/DateFormatter.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/DateFormatter.java @@ -1,11 +1,12 @@ package com.djrapitops.plan.utilities.formatting.time; +import com.djrapitops.plan.system.locale.Locale; +import com.djrapitops.plan.system.locale.lang.GenericLang; import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.config.PlanConfig; import com.djrapitops.plan.utilities.formatting.Formatter; import java.text.SimpleDateFormat; -import java.util.Locale; import java.util.TimeZone; import java.util.concurrent.TimeUnit; @@ -17,9 +18,11 @@ import java.util.concurrent.TimeUnit; public abstract class DateFormatter implements Formatter { protected final PlanConfig config; + protected final Locale locale; - public DateFormatter(PlanConfig config) { + public DateFormatter(PlanConfig config, Locale locale) { this.config = config; + this.locale = locale; } @Override @@ -28,7 +31,9 @@ public abstract class DateFormatter implements Formatter { protected String format(long epochMs, String format) { boolean useServerTime = config.isTrue(Settings.USE_SERVER_TIME); String locale = config.getString(Settings.LOCALE); - Locale usedLocale = locale.equalsIgnoreCase("default") ? Locale.ENGLISH : Locale.forLanguageTag(locale); + java.util.Locale usedLocale = locale.equalsIgnoreCase("default") + ? java.util.Locale.ENGLISH + : java.util.Locale.forLanguageTag(locale); SimpleDateFormat dateFormat = new SimpleDateFormat(format, usedLocale); TimeZone timeZone = useServerTime ? TimeZone.getDefault() : TimeZone.getTimeZone("GMT"); dateFormat.setTimeZone(timeZone); @@ -44,9 +49,9 @@ public abstract class DateFormatter implements Formatter { long fromStartOfDay = now % TimeUnit.DAYS.toMillis(1L); if (epochMs > now - fromStartOfDay) { - format = format.replace(pattern, "'Today'"); + format = format.replace(pattern, locale.getString(GenericLang.TODAY)); } else if (epochMs > now - TimeUnit.DAYS.toMillis(1L) - fromStartOfDay) { - format = format.replace(pattern, "'Yesterday'"); + format = format.replace(pattern, locale.getString(GenericLang.YESTERDAY)); } else if (epochMs > now - TimeUnit.DAYS.toMillis(5L)) { format = format.replace(pattern, "EEEE"); } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/DayFormatter.java b/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/DayFormatter.java index 42afc290b..ad6add619 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/DayFormatter.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/DayFormatter.java @@ -1,5 +1,6 @@ package com.djrapitops.plan.utilities.formatting.time; +import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.config.PlanConfig; @@ -10,8 +11,8 @@ import com.djrapitops.plan.system.settings.config.PlanConfig; */ public class DayFormatter extends DateFormatter { - public DayFormatter(PlanConfig config) { - super(config); + public DayFormatter(PlanConfig config, Locale locale) { + super(config, locale); } @Override diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/ISO8601NoClockFormatter.java b/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/ISO8601NoClockFormatter.java index 90dd7c8b8..915d54e94 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/ISO8601NoClockFormatter.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/ISO8601NoClockFormatter.java @@ -1,5 +1,6 @@ package com.djrapitops.plan.utilities.formatting.time; +import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.settings.config.PlanConfig; /** @@ -9,8 +10,8 @@ import com.djrapitops.plan.system.settings.config.PlanConfig; */ public class ISO8601NoClockFormatter extends DateFormatter { - public ISO8601NoClockFormatter(PlanConfig config) { - super(config); + public ISO8601NoClockFormatter(PlanConfig config, Locale locale) { + super(config, locale); } @Override diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/SecondFormatter.java b/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/SecondFormatter.java index 832d3e531..56d86ed56 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/SecondFormatter.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/SecondFormatter.java @@ -1,8 +1,10 @@ package com.djrapitops.plan.utilities.formatting.time; +import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.config.PlanConfig; + /** * Formatter for timestamp which includes seconds as the smallest entry. * @@ -10,8 +12,8 @@ import com.djrapitops.plan.system.settings.config.PlanConfig; */ public class SecondFormatter extends DateFormatter { - public SecondFormatter(PlanConfig config) { - super(config); + public SecondFormatter(PlanConfig config, Locale locale) { + super(config, locale); } @Override diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/YearFormatter.java b/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/YearFormatter.java index 1f525b241..48379ff96 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/YearFormatter.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/formatting/time/YearFormatter.java @@ -1,5 +1,6 @@ package com.djrapitops.plan.utilities.formatting.time; +import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.config.PlanConfig; @@ -10,8 +11,8 @@ import com.djrapitops.plan.system.settings.config.PlanConfig; */ public class YearFormatter extends DateFormatter { - public YearFormatter(PlanConfig config) { - super(config); + public YearFormatter(PlanConfig config, Locale locale) { + super(config, locale); } @Override diff --git a/Plan/src/main/resources/locale/locale_CN.txt b/Plan/src/main/resources/locale/locale_CN.txt index d7c7c33eb..f8c3fd1aa 100644 --- a/Plan/src/main/resources/locale/locale_CN.txt +++ b/Plan/src/main/resources/locale/locale_CN.txt @@ -312,4 +312,6 @@ WebServer - Notify HTTP User Auth || 网页服务器:已禁用 WebServer - Notify no Cert file || 网页服务器:未找到证书密钥存储文件:${0} WebServer FAIL - Port Bind || 未成功初始化网页服务器。端口(${0})是否被占用? WebServer FAIL - SSL Context || 网页服务器:SSL 环境初始化失败。 -WebServer FAIL - Store Load || 网页服务器:SSL 证书载入失败。 \ No newline at end of file +WebServer FAIL - Store Load || 网页服务器:SSL 证书载入失败。 +Yesterday || 'Yesterday' +Today || 'Today' \ No newline at end of file diff --git a/Plan/src/main/resources/locale/locale_CZ.txt b/Plan/src/main/resources/locale/locale_CZ.txt index 29f63a3f2..6096e4118 100644 --- a/Plan/src/main/resources/locale/locale_CZ.txt +++ b/Plan/src/main/resources/locale/locale_CZ.txt @@ -312,3 +312,5 @@ WebServer - Notify no Cert file || WebServer: Certificate KeySto WebServer FAIL - Port Bind || WebServer was not initialized successfully. Is the port (${0}) in use? WebServer FAIL - SSL Context || WebServer: SSL Context Initialization Failed. WebServer FAIL - Store Load || WebServer: SSL Certificate loading Failed. +Yesterday || 'Yesterday' +Today || 'Today' \ No newline at end of file diff --git a/Plan/src/main/resources/locale/locale_DE.txt b/Plan/src/main/resources/locale/locale_DE.txt index 26a694b20..bec21f327 100644 --- a/Plan/src/main/resources/locale/locale_DE.txt +++ b/Plan/src/main/resources/locale/locale_DE.txt @@ -312,3 +312,5 @@ WebServer - Notify no Cert file || WebServer: Zertifikat KeyStor WebServer FAIL - Port Bind || WebServer wurde nicht erfolgreich initalisiert. Ist der Port (${0}) schon benutzt? WebServer FAIL - SSL Context || WebServer: SSL Context Initialisierung fehlgeschlagen. WebServer FAIL - Store Load || WebServer: SSL Zertifikat konnte nicht geladen werden. +Yesterday || 'Yesterday' +Today || 'Today' \ No newline at end of file diff --git a/Plan/src/main/resources/locale/locale_EN.txt b/Plan/src/main/resources/locale/locale_EN.txt index 29f63a3f2..6096e4118 100644 --- a/Plan/src/main/resources/locale/locale_EN.txt +++ b/Plan/src/main/resources/locale/locale_EN.txt @@ -312,3 +312,5 @@ WebServer - Notify no Cert file || WebServer: Certificate KeySto WebServer FAIL - Port Bind || WebServer was not initialized successfully. Is the port (${0}) in use? WebServer FAIL - SSL Context || WebServer: SSL Context Initialization Failed. WebServer FAIL - Store Load || WebServer: SSL Certificate loading Failed. +Yesterday || 'Yesterday' +Today || 'Today' \ No newline at end of file diff --git a/Plan/src/main/resources/locale/locale_FI.txt b/Plan/src/main/resources/locale/locale_FI.txt index 806e94a76..deca1a97d 100644 --- a/Plan/src/main/resources/locale/locale_FI.txt +++ b/Plan/src/main/resources/locale/locale_FI.txt @@ -311,3 +311,5 @@ WebServer - Notify no Cert file || Web Palvelin: Sertifikaatti A WebServer FAIL - Port Bind || Web Palvelin ei käynnistynyt. Onko portti (${0}) käytössä? WebServer FAIL - SSL Context || Web Palvelin: SSL Kontekstin käynnistys ei onnistunut. WebServer FAIL - Store Load || Web Palvelin: SSL Sertifikaatin lataus ei onnistunut. +Yesterday || 'Eilen' +Today || 'Tänään' \ No newline at end of file diff --git a/Plan/src/main/resources/locale/locale_FR.txt b/Plan/src/main/resources/locale/locale_FR.txt index 29f63a3f2..6096e4118 100644 --- a/Plan/src/main/resources/locale/locale_FR.txt +++ b/Plan/src/main/resources/locale/locale_FR.txt @@ -312,3 +312,5 @@ WebServer - Notify no Cert file || WebServer: Certificate KeySto WebServer FAIL - Port Bind || WebServer was not initialized successfully. Is the port (${0}) in use? WebServer FAIL - SSL Context || WebServer: SSL Context Initialization Failed. WebServer FAIL - Store Load || WebServer: SSL Certificate loading Failed. +Yesterday || 'Yesterday' +Today || 'Today' \ No newline at end of file diff --git a/Plan/src/main/resources/locale/locale_GA.txt b/Plan/src/main/resources/locale/locale_GA.txt index 29f63a3f2..6096e4118 100644 --- a/Plan/src/main/resources/locale/locale_GA.txt +++ b/Plan/src/main/resources/locale/locale_GA.txt @@ -312,3 +312,5 @@ WebServer - Notify no Cert file || WebServer: Certificate KeySto WebServer FAIL - Port Bind || WebServer was not initialized successfully. Is the port (${0}) in use? WebServer FAIL - SSL Context || WebServer: SSL Context Initialization Failed. WebServer FAIL - Store Load || WebServer: SSL Certificate loading Failed. +Yesterday || 'Yesterday' +Today || 'Today' \ No newline at end of file diff --git a/Plan/src/main/resources/locale/locale_IT.txt b/Plan/src/main/resources/locale/locale_IT.txt index 29f63a3f2..6096e4118 100644 --- a/Plan/src/main/resources/locale/locale_IT.txt +++ b/Plan/src/main/resources/locale/locale_IT.txt @@ -312,3 +312,5 @@ WebServer - Notify no Cert file || WebServer: Certificate KeySto WebServer FAIL - Port Bind || WebServer was not initialized successfully. Is the port (${0}) in use? WebServer FAIL - SSL Context || WebServer: SSL Context Initialization Failed. WebServer FAIL - Store Load || WebServer: SSL Certificate loading Failed. +Yesterday || 'Yesterday' +Today || 'Today' \ No newline at end of file diff --git a/Plan/src/main/resources/locale/locale_NL.txt b/Plan/src/main/resources/locale/locale_NL.txt index 29f63a3f2..6096e4118 100644 --- a/Plan/src/main/resources/locale/locale_NL.txt +++ b/Plan/src/main/resources/locale/locale_NL.txt @@ -312,3 +312,5 @@ WebServer - Notify no Cert file || WebServer: Certificate KeySto WebServer FAIL - Port Bind || WebServer was not initialized successfully. Is the port (${0}) in use? WebServer FAIL - SSL Context || WebServer: SSL Context Initialization Failed. WebServer FAIL - Store Load || WebServer: SSL Certificate loading Failed. +Yesterday || 'Yesterday' +Today || 'Today' \ No newline at end of file diff --git a/Plan/src/main/resources/locale/locale_NO.txt b/Plan/src/main/resources/locale/locale_NO.txt index 29f63a3f2..6096e4118 100644 --- a/Plan/src/main/resources/locale/locale_NO.txt +++ b/Plan/src/main/resources/locale/locale_NO.txt @@ -312,3 +312,5 @@ WebServer - Notify no Cert file || WebServer: Certificate KeySto WebServer FAIL - Port Bind || WebServer was not initialized successfully. Is the port (${0}) in use? WebServer FAIL - SSL Context || WebServer: SSL Context Initialization Failed. WebServer FAIL - Store Load || WebServer: SSL Certificate loading Failed. +Yesterday || 'Yesterday' +Today || 'Today' \ No newline at end of file diff --git a/Plan/src/main/resources/locale/locale_PL.txt b/Plan/src/main/resources/locale/locale_PL.txt index 29f63a3f2..6096e4118 100644 --- a/Plan/src/main/resources/locale/locale_PL.txt +++ b/Plan/src/main/resources/locale/locale_PL.txt @@ -312,3 +312,5 @@ WebServer - Notify no Cert file || WebServer: Certificate KeySto WebServer FAIL - Port Bind || WebServer was not initialized successfully. Is the port (${0}) in use? WebServer FAIL - SSL Context || WebServer: SSL Context Initialization Failed. WebServer FAIL - Store Load || WebServer: SSL Certificate loading Failed. +Yesterday || 'Yesterday' +Today || 'Today' \ No newline at end of file diff --git a/Plan/src/main/resources/locale/locale_PT.txt b/Plan/src/main/resources/locale/locale_PT.txt index 29f63a3f2..6096e4118 100644 --- a/Plan/src/main/resources/locale/locale_PT.txt +++ b/Plan/src/main/resources/locale/locale_PT.txt @@ -312,3 +312,5 @@ WebServer - Notify no Cert file || WebServer: Certificate KeySto WebServer FAIL - Port Bind || WebServer was not initialized successfully. Is the port (${0}) in use? WebServer FAIL - SSL Context || WebServer: SSL Context Initialization Failed. WebServer FAIL - Store Load || WebServer: SSL Certificate loading Failed. +Yesterday || 'Yesterday' +Today || 'Today' \ No newline at end of file