KLocale vs QLocale vs system locale

Andriy Rysin arysin at gmail.com
Thu Nov 1 00:28:18 GMT 2007


Hi,
I have two questions and would appreciate if anybody can give me an answer.

1. Is there any reason that QLocale is synched with system locale and
KLocale is not?
2. Currently when kxkb uses libxklavier to fetch translations (for more
details see my recent email in kde-i18n) I have to set system locale from
KLocale with the code below. The question is: is there a better solution I
should have used?

Thanks,
Andriy

static const int LOCALE_CATEGORY = LC_ALL;
...
    const char* currLocale = setlocale(LOCALE_CATEGORY, NULL);

    QString locale = KGlobal::locale()->language();
    if( locale.indexOf('_') == -1 ) {   // TODO: do we have to do this?
        QString country = KGlobal::locale()->country();
        if( ! country.isEmpty() ) {
            locale += "_";
            locale += country.toUpper();
        }
    }
    locale += ".UTF-8";

    const char* newLocale = setlocale(LOCALE_CATEGORY, locale.toLatin1());
    if( newLocale == NULL ) {
        setlocale(LC_ALL, "C");
    }

... call libxklavier ...

    setlocale(LOCALE_CATEGORY, currLocale);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20071101/423b4090/attachment.htm>


More information about the kde-core-devel mailing list