Minimal QML i18n context that routes through Qt's translation system. More...
#include <PhosphorControl/LocalizedContext.h>
Signals | |
| void | translationContextChanged () |
Public Member Functions | |
| LocalizedContext (QObject *parent=nullptr) | |
| ~LocalizedContext () override | |
| QString | translationContext () const |
| Returns the current translation context — the explicit setter value if non-empty, otherwise the live QCoreApplication::applicationName(). | |
| void | setTranslationContext (const QString &ctx) |
| QString | i18n (const QString &text) const |
| QString | i18nc (const QString &context, const QString &text) const |
| QString | i18np (const QString &singular, const QString &plural, int n) const |
| QString | i18ncp (const QString &context, const QString &singular, const QString &plural, int n) const |
Minimal QML i18n context that routes through Qt's translation system.
Install on a QQmlEngine so QML expressions can call i18n()/i18nc()/ i18np() as bare-word functions:
engine.rootContext()->setContextObject(new LocalizedContext(&engine));
The Q_INVOKABLE methods delegate to QCoreApplication::translate() with a configurable translation context — by default the application name.
Apps that already use KLocalizedContext (KF6CoreAddons) should prefer that — it provides richer plural forms and shares its catalogue with the broader KDE translation infrastructure. This class exists for Qt-only consumers that don't want a KF6 dependency.
|
explicit |
|
override |
| QString PhosphorControl::LocalizedContext::i18n | ( | const QString & | text | ) | const |
| QString PhosphorControl::LocalizedContext::i18nc | ( | const QString & | context, |
| const QString & | text ) const |
| QString PhosphorControl::LocalizedContext::i18ncp | ( | const QString & | context, |
| const QString & | singular, | ||
| const QString & | plural, | ||
| int | n ) const |
| QString PhosphorControl::LocalizedContext::i18np | ( | const QString & | singular, |
| const QString & | plural, | ||
| int | n ) const |
| void PhosphorControl::LocalizedContext::setTranslationContext | ( | const QString & | ctx | ) |
| QString PhosphorControl::LocalizedContext::translationContext | ( | ) | const |
Returns the current translation context — the explicit setter value if non-empty, otherwise the live QCoreApplication::applicationName().
Note: because the empty-state getter reads applicationName() at call time, the property's effective value can change without a NOTIFY emit if setApplicationName() is called externally while m_context is empty. This is intentional: consumers wanting to track late-binding application-name changes get them for free. Consumers wanting a stable value should call setTranslationContext() explicitly once at startup.
|
signal |