Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
PhosphorControl::LocalizedContext Class Reference

Minimal QML i18n context that routes through Qt's translation system. More...

#include <PhosphorControl/LocalizedContext.h>

Inheritance diagram for PhosphorControl::LocalizedContext:
[legend]

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

Detailed Description

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.

Constructor & Destructor Documentation

◆ LocalizedContext()

PhosphorControl::LocalizedContext::LocalizedContext ( QObject * parent = nullptr)
explicit

◆ ~LocalizedContext()

PhosphorControl::LocalizedContext::~LocalizedContext ( )
override

Member Function Documentation

◆ i18n()

QString PhosphorControl::LocalizedContext::i18n ( const QString & text) const

◆ i18nc()

QString PhosphorControl::LocalizedContext::i18nc ( const QString & context,
const QString & text ) const

◆ i18ncp()

QString PhosphorControl::LocalizedContext::i18ncp ( const QString & context,
const QString & singular,
const QString & plural,
int n ) const

◆ i18np()

QString PhosphorControl::LocalizedContext::i18np ( const QString & singular,
const QString & plural,
int n ) const

◆ setTranslationContext()

void PhosphorControl::LocalizedContext::setTranslationContext ( const QString & ctx)

◆ translationContext()

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.

◆ translationContextChanged

void PhosphorControl::LocalizedContext::translationContextChanged ( )
signal

The documentation for this class was generated from the following file: