File indexing completed on 2025-02-09 04:28:36

0001 /*
0002   This file is part of the KTextTemplate library
0003 
0004   SPDX-FileCopyrightText: 2010 Stephen Kelly <steveire@gmail.com>
0005 
0006   SPDX-License-Identifier: LGPL-2.1-or-later
0007 
0008 */
0009 
0010 #ifndef KTEXTTEMPLATE_ABSTRACTLOCALIZER_H
0011 #define KTEXTTEMPLATE_ABSTRACTLOCALIZER_H
0012 
0013 #include "ktexttemplate_export.h"
0014 
0015 #include <QLocale>
0016 #include <QSharedPointer>
0017 #include <QVariantList>
0018 
0019 class QDateTime;
0020 
0021 namespace KTextTemplate
0022 {
0023 
0024 /// @headerfile abstractlocalizer.h <KTextTemplate/AbstractLocalizer>
0025 
0026 /**
0027   @brief Interface for implementing an internationalization system.
0028 
0029   This class defines an interface for accessing an internationalization, such as
0030   QLocale/QTranslator or gettext/KLocale.
0031 
0032   @author Stephen Kelly <steveire@gmail.com>
0033 */
0034 class KTEXTTEMPLATE_EXPORT AbstractLocalizer
0035 {
0036 public:
0037     /**
0038      Constructor
0039     */
0040     AbstractLocalizer();
0041 
0042     /**
0043      Destructor
0044     */
0045     virtual ~AbstractLocalizer();
0046 
0047     /**
0048       Processes the data in @p variant into a localized string.
0049 
0050       The base implementation can localize numbers, dates and times, and
0051       strings.
0052     */
0053     virtual QString localize(const QVariant &variant) const;
0054 
0055     /**
0056       Returns the current locale as a string.
0057     */
0058     virtual QString currentLocale() const = 0;
0059 
0060     /**
0061       Makes this localizer use the locale specified by @p localeName for output.
0062     */
0063     virtual void pushLocale(const QString &localeName) = 0;
0064 
0065     /**
0066       Makes this localizer use the previous locale for output.
0067      */
0068     virtual void popLocale() = 0;
0069 
0070     /**
0071       Loads the @p catalog from @p path.
0072     */
0073     virtual void loadCatalog(const QString &path, const QString &catalog) = 0;
0074 
0075     /**
0076       Unloads the @p catalog
0077     */
0078     virtual void unloadCatalog(const QString &catalog) = 0;
0079 
0080     /**
0081       Localizes @p number
0082     */
0083     virtual QString localizeNumber(int number) const = 0;
0084 
0085     /**
0086       Localizes @p number
0087     */
0088     virtual QString localizeNumber(qreal number) const = 0;
0089 
0090     /**
0091       Localizes @p value as a monetary value in the currency specified by @p
0092       currencyCode.
0093     */
0094     virtual QString localizeMonetaryValue(qreal value, const QString &currencyCode = {}) const = 0;
0095 
0096     /**
0097       Localizes @p date with the specified @p formatType
0098     */
0099     virtual QString localizeDate(const QDate &date, QLocale::FormatType formatType = QLocale::ShortFormat) const = 0;
0100 
0101     /**
0102       Localizes @p time with the specified @p formatType
0103     */
0104     virtual QString localizeTime(const QTime &time, QLocale::FormatType formatType = QLocale::ShortFormat) const = 0;
0105 
0106     /**
0107       Localizes @p dateTime with the specified @p formatType
0108     */
0109     virtual QString localizeDateTime(const QDateTime &dateTime, QLocale::FormatType formatType = QLocale::ShortFormat) const = 0;
0110 
0111     /**
0112       Localizes @p string with the specified @p arguments for substitution
0113     */
0114     virtual QString localizeString(const QString &string, const QVariantList &arguments = {}) const = 0;
0115 
0116     /**
0117       Localizes @p string, disambiguated by @p context with the specified @p
0118       arguments for substitution
0119     */
0120     virtual QString localizeContextString(const QString &string, const QString &context, const QVariantList &arguments = {}) const = 0;
0121 
0122     /**
0123       Localizes @p string or its @p pluralForm with the specified @p arguments
0124       for substitution
0125     */
0126     virtual QString localizePluralString(const QString &string, const QString &pluralForm, const QVariantList &arguments = {}) const = 0;
0127 
0128     /**
0129       Localizes @p string or its @p pluralForm, disambiguated by @p context with
0130       the specified @p arguments for substitution
0131     */
0132     virtual QString
0133     localizePluralContextString(const QString &string, const QString &pluralForm, const QString &context, const QVariantList &arguments = {}) const = 0;
0134 
0135 private:
0136     Q_DISABLE_COPY(AbstractLocalizer)
0137 };
0138 }
0139 
0140 #endif