[Interest] cross-language matching of QStrings: partial success only?

René J.V. Bertin rjvbertin at gmail.com
Mon May 11 19:07:31 CEST 2015


Hi,

In a nutshell: I'm trying to find QStrings in a QStringList, and can't get it to work reliably if the working environment isn't set to english. For instance:

QFontDialogPrivate::updateStyles() familyList= "Segoe UI" style= "Demi-gras Italique" styles= ("Italic", "Light", "Bold Italic", "Regular", "Semibold Italic", "Bold", "Semibold")

In this case, I will at some point have cstyle=style="Demi-gras Italique" and istyle="Semibold Italic", and will be looking for

cstyle.contains(pattern) && istyle.contains(pattern)

with pattern taken from a QStringList of synonyms for Semibold, translated using QCoreApplication::translate("QFontDatabase").

I do get a partial hit:

cstyle= "Demi-gras Italique" matches istyle= "Semibold Italic" for weight; hit in list ("DemiBold", "Demi-gras", "SemiBold", "Semi Bold")

but then I still need to do a similar check for the slant, where I'll be using a QStringList containing the translations for "Italic" and "Oblique", to be exact I require:

cstyle.contains(pattern) == istyle.contains(pattern)

(so either both true or both false).

Here, I see this:

( "Demi-gras Italique" , "Semibold Italic" ) vs ("Italique", "Oblique") = true false


So apparently the string comparison does not do translation (which isn't really a surprise except when you look at the context in which I'm working here...).

It seems the best option would be to ensure that cstyle and istyle are both in the same language. For that, I think I'd need to know the language in which the elements of "styles" are stored, and then translate "style" (cstyle) into that language.

How does one do that?

Also, the QFontDatabase translations apparently aren't complete (only "Demi Bold" gets translated); where are they defined?

Thanks...

R.




More information about the Interest mailing list