I'm doing a multilanguage application with Qt, in Eclipse/Linux. In thai, the line breaks don't seem to be well supported on my controller (I'm still not sure why). Anyway, the following algorithm inserts a zero-width space (\u200b) between each thai characters (except between a character & its accents), so line breaks can occur. However, my controller now takes 12 minutes to boot in thai language (12 minutes before showing the opening QString message). The function overrides QTranslator::translate from Qt, so I can add zero-width spaces in each translated QString.
My question is the following: Can you guys tell me if I manipulate correctly Unicode & Utf-8 characters in the QString? Edit: Is the rendering of thai symbols a Qt issue? Thanks a lot!
QString EditTranslation::translate(const char *context, const char *sourceText, const char *disambiguation) const{
QString translatedString = QTranslator::translate(context, sourceText, disambiguation);
if (SystemSettingsService->getLanguageType() != ISystemSettingsService::Thai )
return translatedString;
// Important block starts here*********************
QString translatedStringModified;
for(QString::const_iterator i(translatedString.begin()); i != translatedString.end(); ++i){
translatedStringModified.append(i->unicode());
int unicode = (i+1)->unicode();
if(((unicode > 3584 && unicode < 3634 && unicode != 3633) || (unicode > 3646 && unicode < 3655) || (unicode > 3662 && unicode < 3676))){
translatedStringModified.append(QString::fromUtf8("\u200b")); // Zero-width space is added
}
}
// ************************************
return translatedStringModified;
}
In Thai spaces are used between paragraphs rather than words; this is the reason line breaking is poor in your original problem.
To solve this properly, you should use an algorithm to find boundaries between words; such as in libthai; and insert breaks there instead of arbitrarily inserting between consonants.
Inserting a space between every consonant is probably one of the reasons for the slowness.
In the mean time, the ranges you are using are wrong: you shouldn't break after a preceding vowel. This code snippet should clear it up for you: