KLazyLocalizedString
#include <KLazyLocalizedString>
Public Member Functions | |
constexpr | KLazyLocalizedString ()=default |
KLocalizedString | ignoreMarkup () const |
KLocalizedString | inContext (const QString &key, const QString &value) const |
constexpr bool | isEmpty () const |
operator KLocalizedString () const | |
KLocalizedString | relaxSubs () const |
KLocalizedString | subs (const KLocalizedString &a, int fieldWidth=0, QChar fillChar=QLatin1Char(' ')) const |
KLocalizedString | subs (const QString &a, int fieldWidth=0, QChar fillChar=QLatin1Char(' ')) const |
KLocalizedString | subs (double a, int fieldWidth=0, char format='g', int precision=-1, QChar fillChar=QLatin1Char(' ')) const |
KLocalizedString | subs (int a, int fieldWidth=0, int base=10, QChar fillChar=QLatin1Char(' ')) const |
KLocalizedString | subs (long a, int fieldWidth=0, int base=10, QChar fillChar=QLatin1Char(' ')) const |
KLocalizedString | subs (QChar a, int fieldWidth=0, QChar fillChar=QLatin1Char(' ')) const |
KLocalizedString | subs (qlonglong a, int fieldWidth=0, int base=10, QChar fillChar=QLatin1Char(' ')) const |
KLocalizedString | subs (qulonglong a, int fieldWidth=0, int base=10, QChar fillChar=QLatin1Char(' ')) const |
KLocalizedString | subs (uint a, int fieldWidth=0, int base=10, QChar fillChar=QLatin1Char(' ')) const |
KLocalizedString | subs (ulong a, int fieldWidth=0, int base=10, QChar fillChar=QLatin1Char(' ')) const |
QString | toString () const |
QString | toString (const char *domain) const |
QString | toString (const QStringList &languages) const |
QString | toString (Kuit::VisualFormat format) const |
constexpr const char * | untranslatedText () const |
KLocalizedString | withDomain (const char *domain) const |
KLocalizedString | withFormat (Kuit::VisualFormat format) const |
KLocalizedString | withLanguages (const QStringList &languages) const |
Detailed Description
Lazy-initialized variant of KLocalizedString.
This is a safer replacement for the I18N_NOOP set of macros and allows marking strings for extraction without runtime-initializing KLocalizedString instances, for storing in static data tables.
Instances of KLazyLocalizedString are not created directly, unless they should be empty. Instead they have to be obtained via the kli18n* functions (similar to KLocalizedString and the ki18n* functions).
Example usage in a static message table:
- Note
- KLazyLocalizedString is primarily meant for storage in e.g. message tables, not for use in API, especially not across translation domains. This is due to it not carrying the translation domain in which it was created, but using the active translation domain at the point of converting to a KLocalizedString.
- Since
- 5.89
Definition at line 50 of file klazylocalizedstring.h.
Constructor & Destructor Documentation
◆ KLazyLocalizedString()
|
inlineconstexprdefault |
Construct an empty message.
Direct construction is used when e.g. a KLazyLocalizedString field in a data table needs to be set, but there is not message to be used. Directly constructed instances are not valid for finalization by toString
methods.
- See also
- isEmpty
Member Function Documentation
◆ ignoreMarkup()
|
inline |
Do not resolve KUIT markup.
If the message is markup-aware (constructed by one of *xi18n*
calls), this function can be used to make it non-markup-aware. This may be useful for debugging markup.
- Returns
- updated KLocalizedString
Definition at line 404 of file klazylocalizedstring.h.
◆ inContext()
|
inline |
Add dynamic context to the message.
See dyn_ctxt for use cases.
- Parameters
-
key context key value context value
- Returns
- updated KLocalizedString
Definition at line 367 of file klazylocalizedstring.h.
◆ isEmpty()
|
inlineconstexpr |
Check whether the message is empty.
The message is considered empty if the object was constructed via the default constructor.
Empty messages are not valid for finalization. The behavior of calling toString() on them is undefined. In debug mode, an error mark may appear in the returned string.
- Returns
true
if the message is empty,false
otherwise
Definition at line 95 of file klazylocalizedstring.h.
◆ operator KLocalizedString()
|
inline |
Convert to a KLocalizedString to actually perform the translation and obtain a concrete localized string.
The translation domain active at this point will be used. This means this has to be called in the same translation domain the corresponding kli18n
call is in.
Definition at line 71 of file klazylocalizedstring.h.
◆ relaxSubs()
|
inline |
Relax matching between placeholders and arguments.
Normally the placeholders should start from %1 and have no gaps, and on finalization there must be exactly as many arguments supplied through subs
methods as there are unique plaecholders. If this is not satisfied, in debug mode warnings are printed and the finalized string may contain error marks.
This method relaxes the placeholder-argument matching, such that there must only be an argument available for every present unique placeholder (taking placeholder numbers to be 1-based indices into the argument list). This can come useful in some situations.
- Returns
- updated KLocalizedString
Definition at line 389 of file klazylocalizedstring.h.
◆ subs() [1/10]
|
inline |
Substitute another KLocalizedString into the message.
- Parameters
-
a the argument fieldWidth width of the formatted field, padded by spaces. Positive value aligns right, negative aligns left fillChar the character used to fill up the empty places when field width is greater than argument width
- Returns
- updated KLocalizedString
Definition at line 353 of file klazylocalizedstring.h.
◆ subs() [2/10]
|
inline |
Substitute a QString
argument into the message.
- Parameters
-
a the argument fieldWidth width of the formatted field, padded by spaces. Positive value aligns right, negative aligns left fillChar the character used to fill up the empty places when field width is greater than argument width
- Returns
- updated KLocalizedString
Definition at line 338 of file klazylocalizedstring.h.
◆ subs() [3/10]
|
inline |
Substitute a double argument into the message.
- Parameters
-
a the argument fieldWidth width of the formatted field, padded by spaces. Positive value aligns right, negative aligns left format type of floating point formatting, like in QString::arg precision number of digits after the decimal separator fillChar the character used to fill up the empty places when field width is greater than argument width
- Returns
- updated KLocalizedString
Definition at line 308 of file klazylocalizedstring.h.
◆ subs() [4/10]
|
inline |
Substitute an int argument into the message.
- Parameters
-
a the argument fieldWidth width of the formatted field, padded by spaces. Positive value aligns right, negative aligns left base the radix used to represent the number as a string. Valid values range from 2 to 36 fillChar the character used to fill up the empty places when field width is greater than argument width
- Returns
- updated KLocalizedString
Definition at line 207 of file klazylocalizedstring.h.
◆ subs() [5/10]
|
inline |
Substitute a long argument into the message.
- Parameters
-
a the argument fieldWidth width of the formatted field, padded by spaces. Positive value aligns right, negative aligns left base the radix used to represent the number as a string. Valid values range from 2 to 36 fillChar the character used to fill up the empty places when field width is greater than argument width
- Returns
- updated KLocalizedString
Definition at line 241 of file klazylocalizedstring.h.
◆ subs() [6/10]
|
inline |
Substitute a QChar
argument into the message.
- Parameters
-
a the argument fieldWidth width of the formatted field, padded by spaces. Positive value aligns right, negative aligns left fillChar the character used to fill up the empty places when field width is greater than argument width
- Returns
- updated KLocalizedString
Definition at line 323 of file klazylocalizedstring.h.
◆ subs() [7/10]
|
inline |
Substitute a long long argument into the message.
- Parameters
-
a the argument fieldWidth width of the formatted field, padded by spaces. Positive value aligns right, negative aligns left base the radix used to represent the number as a string. Valid values range from 2 to 36 fillChar the character used to fill up the empty places when field width is greater than argument width
- Returns
- updated KLocalizedString
Definition at line 275 of file klazylocalizedstring.h.
◆ subs() [8/10]
|
inline |
Substitute an unsigned long long argument into the message.
- Parameters
-
a the argument fieldWidth width of the formatted field, padded by spaces. Positive value aligns right, negative aligns left base the radix used to represent the number as a string. Valid values range from 2 to 36 fillChar the character used to fill up the empty places when field width is greater than argument width
- Returns
- updated KLocalizedString
Definition at line 292 of file klazylocalizedstring.h.
◆ subs() [9/10]
|
inline |
Substitute an unsigned int argument into the message.
- Parameters
-
a the argument fieldWidth width of the formatted field, padded by spaces. Positive value aligns right, negative aligns left base the radix used to represent the number as a string. Valid values range from 2 to 36 fillChar the character used to fill up the empty places when field width is greater than argument width
- Returns
- updated KLocalizedString
Definition at line 224 of file klazylocalizedstring.h.
◆ subs() [10/10]
|
inline |
Substitute an unsigned long argument into the message.
- Parameters
-
a the argument fieldWidth width of the formatted field, padded by spaces. Positive value aligns right, negative aligns left base the radix used to represent the number as a string. Valid values range from 2 to 36 fillChar the character used to fill up the empty places when field width is greater than argument width
- Returns
- updated KLocalizedString
Definition at line 258 of file klazylocalizedstring.h.
◆ toString() [1/4]
|
inline |
Finalize the translation.
Creates translated QString. If the string has placeholders, make sure to call instead KLazyLocalizedString::subs
and further KLocalizedString::subs
methods before finalizing. Translated text is searched for based on the global locale.
- Returns
- finalized translation
Definition at line 116 of file klazylocalizedstring.h.
◆ toString() [2/4]
|
inline |
Like toString(), but look for translation in the given domain.
- Parameters
-
domain the translation domain
- Returns
- finalized translation
Definition at line 141 of file klazylocalizedstring.h.
◆ toString() [3/4]
|
inline |
Like toString(), but look for translation only in given languages.
Given languages override languages defined by the global locale. If languages
is empty, original message is returned.
- Parameters
-
languages list of language codes (by decreasing priority)
- Returns
- finalized translation
Definition at line 130 of file klazylocalizedstring.h.
◆ toString() [4/4]
|
inline |
Like toString(), but resolve KUIT markup into given visual format.
Given visual format overrides that implied by the context UI marker. If the message is not markup-aware, this is same as toString().
- Parameters
-
format the target visual format
- Returns
- finalized translation
Definition at line 155 of file klazylocalizedstring.h.
◆ untranslatedText()
|
inlineconstexpr |
Returns the raw untranslated text as passed to kli18n*
.
Definition at line 101 of file klazylocalizedstring.h.
◆ withDomain()
|
inline |
Indicate to look for translation in the given domain.
- Parameters
-
domain the translation domain
- Returns
- updated KLocalizedString
Definition at line 177 of file klazylocalizedstring.h.
◆ withFormat()
|
inline |
Indicate to resolve KUIT markup into given visual format.
If the message is not markup-aware, this has no effect.
- Parameters
-
format the target visual format
- Returns
- updated KLocalizedString
Definition at line 190 of file klazylocalizedstring.h.
◆ withLanguages()
|
inline |
Indicate to look for translation only in given languages.
- Parameters
-
languages list of language codes (by decreasing priority)
- Returns
- updated KLocalizedString
Definition at line 166 of file klazylocalizedstring.h.
The documentation for this class was generated from the following file:
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:05:34 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.