From 841f85a74331a02bd45f3d40ea1b50e4bc9dd3eb Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 17 Apr 2020 17:21:34 -0400 Subject: use better short date translations --- src/SMAPI/Utilities/SDate.cs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'src/SMAPI/Utilities') diff --git a/src/SMAPI/Utilities/SDate.cs b/src/SMAPI/Utilities/SDate.cs index 36907714..4d4920ab 100644 --- a/src/SMAPI/Utilities/SDate.cs +++ b/src/SMAPI/Utilities/SDate.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using StardewModdingAPI.Framework; using StardewValley; namespace StardewModdingAPI.Utilities @@ -19,6 +20,9 @@ namespace StardewModdingAPI.Utilities /// The number of days in a season. private readonly int DaysInSeason = 28; + /// The core SMAPI translations. + internal static Translator Translations; + /********* ** Accessors @@ -126,16 +130,31 @@ namespace StardewModdingAPI.Utilities return new WorldDate(this.Year, this.Season, this.Day); } - /// Get a string representation of the date. This is mainly intended for debugging or console messages. + /// Get an untranslated string representation of the date. This is mainly intended for debugging or console messages. public override string ToString() { return $"{this.Day:00} {this.Season} Y{this.Year}"; } /// Get a translated string representation of the date in the current game locale. - public string ToLocaleString() + /// Whether to get a string which includes the year number. + public string ToLocaleString(bool withYear = true) { - return Utility.getDateStringFor(this.Day, this.SeasonIndex, this.Year); + // get fallback translation from game + string fallback = Utility.getDateStringFor(this.Day, this.SeasonIndex, this.Year); + if (SDate.Translations == null) + return fallback; + + // get short format + string seasonName = Utility.getSeasonNameFromNumber(this.SeasonIndex); + return SDate.Translations + .Get(withYear ? "generic.date-with-year" : "generic.date", new + { + day = this.Day, + year = this.Year, + season = Utility.getSeasonNameFromNumber(this.SeasonIndex) + }) + .Default(fallback); } /**** -- cgit