From 490b865ddd232667070aed01f829dc7910a7df39 Mon Sep 17 00:00:00 2001 From: Benau Date: Sun, 3 Jun 2018 15:15:25 +0800 Subject: [PATCH] Allow using %f with translated message --- src/states_screens/dialogs/ranking_callback.hpp | 6 +++--- src/utils/string_utils.cpp | 6 ++++-- src/utils/string_utils.hpp | 17 ++++++++++++++--- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/states_screens/dialogs/ranking_callback.hpp b/src/states_screens/dialogs/ranking_callback.hpp index b6c5e8d24..6f39f8ece 100644 --- a/src/states_screens/dialogs/ranking_callback.hpp +++ b/src/states_screens/dialogs/ranking_callback.hpp @@ -58,15 +58,15 @@ protected: if (isSuccess()) { int rank = -1; - float score = 0.0; + float score = 0.0f; getXMLData()->get("rank", &rank); getXMLData()->get("scores", &score); if (rank > 0) { // I18N: In the network player dialog show rank and // score of a player - result = _("%s has a rank of %d with score %d.", - m_name, rank, (int)score); + result = _("%s has a rank of %d with score %f.", + m_name, rank, score); } } *done = true; diff --git a/src/utils/string_utils.cpp b/src/utils/string_utils.cpp index 9fc0e1526..43b88bb11 100644 --- a/src/utils/string_utils.cpp +++ b/src/utils/string_utils.cpp @@ -358,7 +358,8 @@ namespace StringUtils } else { - if(sv[i][1]=='s' || sv[i][1]=='d' || sv[i][1]=='i') + if(sv[i][1]=='s' || sv[i][1]=='d' || sv[i][1]=='i' || + sv[i][1]=='f') { if (insertValID >= all_vals.size()) { @@ -430,7 +431,8 @@ namespace StringUtils } else { - if (sv[i][1]=='s' || sv[i][1]=='d' || sv[i][1]=='i') + if (sv[i][1]=='s' || sv[i][1]=='d' || sv[i][1]=='i' || + sv[i][1]=='f') { if (insertValID >= all_vals.size()) { diff --git a/src/utils/string_utils.hpp b/src/utils/string_utils.hpp index 146c0bdc5..15e9dbe72 100644 --- a/src/utils/string_utils.hpp +++ b/src/utils/string_utils.hpp @@ -21,6 +21,7 @@ #ifndef HEADER_STRING_UTILS_HPP #define HEADER_STRING_UTILS_HPP +#include #include #include #include @@ -67,10 +68,20 @@ namespace StringUtils // ------------------------------------------------------------------------ template - std::string toString (const T& any) + std::string toString(const T& any) { std::ostringstream oss; - oss << any ; + oss << any; + return oss.str(); + } // toString template + + // ------------------------------------------------------------------------ + template <> + inline std::string toString(const double& any) + { + std::ostringstream oss; + oss.precision(std::numeric_limits::max_digits10); + oss << any; return oss.str(); } // toString template @@ -115,7 +126,7 @@ namespace StringUtils // ------------------------------------------------------------------------ /** - * Replaces the first %s or %i/%d in the string with the first value + * Replaces the first %s or %i/%d/%f in the string with the first value * converted to a string), the 2nd %s or %d with the second value etc. * So this is basically a simplified s(n)printf replacement, but doesn't * do any fancy formatting (and no type checks either - so you can print