Merge pull request #2133 from Flakebi/translation-fixes

Fix some translation and bidi issues
This commit is contained in:
auriamg 2015-04-26 19:29:02 -04:00
commit 38e4e4e03c
8 changed files with 106 additions and 56 deletions

View File

@ -113,7 +113,7 @@ public:
irr::core::stringw getDescription() const { return _(m_description.c_str()); }
// ------------------------------------------------------------------------
/** Returns the name of this achievement. */
irr::core::stringw getName() const { return _(m_name.c_str()); }
irr::core::stringw getName() const { return _LTR(m_name.c_str()); }
// ------------------------------------------------------------------------
bool needsResetAfterRace() const { return m_reset_type == AFTER_RACE; }
// ------------------------------------------------------------------------

View File

@ -74,7 +74,7 @@ void BubbleWidget::replaceText()
EGUI_ALIGNMENT align = EGUIA_UPPERLEFT;
if (m_properties[PROP_TEXT_ALIGN] == "center") align = EGUIA_CENTER;
else if (m_properties[PROP_TEXT_ALIGN] == "right") align = EGUIA_LOWERRIGHT;
else if (translations->isRTLLanguage()) align = EGUIA_LOWERRIGHT;
else if (translations->isRTLText(message)) align = EGUIA_LOWERRIGHT;
EGUI_ALIGNMENT valign = EGUIA_CENTER ; //TODO: make label v-align configurable through XML file?
@ -90,7 +90,7 @@ void BubbleWidget::replaceText()
m_expanded_size.LowerRightCorner.Y += additionalNeededSize/2 + 10;
// reduce text to fit in the available space if it's too long
if (translations->isRTLLanguage())
if (translations->isRTLText(message))
{
while (text_height > m_shrinked_size.getHeight() && message.size() > 10)
{

View File

@ -344,6 +344,7 @@ void PlayerKartWidget::add()
name = m_associated_player->getProfile()->getName();
if (m_associated_user)
name = m_associated_user->getUserName();
core::stringw label = translations->fribidize(name);
if (m_parent_screen->m_multiplayer)
{
@ -357,21 +358,21 @@ void PlayerKartWidget::add()
{
// I18N: 'handicapped' indicates that per-player handicaps are
// activated for this kart (i.e. it will drive slower)
label = _("%s (handicapped)", label);
label = _("%s (handicapped)", name);
m_player_ident_spinner->addLabel(label);
}
}
// select the right player profile in the spinner
m_player_ident_spinner->setValue(name);
m_player_ident_spinner->setValue(label);
}
else
{
m_player_ident_spinner->addLabel(name);
m_player_ident_spinner->addLabel(label);
m_player_ident_spinner->setVisible(false);
}
assert(m_player_ident_spinner->getStringValue() == name);
assert(m_player_ident_spinner->getStringValue() == label);
} // add
// ------------------------------------------------------------------------

View File

@ -148,7 +148,7 @@ public:
// ------------------------------------------------------------------------
/** @return the (potentially translated) user-visible name of the Grand
* Prix (apply fribidi as needed) */
irr::core::stringw getName() const { return _LTR(m_name.c_str()); }
irr::core::stringw getName() const { return m_editable ? m_name.c_str() : _LTR(m_name.c_str()); }
// ------------------------------------------------------------------------
/** @return the internal indentifier of the Grand Prix (not translated) */

View File

@ -161,7 +161,7 @@ void GrandPrixEditorScreen::setSelection (const GrandPrixData* gpdata)
if (gpdata == NULL)
{
m_selection = NULL;
gpname_widget->setText (L"Please select a Grand Prix", true);
gpname_widget->setText (_("Please select a Grand Prix"), true);
tracks_widget->clearItems();
tracks_widget->updateItemDisplay();
}

View File

@ -107,7 +107,7 @@ void BaseOnlineProfileAchievements::init()
const Achievement *a = it->second;
if(a->getInfo()->isSecret() && !a->isAchieved())
continue;
ListWidget::ListCell title(a->getInfo()->getName(), -1, 2);
ListWidget::ListCell title(translations->fribidize(a->getInfo()->getName()), -1, 2);
ListWidget::ListCell progress(a->getProgressAsString(), -1, 1);
row.push_back(title);
row.push_back(progress);

View File

@ -25,6 +25,7 @@
#include "utils/translation.hpp"
#include <algorithm>
#include <assert.h>
#include <locale.h>
#include <stdio.h>
@ -144,12 +145,30 @@ FriBidiChar* toFribidiChar(const wchar_t* str)
}
#ifdef TEST_BIDI
// Prepend a character that forces RTL style
// Prepend a character in each line that forces RTL style
int lines = 1;
for (std::size_t i = 0; i <= length; i++)
{
if (str[i] == L'\n')
lines++;
}
FriBidiChar *tmp = result;
result = new FriBidiChar[++length + 1];
std::memcpy(result + 1, tmp, length * sizeof(FriBidiChar));
length += lines;
result = new FriBidiChar[length + 1];
lines = 1;
result[0] = L'\u202E';
freeFribidiChar(tmp);
for (std::size_t i = 1; i <= length; i++)
{
result[i] = tmp[i - lines];
if (str[i - lines] == L'\n')
{
lines++;
i++;
result[i] = L'\u202E';
}
}
if (sizeof(wchar_t) != sizeof(FriBidiChar))
delete[] tmp;
#endif
return result;
@ -366,54 +385,31 @@ Translations::Translations() //: m_dictionary_manager("UTF-16")
const wchar_t* Translations::fribidize(const wchar_t* in_ptr)
{
#if ENABLE_BIDI
if(this->isRTLLanguage())
if (isRTLText(in_ptr))
{
FriBidiChar *fribidiInput = toFribidiChar(in_ptr);
std::size_t length = 0;
while (fribidiInput[length])
length++;
// Split text into lines
std::vector<core::stringw> input_lines = StringUtils::split(in_ptr, '\n');
// Reverse lines for RTL strings, irrlicht will reverse them back
// This is needed because irrlicht inserts line breaks itself if a text
// is too long for one line and then reverses the lines again.
std::reverse(input_lines.begin(), input_lines.end());
// Assume right to left as start direction.
#if FRIBIDI_MINOR_VERSION==10
// While the doc for older fribidi versions is somewhat sparse,
// using the RIGHT-TO-LEFT EMBEDDING character here appears to
// work correct.
FriBidiCharType pbase_dir = L'\u202B';
#else
FriBidiCharType pbase_dir = FRIBIDI_PAR_ON;
#endif
FriBidiChar *fribidiOutput = new FriBidiChar[length + 1];
memset(fribidiOutput, 0, (length + 1) * sizeof(FriBidiChar));
fribidi_boolean result = fribidi_log2vis(fribidiInput,
length,
&pbase_dir,
fribidiOutput,
/* gint *position_L_to_V_list */ NULL,
/* gint *position_V_to_L_list */ NULL,
/* gint8 *embedding_level_list */ NULL
);
freeFribidiChar(fribidiInput);
if (!result)
// Fribidize and concat lines
for (std::vector<core::stringw>::iterator it = input_lines.begin();
it != input_lines.end(); it++)
{
delete[] fribidiOutput;
Log::error("Translations::fribidize", "Fribidi failed in 'fribidi_log2vis' =(");
m_converted_string = core::stringw(in_ptr);
return m_converted_string.c_str();
if (it == input_lines.begin())
m_converted_string = fribidizeLine(*it);
else
{
m_converted_string += "\n";
m_converted_string += fribidizeLine(*it);
}
}
wchar_t *convertedString = fromFribidiChar(fribidiOutput);
m_converted_string = core::stringw(convertedString);
freeFribidiChar(convertedString);
delete[] fribidiOutput;
return m_converted_string.c_str();
}
#endif // ENABLE_BIDI
return in_ptr;
else
return in_ptr;
}
bool Translations::isRTLText(const wchar_t *in_ptr)
@ -545,3 +541,53 @@ std::string Translations::getCurrentLanguageName()
//return m_dictionary_manager.get_language().get_name();
}
core::stringw Translations::fribidizeLine(const core::stringw &str)
{
#if ENABLE_BIDI
FriBidiChar *fribidiInput = toFribidiChar(str.c_str());
std::size_t length = 0;
while (fribidiInput[length])
length++;
// Assume right to left as start direction.
#if FRIBIDI_MINOR_VERSION==10
// While the doc for older fribidi versions is somewhat sparse,
// using the RIGHT-TO-LEFT EMBEDDING character here appears to
// work correct.
FriBidiCharType pbase_dir = L'\u202B';
#else
FriBidiCharType pbase_dir = FRIBIDI_PAR_ON;
#endif
// Reverse text line by line
FriBidiChar *fribidiOutput = new FriBidiChar[length + 1];
memset(fribidiOutput, 0, (length + 1) * sizeof(FriBidiChar));
fribidi_boolean result = fribidi_log2vis(fribidiInput,
length,
&pbase_dir,
fribidiOutput,
/* gint *position_L_to_V_list */ NULL,
/* gint *position_V_to_L_list */ NULL,
/* gint8 *embedding_level_list */ NULL
);
freeFribidiChar(fribidiInput);
if (!result)
{
delete[] fribidiOutput;
Log::error("Translations::fribidize", "Fribidi failed in 'fribidi_log2vis' =(");
return core::stringw(str);
}
wchar_t *convertedString = fromFribidiChar(fribidiOutput);
core::stringw converted_string(convertedString);
freeFribidiChar(convertedString);
delete[] fribidiOutput;
return converted_string;
#else
return core::stringw(str);
#endif // ENABLE_BIDI
}

View File

@ -70,6 +70,9 @@ public:
const std::vector<std::string>* getLanguageList() const;
std::string getCurrentLanguageName();
private:
irr::core::stringw fribidizeLine(const irr::core::stringw &str);
}; // Translations