Fixed special formatting sequences (e.g. %i, $1$s)for RTL languages (bug 3159482).

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7485 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk
2011-01-20 01:55:30 +00:00
parent c797bbe757
commit ef35dfc72e

View File

@@ -257,12 +257,35 @@ const wchar_t* Translations::w_gettext(const char* original)
return m_converted_string.c_str();
}
//std::cout << "fribidi output : ";
//for (FriBidiChar* c=fribidiOutput; *c != 0; c++)
//{
// std::cout << (int)fribidiOutput[n] << " ";
//}
//std::cout << "\n";
// Special format sequences like '%i' and '%2$s' will be reversed
// by fribidi (since wrapping them in 'embeded ltr' unicode sequences
// is not supported by some editors; see bug 3159482 for details)
// so we have to reverse 'i%' and 's$2%' back:
FriBidiChar *c=fribidiOutput;
if(*c)
while(*(c+1))
{
if( (*c!='i' && *c!='s') ) continue;
if (*(c+1)=='%')
{
*(c+1) = *c;
*c = '%';
c++; // Skip the reversed character
}
// Check for %1$s or %2$i, which will have been
// reversed to s$1% and i$2%
else if( *(c+1)=='$' &&
*(c+2) && (*(c+2)>='0' && *(c+2)<='9') &&
*(c+3) && (*(c+3)=='%') )
{
*(c+3) = *c;
*(c+1) = *(c+2);
*(c+2) = '$';
*c = '%';
c+=3; // skip the reversed characters
}
c++;
}
#ifdef WIN32
// On windows FriBidiChar is 4 bytes, but wchar_t is 2 bytes.
// So we simply copy the characters over here (note that this