KTextTemplate

qtlocalizer.h
1/*
2 This file is part of the KTextTemplate library
3
4 SPDX-FileCopyrightText: 2010 Stephen Kelly <steveire@gmail.com>
5
6 SPDX-License-Identifier: LGPL-2.1-or-later
7
8*/
9
10#ifndef KTEXTTEMPLATE_QTLOCALIZER_P_H
11#define KTEXTTEMPLATE_QTLOCALIZER_P_H
12
13#include "abstractlocalizer.h"
14
15class QTranslator;
16
17namespace KTextTemplate
18{
19
20class QtLocalizerPrivate;
21
22/// @headerfile qtlocalizer.h <KTextTemplate/QtLocalizer>
23
24/**
25 @brief Provides internationalization based on QLocale and QTranslator.
26
27 This class implements access to the %Qt Localization system. Localizable
28 types such as strings, numbers, dates and times can be processed.
29
30 @code
31 auto t = m_engine->loadTemplate(someTemplate);
32 auto c = getContext();
33
34 // Render with the German locale
35 c.setLocalizer(m_de_Localizer);
36 auto deText = t->render(&c);
37 de_display->setText(deText);
38
39 // Render with the French locale
40 c.setLocalizer(m_fr_Localizer);
41 auto frText = t->render(&c);
42 fr_display->setText(frText);
43 @endcode
44
45*/
46class KTEXTTEMPLATE_EXPORT QtLocalizer : public AbstractLocalizer
47{
48public:
49 /**
50 Constructs a new **%QtLocalizer** using the @p locale
51 */
52 QtLocalizer(const QLocale &locale = QLocale::system());
53
54 /**
55 Destructor
56 */
57 ~QtLocalizer() override;
58
59 /**
60 Set the path to look for translations of the application strings.
61 */
62 void setAppTranslatorPath(const QString &path);
63
64 /**
65 Set the prefix of translation files. For example, if the German translation
66 file is called <tt>myapp_de_DE.qm</tt>, the prefix should be set to
67 <tt>myapp_</tt>.
68 */
69 void setAppTranslatorPrefix(const QString &prefix);
70
71 /**
72 Install a @p translator to use for a particular @p localeName.
73
74 @code
75 auto deTranslator = new QTranslator(this);
76 auto loaded = deTranslator->load("myapp_de_DE");
77 if (!loaded)
78 return;
79
80 de_localizer->installTranslator(deTranslator, "de_DE");
81 @endcode
82 */
83 void installTranslator(QTranslator *translator, const QString &localeName = QLocale::system().name());
84
85 QString currentLocale() const override;
86 void pushLocale(const QString &localeName) override;
87 void popLocale() override;
88 void loadCatalog(const QString &path, const QString &catalog) override;
89 void unloadCatalog(const QString &catalog) override;
90
91 QString localizeNumber(int number) const override;
92 QString localizeNumber(qreal number) const override;
93 QString localizeMonetaryValue(qreal value, const QString &currencyCode = {}) const override;
94 QString localizeDate(const QDate &date, QLocale::FormatType formatType = QLocale::ShortFormat) const override;
95 QString localizeTime(const QTime &time, QLocale::FormatType formatType = QLocale::ShortFormat) const override;
96 QString localizeDateTime(const QDateTime &dateTime, QLocale::FormatType formatType = QLocale::ShortFormat) const override;
97 QString localizeString(const QString &string, const QVariantList &arguments = {}) const override;
98 QString localizeContextString(const QString &string, const QString &context, const QVariantList &arguments = {}) const override;
100 localizePluralContextString(const QString &string, const QString &pluralForm, const QString &context, const QVariantList &arguments = {}) const override;
101 QString localizePluralString(const QString &string, const QString &pluralForm, const QVariantList &arguments = {}) const override;
102
103private:
104 Q_DECLARE_PRIVATE(QtLocalizer)
105 Q_DISABLE_COPY(QtLocalizer)
106 QtLocalizerPrivate *const d_ptr;
107};
108}
109
110#endif
Interface for implementing an internationalization system.
Provides internationalization based on QLocale and QTranslator.
Definition qtlocalizer.h:47
The KTextTemplate namespace holds all public KTextTemplate API.
Definition Mainpage.dox:8
QLocale system()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:42 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.