KTextTemplate::QtLocalizer Class
class KTextTemplate::QtLocalizerProvides internationalization based on QLocale and QTranslator. More...
Header: | #include <KTextTemplate/QtLocalizer> |
CMake: | find_package(KF6 REQUIRED COMPONENTS TextTemplate) target_link_libraries(mytarget PRIVATE KF6::TextTemplate) |
Inherits: | KTextTemplate::AbstractLocalizer |
Public Functions
QtLocalizer(const QLocale &locale = QLocale::system()) | |
void | installTranslator(QTranslator *translator, const QString &localeName = QLocale::system().name()) |
void | setAppTranslatorPath(const QString &path) |
void | setAppTranslatorPrefix(const QString &prefix) |
Detailed Description
This class implements access to the %Qt Localization system. Localizable types such as strings, numbers, dates and times can be processed.
auto t = m_engine->loadTemplate(someTemplate); auto c = getContext(); // Render with the German locale c.setLocalizer(m_de_Localizer); auto deText = t->render(&c); de_display->setText(deText); // Render with the French locale c.setLocalizer(m_fr_Localizer); auto frText = t->render(&c); fr_display->setText(frText);
Member Function Documentation
QtLocalizer::QtLocalizer(const QLocale &locale = QLocale::system())
Constructs a new QtLocalizer using the locale
void QtLocalizer::installTranslator(QTranslator *translator, const QString &localeName = QLocale::system().name())
Install a translator to use for a particular localeName.
auto deTranslator = new QTranslator(this); auto loaded = deTranslator->load("myapp_de_DE"); if (!loaded) return; de_localizer->installTranslator(deTranslator, "de_DE");
void QtLocalizer::setAppTranslatorPath(const QString &path)
Set the path to look for translations of the application strings.
void QtLocalizer::setAppTranslatorPrefix(const QString &prefix)
Set the prefix of translation files. For example, if the German translation file is called myapp_de_DE.qm, the prefix should be set to myapp_.