Request for additional method for the trolls

Jacob R Rideout kde at jacobrideout.net
Fri Jan 5 14:48:20 GMT 2007


> Why do you need this? Any matching being made will be most surely very
> restricted. Why would you not have the enum in the first place?
>
> If you have both at some point and you need to discard one, discard the
> string.

I don't truly need the function I cited, but it would make things
simple and Qt already has the data, it just isn't exposed. I could use
the enum, but then I'd need to maintain some hash of my own that
related unicode block names to the the the QLocale enum. Since Qt
already has such a hash, it would be easier just to access it, but not
entirely necessary.

This is the highly inefficient code I am using as a quick hack. If Qt
doesn't implement the call I suggested, I'll just use the iso code for
the names I already know, and maintain a hash for those I don't.
Again, before people complain, the code below won't be shipped.

QString GuessLanguagePrivate::codeFromName(const QString & fullName)
{
    int i;
    for (i=0;i<150;++i)
    {
        if ( QLocale::languageToString( (QLocale::Language)i ) == fullName)
            return QLocale( (QLocale::Language) i ).name().left(2);
    }

    // handle codes not in QLocale
    if (fullName == "Khmer")
        return QString("km");
    if (fullName == "Kyrgyz")
        return QString("ky");
    if (fullName == "Klingon")
        return QString("tlh");

    return QLocale(QLocale::C).name();
}




More information about the kde-core-devel mailing list