[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: locale settings by language
From:       David Faure <faure () kde ! org>
Date:       2005-07-27 10:32:23
Message-ID: 200507271232.23742.faure () kde ! org
[Download RAW message or body]

On Tuesday 26 July 2005 15:00, Tomasz Grobelny wrote:
> Dnia Tuesday 26 of July 2005 02:32, David Faure napisał:
> > On Tuesday 26 July 2005 01:31, Tomasz Grobelny wrote:
> > > Is it possible to get locale settings for a given language? For example I
> > > want to format date in English while my current locale is Polish. If
> > > there is no appropriate function would such a code be safe (if it works
> > > at all): QString oldlang=KGlobal::locale()->language();
> > > KGlobal::locale()->setLanguage("en");
> > > QString dateInEnglish=KGlobal::locale()->formatDate(qdate);
> > > KGlobal::locale()->setLanguage(oldlang);
> >
> > This isn't C, no need to set/reset a global state when you can instanciate
> > a class ;-)
> >
> I felt it was not the best solution, that's why I asked. BTW, see 
> kdepim/libkmime/kmime_util.cpp:715

Well.... someone went ahead without asking here first ;)
Of course creating a KLocale instance might be expensive, so the solution
of creating one instead of switching the global one should probably only
be done when the other klocale can be kept somewhere and reused (like
in kspread).

> > KLocale englishLanguage("en");
> > QString dateInEnglish = englishLanguage.formatDate(qdate);
> >
> > should work.
> But it doesn't. 
Sorry, the parameter isn't the language, but the instance name...

// Do this once when first needed
KLocale englishLanguage(KGlobal::instance()->instanceName());
englishLanguage.setLanguage( "en_US" );  // or "C"

// Then do this to format a date in english
QString dateInEnglish = englishLanguage.formatDate(qdate);

[still untested though ;)]

>  KLocale polishLanguage("pl_PL"); //"pl" doesn't work either
It's setLanguage("pl"). The string to use is the language as known in l10n/.

-- 
David Faure, faure@kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).

 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic