From 93a3c40c3911209dfe2dfd6e4f186406f3444acd Mon Sep 17 00:00:00 2001 From: Dav999-v Date: Sat, 31 Dec 2022 02:09:53 +0100 Subject: [PATCH] UtilityClass.cpp: make time formats and numbers translatable This replaces SDL_snprintf by VFormat for the time strings, and makes number_words get translated numbers. This commit is part of rewritten history of the localization branch. The original (unsquashed) commit history can be found here: https://github.com/Dav999-v/VVVVVV/tree/localization-orig --- desktop_version/src/UtilityClass.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/desktop_version/src/UtilityClass.cpp b/desktop_version/src/UtilityClass.cpp index 0b072c08..d4d1e972 100644 --- a/desktop_version/src/UtilityClass.cpp +++ b/desktop_version/src/UtilityClass.cpp @@ -5,7 +5,9 @@ #include #include "Constants.h" +#include "Localization.h" #include "Maths.h" +#include "VFormat.h" static const char* GCChar(const SDL_GameControllerButton button) { @@ -183,24 +185,27 @@ void UtilityClass::format_time(char* buffer, const size_t buffer_size, int secon if (h > 0) { /* H:MM:SS / H:MM:SS.CC */ - SDL_snprintf(buffer, buffer_size, - frames == -1 ? "%d:%02d:%02d" : "%d:%02d:%02d.%02d", + vformat_buf(buffer, buffer_size, + loc::gettext(frames == -1 ? "{hrs}:{min|digits=2}:{sec|digits=2}" : "{hrs}:{min|digits=2}:{sec|digits=2}.{cen|digits=2}"), + "hrs:int, min:int, sec:int, cen:int", h, m, s, frames * 100 / 30 ); } else if (m > 0 || always_minutes || frames == -1) { /* M:SS / M:SS.CC */ - SDL_snprintf(buffer, buffer_size, - frames == -1 ? "%d:%02d" : "%d:%02d.%02d", + vformat_buf(buffer, buffer_size, + loc::gettext(frames == -1 ? "{min}:{sec|digits=2}" : "{min}:{sec|digits=2}.{cen|digits=2}"), + "min:int, sec:int, cen:int", m, s, frames * 100 / 30 ); } else { /* S.CC */ - SDL_snprintf(buffer, buffer_size, - "%d.%02d", + vformat_buf(buffer, buffer_size, + loc::gettext("{sec}.{cen|digits=2}"), + "sec:int, cen:int", s, frames * 100 / 30 ); } @@ -216,6 +221,11 @@ std::string UtilityClass::timestring( int t ) std::string UtilityClass::number_words( int _t ) { + if (loc::lang != "en") + { + return loc::getnumber(_t); + } + static const std::string ones_place[] = {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"}; static const std::string tens_place[] = {"Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"}; static const std::string teens[] = {"Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"};