From c161a3911a9e59a64a2879c15e28948e99e7aef6 Mon Sep 17 00:00:00 2001 From: Arnold Zhou Date: Sun, 29 Sep 2024 01:13:48 +1000 Subject: [PATCH] Fix #22072: Localisation: Separate objective date string from staff tenure date string (#22074) Co-authored-by: Tulio Leao --- data/language/en-GB.txt | 7 +++++-- distribution/changelog.txt | 1 + src/openrct2/localisation/FormatCodes.cpp | 2 ++ src/openrct2/localisation/FormatCodes.h | 1 + src/openrct2/localisation/Formatting.cpp | 11 +++++++---- src/openrct2/localisation/StringIds.h | 2 ++ test/tests/FormattingTests.cpp | 2 +- 7 files changed, 19 insertions(+), 7 deletions(-) diff --git a/data/language/en-GB.txt b/data/language/en-GB.txt index 6373d1cdc1..a06436ce9c 100644 --- a/data/language/en-GB.txt +++ b/data/language/en-GB.txt @@ -1739,8 +1739,8 @@ STR_2382 :Land STR_2383 :Water STR_2384 :{WINDOW_COLOUR_2}Your objective: STR_2385 :{BLACK}None -STR_2386 :{BLACK}To have at least {COMMA32} guests in your park at the end of {MONTHYEAR}, with a park rating of at least 600 -STR_2387 :{BLACK}To achieve a park value of at least {POP16}{POP16}{CURRENCY} at the end of {PUSH16}{PUSH16}{PUSH16}{PUSH16}{PUSH16}{MONTHYEAR} +STR_2386 :{BLACK}To have at least {COMMA32} guests in your park at the end of {MONTHYEAR_SENTENCE}, with a park rating of at least 600 +STR_2387 :{BLACK}To achieve a park value of at least {POP16}{POP16}{CURRENCY} at the end of {PUSH16}{PUSH16}{PUSH16}{PUSH16}{PUSH16}{MONTHYEAR_SENTENCE} STR_2388 :{BLACK}Have Fun! STR_2389 :{BLACK}Build the best {STRINGID} you can! STR_2390 :{BLACK}To have 10 different types of roller coasters operating in your park, each with an excitement value of at least 6.00 @@ -1950,6 +1950,7 @@ STR_2732 :{COMMA32} ft STR_2733 :{COMMA32} m STR_2734 :{COMMA16} mph STR_2735 :{COMMA16} km/h +# Used only as part of label-value pair. STR_2736 :{MONTH}, Year {COMMA16} STR_2737 :{STRINGID} {MONTH}, Year {COMMA16} STR_2738 :Title screen music: @@ -3743,6 +3744,8 @@ STR_6670 :Guest behaviour STR_6671 :Show ‘real’ names of staff STR_6672 :Toggle between showing ‘real’ names of staff and staff numbers STR_6673 :Transparent +# Used as part of a sentence (see https://github.com/OpenRCT2/OpenRCT2/issues/22072). +STR_6674 :{MONTH}, Year {COMMA16} ############# # Scenarios # diff --git a/distribution/changelog.txt b/distribution/changelog.txt index f7b5f3a1cc..4bda088d19 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -14,6 +14,7 @@ - Fix: [#7672] Wide path status is set to all ‘wide’ paths, instead of only a quarter, impeding pathfinding. - Fix: [#15406] Tunnels on steep Side-Friction track are drawn too low. - Fix: [#21959] “Save this before...?” message does not appear when selecting “New Game”. +- Fix: [#22072] Objective date string and staff tenure date string cannot be reused on agglutinative languages. - Fix: [#22231] Invalid object version can cause a crash. - Fix: [#22562] Bottom row of pixels is not always drawn by the OpenGL renderer when zoomed in. - Fix: [#22653] Missing water tiles in RCT1 and RCT2 scenarios. diff --git a/src/openrct2/localisation/FormatCodes.cpp b/src/openrct2/localisation/FormatCodes.cpp index 746e8280f6..ce2b489442 100644 --- a/src/openrct2/localisation/FormatCodes.cpp +++ b/src/openrct2/localisation/FormatCodes.cpp @@ -38,6 +38,7 @@ static const EnumMap FormatTokenMap = { { "STRINGID", FormatToken::StringById, }, { "STRING", FormatToken::String, }, { "MONTHYEAR", FormatToken::MonthYear, }, + { "MONTHYEAR_SENTENCE", FormatToken::MonthYearSentence, }, { "MONTH", FormatToken::Month, }, { "VELOCITY", FormatToken::Velocity, }, { "POP16", FormatToken::Pop16, }, @@ -98,6 +99,7 @@ bool FormatTokenTakesArgument(FormatToken token) case FormatToken::StringById: case FormatToken::String: case FormatToken::MonthYear: + case FormatToken::MonthYearSentence: case FormatToken::Month: case FormatToken::Velocity: case FormatToken::DurationShort: diff --git a/src/openrct2/localisation/FormatCodes.h b/src/openrct2/localisation/FormatCodes.h index 83929ab202..7a1ed89cf8 100644 --- a/src/openrct2/localisation/FormatCodes.h +++ b/src/openrct2/localisation/FormatCodes.h @@ -37,6 +37,7 @@ enum class FormatToken StringById, String, MonthYear, + MonthYearSentence, Month, Velocity, DurationShort, diff --git a/src/openrct2/localisation/Formatting.cpp b/src/openrct2/localisation/Formatting.cpp index b7f636b7c9..d64e07c764 100644 --- a/src/openrct2/localisation/Formatting.cpp +++ b/src/openrct2/localisation/Formatting.cpp @@ -25,7 +25,7 @@ namespace OpenRCT2 { - static void FormatMonthYear(FormatBuffer& ss, int32_t month, int32_t year); + static void FormatMonthYear(FormatBuffer& ss, int32_t month, int32_t year, bool inSentence); static std::optional ParseNumericToken(std::string_view s) { @@ -585,11 +585,12 @@ namespace OpenRCT2 } break; case FormatToken::MonthYear: + case FormatToken::MonthYearSentence: if constexpr (std::is_integral()) { auto month = DateGetMonth(arg); auto year = DateGetYear(arg) + 1; - FormatMonthYear(ss, month, year); + FormatMonthYear(ss, month, year, token == FormatToken::MonthYearSentence); } break; case FormatToken::Month: @@ -779,6 +780,7 @@ namespace OpenRCT2 break; case FormatToken::UInt16: case FormatToken::MonthYear: + case FormatToken::MonthYearSentence: case FormatToken::Month: case FormatToken::Velocity: case FormatToken::DurationShort: @@ -815,12 +817,13 @@ namespace OpenRCT2 } } - static void FormatMonthYear(FormatBuffer& ss, int32_t month, int32_t year) + static void FormatMonthYear(FormatBuffer& ss, int32_t month, int32_t year, bool inSentence) { thread_local std::vector tempArgs; tempArgs.clear(); - auto fmt = GetFmtStringById(STR_DATE_FORMAT_MY); + auto stringId = inSentence ? STR_DATE_FORMAT_MY_SENTENCE : STR_DATE_FORMAT_MY; + auto fmt = GetFmtStringById(stringId); Formatter ft; ft.Add(month); ft.Add(year); diff --git a/src/openrct2/localisation/StringIds.h b/src/openrct2/localisation/StringIds.h index 3fa8a99caf..1812de6b03 100644 --- a/src/openrct2/localisation/StringIds.h +++ b/src/openrct2/localisation/StringIds.h @@ -1692,6 +1692,8 @@ enum : StringId STR_CHEAT_IGNORE_PRICE = 6659, + STR_DATE_FORMAT_MY_SENTENCE = 6674, + // Have to include resource strings (from scenarios and objects) for the time being now that language is partially working /* MAX_STR_COUNT = 32768 */ // MAX_STR_COUNT - upper limit for number of strings, not the current count strings }; diff --git a/test/tests/FormattingTests.cpp b/test/tests/FormattingTests.cpp index 449cf1eb93..5e6fcd950c 100644 --- a/test/tests/FormattingTests.cpp +++ b/test/tests/FormattingTests.cpp @@ -42,7 +42,7 @@ TEST_F(FmtStringTests, iteration) actual += String::StdFormat("[%d:%s]", t.kind, std::string(t.text).c_str()); } - ASSERT_EQ("[29:{BLACK}][1:Guests: ][8:{INT32}]", actual); + ASSERT_EQ("[30:{BLACK}][1:Guests: ][8:{INT32}]", actual); } TEST_F(FmtStringTests, iteration_escaped)