Grantlee 5.3.0

Public Member Functions | List of all members
Grantlee::QtLocalizer Class Reference

Provides internationalization based on QLocale and QTranslator. More...

`#include <qtlocalizer.h>`

Inheritance diagram for Grantlee::QtLocalizer:
[legend]

## 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 Grantlee::AbstractLocalizer
| AbstractLocalizer ()
virtual | ~AbstractLocalizer ()
virtual QString | currentLocale () const =0
virtual void | loadCatalog (const QString &path, const QString &catalog)=0
virtual QString | localize (const QVariant &variant) const
virtual QString | localizeContextString (const QString &string, const QString &context, const QVariantList &arguments={}) const =0
virtual QString | localizeDate (const QDate &date, QLocale::FormatType formatType=QLocale::ShortFormat) const =0
virtual QString | localizeDateTime (const QDateTime &dateTime, QLocale::FormatType formatType=QLocale::ShortFormat) const =0
virtual QString | localizeMonetaryValue (qreal value, const QString &currencyCode={}) const =0
virtual QString | localizeNumber (int number) const =0
virtual QString | localizeNumber (qreal number) const =0
virtual QString | localizePluralContextString (const QString &string, const QString &pluralForm, const QString &context, const QVariantList &arguments={}) const =0
virtual QString | localizePluralString (const QString &string, const QString &pluralForm, const QVariantList &arguments={}) const =0
virtual QString | localizeString (const QString &string, const QVariantList &arguments={}) const =0
virtual QString | localizeTime (const QTime &time, QLocale::FormatType formatType=QLocale::ShortFormat) const =0
virtual void | popLocale ()=0
virtual void | pushLocale (const QString &localeName)=0
virtual void | unloadCatalog (const QString &catalog)=0

## Detailed Description

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 55 of file qtlocalizer.h.

## Constructor & Destructor Documentation

## ◆ QtLocalizer()

Grantlee::QtLocalizer::QtLocalizer | ( | const QLocale & | locale = `QLocale::system()` | ) |

Constructs a new QtLocalizer using the `locale`

## ◆ ~QtLocalizer()

Grantlee::QtLocalizer::~QtLocalizer | ( |  | ) |
| override

Destructor

## Member Function Documentation

## ◆ currentLocale()

QString Grantlee::QtLocalizer::currentLocale | ( |  | ) | const
| override virtual

Returns the current locale as a string.

Implements Grantlee::AbstractLocalizer.

## ◆ installTranslator()

void Grantlee::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");

## ◆ loadCatalog()

void Grantlee::QtLocalizer::loadCatalog | ( | const QString & | path,
|  | const QString & | catalog
| ) |  |
| override virtual

Loads the `catalog` from `path`.

Implements Grantlee::AbstractLocalizer.

## ◆ localizeContextString()

QString Grantlee::QtLocalizer::localizeContextString | ( | const QString & | string,
|  | const QString & | context,
|  | const QVariantList & | arguments = `{}`
| ) |  | const
| override virtual

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

Implements Grantlee::AbstractLocalizer.

## ◆ localizeDate()

QString Grantlee::QtLocalizer::localizeDate | ( | const QDate & | date,
|  | QLocale::FormatType | formatType = `QLocale::ShortFormat`
| ) |  | const
| override virtual

Localizes `date` with the specified `formatType`

Implements Grantlee::AbstractLocalizer.

## ◆ localizeDateTime()

QString Grantlee::QtLocalizer::localizeDateTime | ( | const QDateTime & | dateTime,
|  | QLocale::FormatType | formatType = `QLocale::ShortFormat`
| ) |  | const
| override virtual

Localizes `dateTime` with the specified `formatType`

Implements Grantlee::AbstractLocalizer.

## ◆ localizeMonetaryValue()

QString Grantlee::QtLocalizer::localizeMonetaryValue | ( | qreal | value,
|  | const QString & | currencyCode = `{}`
| ) |  | const
| override virtual

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

Implements Grantlee::AbstractLocalizer.

## ◆ localizeNumber() [1/2]

QString Grantlee::QtLocalizer::localizeNumber | ( | int | number | ) | const
| override virtual

Localizes `number`

Implements Grantlee::AbstractLocalizer.

## ◆ localizeNumber() [2/2]

QString Grantlee::QtLocalizer::localizeNumber | ( | qreal | number | ) | const
| override virtual

Localizes `number`

Implements Grantlee::AbstractLocalizer.

## ◆ localizePluralContextString()

QString Grantlee::QtLocalizer::localizePluralContextString | ( | const QString & | string,
|  | const QString & | pluralForm,
|  | const QString & | context,
|  | const QVariantList & | arguments = `{}`
| ) |  | const
| override virtual

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

Implements Grantlee::AbstractLocalizer.

## ◆ localizePluralString()

QString Grantlee::QtLocalizer::localizePluralString | ( | const QString & | string,
|  | const QString & | pluralForm,
|  | const QVariantList & | arguments = `{}`
| ) |  | const
| override virtual

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

Implements Grantlee::AbstractLocalizer.

## ◆ localizeString()

QString Grantlee::QtLocalizer::localizeString | ( | const QString & | string,
|  | const QVariantList & | arguments = `{}`
| ) |  | const
| override virtual

Localizes `string` with the specified `arguments` for substitution

Implements Grantlee::AbstractLocalizer.

## ◆ localizeTime()

QString Grantlee::QtLocalizer::localizeTime | ( | const QTime & | time,
|  | QLocale::FormatType | formatType = `QLocale::ShortFormat`
| ) |  | const
| override virtual

Localizes `time` with the specified `formatType`

Implements Grantlee::AbstractLocalizer.

## ◆ popLocale()

void Grantlee::QtLocalizer::popLocale | ( |  | ) |
| override virtual

Makes this localizer use the previous locale for output.

Implements Grantlee::AbstractLocalizer.

## ◆ pushLocale()

void Grantlee::QtLocalizer::pushLocale | ( | const QString & | localeName | ) |
| override virtual

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

Implements Grantlee::AbstractLocalizer.

## ◆ setAppTranslatorPath()

void Grantlee::QtLocalizer::setAppTranslatorPath | ( | const QString & | path | ) |

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

## ◆ setAppTranslatorPrefix()

void Grantlee::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_`.

## ◆ unloadCatalog()

void Grantlee::QtLocalizer::unloadCatalog | ( | const QString & | catalog | ) |
| override virtual

Unloads the `catalog`

Implements Grantlee::AbstractLocalizer.