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())
{
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;

View File

@ -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())
{

View File

@ -21,6 +21,7 @@
#ifndef HEADER_STRING_UTILS_HPP
#define HEADER_STRING_UTILS_HPP
#include <limits>
#include <string>
#include <vector>
#include <sstream>
@ -67,10 +68,20 @@ namespace StringUtils
// ------------------------------------------------------------------------
template <class T>
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<double>::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