[kde-linux] Wrong language detection in KDE since 3.1

Lukáš Tinkl lukas at kde.org
Fri Mar 28 20:58:27 GMT 2003


Dne pá 28. března 2003 17:01 Ingo Klöcker napsal(a):
> Sergey M. Serov wrote:
> > Hello, KDE!
> > You guys doing a good job, keep it going, but I have some problem....
> >
> > How does KDE determinate a user language?
> > It seems that it did use LANG or LC_MESSAGES before 3.1 but now it
> > uses LC_CTYPE.
> > I think it's a bug.
>
> Me too (see below).
>
> > I need to have LANG and LC_MESSAGES to be set to en_US but I need
> > LC_CTYPE an LC_COLLATE to be set ru_RU.CP1251.
> > But when I set LC_CTYPE to ru_RU.CP1251 every KDE apps starts with
> > Russian interface.
> > What I should gonna do?
>
> Wait until KDE is fixed.
>
>
> Why is KDE's behavior wrong? Let's have a look at the man page for
> locale(7):
> =====
> If the second argument to setlocale() is empty string, "", for the
> default  locale, it is determined using the following steps:
> 1. If there is a non-null environment variable LC_ALL, the value of
>    LC_ALL is used.
> 2. If an environment variable with the same name as one of the
>    categories above exists and is non-null, its value is used for that
>    category.
> 3. If there is a non-null environment variable LANG, the value of LANG
>    is used.
> =====
>
>
> Excerpt of kdelibs/kdecore/klocale.cpp:
> =====
> void KLocale::initLanguage(KConfig * config, bool useEnv)
> {
>   KConfigGroupSaver saver(config, "Locale");
>
>   m_country = config->readEntry( "Country" );
>   if ( m_country.isEmpty() )
>     m_country = defaultCountry();
>
>   // Reset the list and add the new languages
>   QStringList languageList;
>   if ( useEnv )
>     languageList += QStringList::split
>       (':', QFile::decodeName( ::getenv("KDE_LANG") ));
>
>   languageList += config->readListEntry("Language", ':');
>
>   // same order as setlocale use
>   if ( useEnv )
>     {
>       // HPB: Only run splitLocale on the environment variables..
>       QStringList langs;
>
>       langs << QFile::decodeName( ::getenv("LC_CTYPE") );
>       langs << QFile::decodeName( ::getenv("LC_MESSAGES") );
>       langs << QFile::decodeName( ::getenv("LC_ALL") );
>       langs << QFile::decodeName( ::getenv("LANG") );
> =====
>
>
> According to the aforementioned man page to following change would
> correct KDE's language determination:
> =====
> -      langs << QFile::decodeName( ::getenv("LC_CTYPE") );
> -      langs << QFile::decodeName( ::getenv("LC_MESSAGES") );
>        langs << QFile::decodeName( ::getenv("LC_ALL") );
> +      langs << QFile::decodeName( ::getenv("LC_MESSAGES") );
>        langs << QFile::decodeName( ::getenv("LANG") );
> =====
>
> The line
>       langs << QFile::decodeName( ::getenv("LC_CTYPE") );
> was added by lukas with the cvs comment:
> =====
> respect LC_CTYPE as well, fixes #32485
> =====
>
> Bug 32485 (http://bugs.kde.org/show_bug.cgi?id=32485) is
> =====
>  KDE should take also LC_CTYPE contents
>  during the first start if LC_ALL or LANG
>  is not set.
> =====
>
> Obviously the fix is wrong (because it prefers LC_CTYPE over the other
> environment variables). The correct fix would have been to add
>       langs << QFile::decodeName( ::getenv("LC_CTYPE") );
> _after_ the three other lines.
>
> Does anyone object against the following change:
> =====
> -      langs << QFile::decodeName( ::getenv("LC_CTYPE") );
> -      langs << QFile::decodeName( ::getenv("LC_MESSAGES") );
>        langs << QFile::decodeName( ::getenv("LC_ALL") );
> +      langs << QFile::decodeName( ::getenv("LC_MESSAGES") );
>        langs << QFile::decodeName( ::getenv("LANG") );
> +      langs << QFile::decodeName( ::getenv("LC_CTYPE") );
> =====
>
> Regards,
> Ingo

Do you know what happens if the root user has LANG=C (or en_US) or 
LC_MESSAGES=C (or en_US) but you still want to enter non-english characters 
under root? Did you actually test that?

-- 
Lukáš Tinkl (lukas at kde.org, lukas.tinkl at suse.cz)
KDE developer | SuSE Labs | KOffice release manager
http://czechia.kde.org





More information about the kde-core-devel mailing list