KLocalization

KLocalization Namespace Reference

Functions

template<typename T >
void retranslateSpinBoxFormatString (T *spinBox)
 
KLocalizedQmlContextsetupLocalizedContext (QQmlEngine *engine)
 
template<typename T >
void setupSpinBoxFormatString (T *spinBox, const KLocalizedString &formatString)
 

Detailed Description

Namespace containing helpers for localization.

Since
6.5

Function Documentation

◆ retranslateSpinBoxFormatString()

template<typename T >
void KLocalization::retranslateSpinBoxFormatString ( T * spinBox)
inline

Retranslates a previously set up format string to the current language and updates the spin box.

The format string is initially set up by setupSpinBoxFormatString(). This function updates the prefix and suffix of a spin box to reflect the current language settings. It is useful for responding to language changes, such as those triggered by QEvent::LanguageChange.

Template Parameters
TThe type of the spin box, which must be either QSpinBox or QDoubleSpinBox.
Parameters
spinBoxPointer to the spin box.
Postcondition
The prefix and suffix of the spin box are updated to reflect the current language.
See also
setupSpinBoxFormatString
Since
6.5

Definition at line 59 of file klocalization.h.

◆ setupLocalizedContext()

KLocalizedQmlContext * KLocalization::setupLocalizedContext ( QQmlEngine * engine)
inline

Creates a KLocalizedQmlContext engine and sets it up in the root context of engine.

If TRANSLATION_DOMAIN is defined, that is also set on the created context.

Since
6.8

Definition at line 316 of file klocalizedqmlcontext.h.

◆ setupSpinBoxFormatString()

template<typename T >
void KLocalization::setupSpinBoxFormatString ( T * spinBox,
const KLocalizedString & formatString )
inline

Sets up a format string for internationalizing spin boxes.

This function allows the customization of prefix and suffix for spin boxes (QSpinBox and QDoubleSpinBox), considering internationalization needs.

Spin boxes display a number and possibly a prefix and/or suffix. However, in some languages, the position of the prefix and suffix may be reversed compared to English. Example: In English, you write 50%, but in Turkish, you write %50. Qt does not offer an out-of-the-box solution for this. This helper now provides complete internationalization for prefixes and suffixes of spin boxes.

For QSpinBox it also provides correct plural handling by installing a handler for the valueChanged() signal to update prefix and suffix whenever the spin box value changes in the future.

Example usage:

QDoubleSpinBox doubleBox;
&doubleBox,
ki18nc("@item %v is a number and the second % is the percent sign", "%v%"));
// Turkish translation: "%%v"
QSpinBox intBox;
&intBox,
ki18ncp("@item %v is a number", "Baking %v cake", "Baking %v cakes"));
void setupSpinBoxFormatString(T *spinBox, const KLocalizedString &formatString)
Sets up a format string for internationalizing spin boxes.
Template Parameters
TThe type of the spin box, which must be either QSpinBox or QDoubleSpinBox.
Parameters
spinBoxPointer to the spin box.
formatStringA localized string in the format "PREFIX%vSUFFIX".
  • For QDoubleSpinBox, plural forms in formatString are ignored and should be avoided. Use ki18nc() to generate the format string.
  • For QSpinBox, if formatString includes plural forms, they are utilized. While optional, their use is highly recommended for accurate pluralization. Use ki18ncp() to generate the format string.
Note
It is safe to call this function multiple times on the same spin box.
See also
retranslateSpinBoxFormatString
Since
6.5

Definition at line 139 of file klocalization.h.

This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 12:01:24 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.