KTextTemplate::QtLocalizer

Search for usage in LXR

KTextTemplate::QtLocalizer Class Reference

#include <KTextTemplate/QtLocalizer>

Inheritance diagram for KTextTemplate::QtLocalizer:

Public Member Functions

 QtLocalizer (const QLocale &locale=QLocale::system())
 
 ~QtLocalizer () override
 
QString currentLocale () const override
 
void installTranslator (QTranslator *translator, const QString &localeName=QLocale::system().name())
 
void loadCatalog (const QString &path, const QString &catalog) override
 
QString localizeContextString (const QString &string, const QString &context, const QVariantList &arguments={}) const override
 
QString localizeDate (const QDate &date, QLocale::FormatType formatType=QLocale::ShortFormat) const override
 
QString localizeDateTime (const QDateTime &dateTime, QLocale::FormatType formatType=QLocale::ShortFormat) const override
 
QString localizeMonetaryValue (qreal value, const QString &currencyCode={}) const override
 
QString localizeNumber (int number) const override
 
QString localizeNumber (qreal number) const override
 
QString localizePluralContextString (const QString &string, const QString &pluralForm, const QString &context, const QVariantList &arguments={}) const override
 
QString localizePluralString (const QString &string, const QString &pluralForm, const QVariantList &arguments={}) const override
 
QString localizeString (const QString &string, const QVariantList &arguments={}) const override
 
QString localizeTime (const QTime &time, QLocale::FormatType formatType=QLocale::ShortFormat) const override
 
void popLocale () override
 
void pushLocale (const QString &localeName) override
 
void setAppTranslatorPath (const QString &path)
 
void setAppTranslatorPrefix (const QString &prefix)
 
void unloadCatalog (const QString &catalog) override
 
- Public Member Functions inherited from KTextTemplate::AbstractLocalizer
 AbstractLocalizer ()
 
virtual ~AbstractLocalizer ()
 
virtual QString localize (const QVariant &variant) const
 

Detailed Description

Provides internationalization based on QLocale and QTranslator.

This class implements access to the Qt Localization system. Localizable types such as strings, numbers, dates and times can be processed.

auto t = m_engine->loadTemplate(someTemplate);
auto c = getContext();
// Render with the German locale
c.setLocalizer(m_de_Localizer);
auto deText = t->render(&c);
de_display->setText(deText);
// Render with the French locale
c.setLocalizer(m_fr_Localizer);
auto frText = t->render(&c);
fr_display->setText(frText);

Definition at line 46 of file qtlocalizer.h.

Constructor & Destructor Documentation

◆ QtLocalizer()

QtLocalizer::QtLocalizer ( const QLocale & locale = QLocale::system())

Constructs a new QtLocalizer using the locale.

Definition at line 141 of file qtlocalizer.cpp.

◆ ~QtLocalizer()

QtLocalizer::~QtLocalizer ( )
override

Destructor.

Definition at line 146 of file qtlocalizer.cpp.

Member Function Documentation

◆ currentLocale()

QString QtLocalizer::currentLocale ( ) const
overridevirtual

Returns the current locale as a string.

Implements KTextTemplate::AbstractLocalizer.

Definition at line 267 of file qtlocalizer.cpp.

◆ installTranslator()

void QtLocalizer::installTranslator ( QTranslator * translator,
const QString & localeName = QLocale::system().name() )

Install a translator to use for a particular localeName.

auto deTranslator = new QTranslator(this);
auto loaded = deTranslator->load("myapp_de_DE");
if (!loaded)
return;
de_localizer->installTranslator(deTranslator, "de_DE");

Definition at line 163 of file qtlocalizer.cpp.

◆ loadCatalog()

void QtLocalizer::loadCatalog ( const QString & path,
const QString & catalog )
overridevirtual

Loads the catalog from path.

Implements KTextTemplate::AbstractLocalizer.

Definition at line 300 of file qtlocalizer.cpp.

◆ localizeContextString()

QString QtLocalizer::localizeContextString ( const QString & string,
const QString & context,
const QVariantList & arguments = {} ) const
overridevirtual

Localizes string, disambiguated by context with the specified arguments for substitution.

Implements KTextTemplate::AbstractLocalizer.

Definition at line 233 of file qtlocalizer.cpp.

◆ localizeDate()

QString QtLocalizer::localizeDate ( const QDate & date,
QLocale::FormatType formatType = QLocale::ShortFormat ) const
overridevirtual

Localizes date with the specified formatType.

Implements KTextTemplate::AbstractLocalizer.

Definition at line 173 of file qtlocalizer.cpp.

◆ localizeDateTime()

QString QtLocalizer::localizeDateTime ( const QDateTime & dateTime,
QLocale::FormatType formatType = QLocale::ShortFormat ) const
overridevirtual

Localizes dateTime with the specified formatType.

Implements KTextTemplate::AbstractLocalizer.

Definition at line 185 of file qtlocalizer.cpp.

◆ localizeMonetaryValue()

QString QtLocalizer::localizeMonetaryValue ( qreal value,
const QString & currencyCode = {} ) const
overridevirtual

Localizes value as a monetary value in the currency specified by currencyCode.

Implements KTextTemplate::AbstractLocalizer.

Definition at line 203 of file qtlocalizer.cpp.

◆ localizeNumber() [1/2]

QString QtLocalizer::localizeNumber ( int number) const
overridevirtual

Localizes number.

Implements KTextTemplate::AbstractLocalizer.

Definition at line 191 of file qtlocalizer.cpp.

◆ localizeNumber() [2/2]

QString QtLocalizer::localizeNumber ( qreal number) const
overridevirtual

Localizes number.

Implements KTextTemplate::AbstractLocalizer.

Definition at line 197 of file qtlocalizer.cpp.

◆ localizePluralContextString()

QString QtLocalizer::localizePluralContextString ( const QString & string,
const QString & pluralForm,
const QString & context,
const QVariantList & arguments = {} ) const
overridevirtual

Localizes string or its pluralForm, disambiguated by context with the specified arguments for substitution.

Implements KTextTemplate::AbstractLocalizer.

Definition at line 247 of file qtlocalizer.cpp.

◆ localizePluralString()

QString QtLocalizer::localizePluralString ( const QString & string,
const QString & pluralForm,
const QVariantList & arguments = {} ) const
overridevirtual

Localizes string or its pluralForm with the specified arguments for substitution.

Implements KTextTemplate::AbstractLocalizer.

Definition at line 257 of file qtlocalizer.cpp.

◆ localizeString()

QString QtLocalizer::localizeString ( const QString & string,
const QVariantList & arguments = {} ) const
overridevirtual

Localizes string with the specified arguments for substitution.

Implements KTextTemplate::AbstractLocalizer.

Definition at line 240 of file qtlocalizer.cpp.

◆ localizeTime()

QString QtLocalizer::localizeTime ( const QTime & time,
QLocale::FormatType formatType = QLocale::ShortFormat ) const
overridevirtual

Localizes time with the specified formatType.

Implements KTextTemplate::AbstractLocalizer.

Definition at line 179 of file qtlocalizer.cpp.

◆ popLocale()

void QtLocalizer::popLocale ( )
overridevirtual

Makes this localizer use the previous locale for output.

Implements KTextTemplate::AbstractLocalizer.

Definition at line 293 of file qtlocalizer.cpp.

◆ pushLocale()

void QtLocalizer::pushLocale ( const QString & localeName)
overridevirtual

Makes this localizer use the locale specified by localeName for output.

Implements KTextTemplate::AbstractLocalizer.

Definition at line 273 of file qtlocalizer.cpp.

◆ setAppTranslatorPath()

void QtLocalizer::setAppTranslatorPath ( const QString & path)

Set the path to look for translations of the application strings.

Definition at line 151 of file qtlocalizer.cpp.

◆ setAppTranslatorPrefix()

void QtLocalizer::setAppTranslatorPrefix ( const QString & prefix)

Set the prefix of translation files.

For example, if the German translation file is called myapp_de_DE.qm, the prefix should be set to myapp_.

Definition at line 157 of file qtlocalizer.cpp.

◆ unloadCatalog()

void QtLocalizer::unloadCatalog ( const QString & catalog)
overridevirtual

Unloads the catalog.

Implements KTextTemplate::AbstractLocalizer.

Definition at line 317 of file qtlocalizer.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:17:29 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.