On Tuesday 26 July 2005 15:00, Tomasz Grobelny wrote:
> Dnia Tuesday 26 of July 2005 02:32, David Faure napisa=B3:
> > On Tuesday 26 July 2005 01:31, Tomasz Grobelny wrote:
> > > Is it possible to get locale settings for a given language? For examp=

le 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 wor=

ks
> > > at all): QString oldlang=3DKGlobal::locale()->language();
> > > KGlobal::locale()->setLanguage("en");
> > > QString dateInEnglish=3DKGlobal::locale()->formatDate(qdate);
> > > KGlobal::locale()->setLanguage(oldlang);

> >
> > This isn't C, no need to set/reset a global state when you can instanci=

ate
> > 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 =3D 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 =3D 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 unsubscrib=

e <<