Allow using %f with translated message

This commit is contained in:
Benau 2018-06-03 15:15:25 +08:00
parent e122d045cc
commit 490b865ddd
3 changed files with 21 additions and 8 deletions

View File

@ -58,15 +58,15 @@ protected:
if (isSuccess()) if (isSuccess())
{ {
int rank = -1; int rank = -1;
float score = 0.0; float score = 0.0f;
getXMLData()->get("rank", &rank); getXMLData()->get("rank", &rank);
getXMLData()->get("scores", &score); getXMLData()->get("scores", &score);
if (rank > 0) if (rank > 0)
{ {
// I18N: In the network player dialog show rank and // I18N: In the network player dialog show rank and
// score of a player // score of a player
result = _("%s has a rank of %d with score %d.", result = _("%s has a rank of %d with score %f.",
m_name, rank, (int)score); m_name, rank, score);
} }
} }
*done = true; *done = true;

View File

@ -358,7 +358,8 @@ namespace StringUtils
} }
else 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()) if (insertValID >= all_vals.size())
{ {
@ -430,7 +431,8 @@ namespace StringUtils
} }
else 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()) if (insertValID >= all_vals.size())
{ {

View File

@ -21,6 +21,7 @@
#ifndef HEADER_STRING_UTILS_HPP #ifndef HEADER_STRING_UTILS_HPP
#define HEADER_STRING_UTILS_HPP #define HEADER_STRING_UTILS_HPP
#include <limits>
#include <string> #include <string>
#include <vector> #include <vector>
#include <sstream> #include <sstream>
@ -74,6 +75,16 @@ namespace StringUtils
return oss.str(); return oss.str();
} // toString template } // toString template
// ------------------------------------------------------------------------
template <>
inline std::string toString(const double& any)
{
std::ostringstream oss;
oss.precision(std::numeric_limits<double>::max_digits10);
oss << any;
return oss.str();
} // toString template
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** Specialisiation for bools to return 'true' or 'false'*/ /** Specialisiation for bools to return 'true' or 'false'*/
inline std::string toString(const bool& b) inline std::string toString(const bool& b)
@ -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. * 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 * 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 * do any fancy formatting (and no type checks either - so you can print