Last active
December 15, 2024 07:28
-
-
Save define-private-public/f01ff2f9bbb74eded144558a2e02966c to your computer and use it in GitHub Desktop.
Qt Software Localizastion (and more) -- https://16bpp.net/blog/post/localizing-a-qt-app-or-anything-else-for-that-matter/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# `Linguist` is required | |
find_package(Qt6 COMPONENTS Linguist REQUIRED) | |
# ... | |
# Have your app specified | |
qt_add_executable(myapp ... | |
# ... | |
# Specify your translations | |
qt_add_translations(myapp | |
TS_FILES | |
i18n/myapp_de_DE.ts | |
i18n/myapp_ja_JP.ts | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Specify your translations | |
qt_add_translations(myapp | |
TS_FILES | |
i18n/myapp_de_DE.ts | |
i18n/myapp_ja_JP.ts | |
) | |
add_dependencies(myapp release_translations) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// User facing strings | |
QtObject { | |
// Render View | |
readonly property string app_window_title: qsTr('PSRayTracing (GUI Edition)') | |
readonly property string scene_label: qsTr('Scene:') | |
readonly property string stop: qsTr('Stop') | |
readonly property string render: qsTr('Render') | |
readonly property string total_render_time_fmt: qsTr('Total Render Time: %1') | |
// ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<!DOCTYPE TS> | |
<TS version="2.1" language="de_DE"> | |
<context> | |
<name>QObject</name> | |
<message> | |
<source>No</source> | |
<comment>denial</comment> | |
<translation type="obsolete">Nein</translation> | |
</message> | |
<message numerus="yes"> | |
<location filename="main.cpp" line="36"/> | |
<source>%Ln Apple(s)</source> | |
<translation type="unfinished"> | |
<numerusform>%Ln Apfel</numerusform> | |
<numerusform>%Ln Äpfel</numerusform> | |
</translation> | |
</message> | |
</context> | |
</TS> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Find this line | |
const QString baseName = "myapp_" + QLocale(locale).name(); | |
// Change it to this | |
const QString baseName = "myapp_" + QLocale().name(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QLocale::setDefault(QLocale::German); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto lbl = new QLabel("Hi Mom!"); | |
QString filePath = "data.csv"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto lbl = new QLabel(tr("Hi Mom!")); | |
QString filePath = QStringLiteral("data.csv"); | |
qDebug() << "Doing this with qDebug() is still okay though!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Controls] | |
Style=Basic | |
[Basic] | |
Font\PointSize=15 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<RCC> | |
<qresource prefix="/"> | |
<file>qtquickcontrols2.conf</file> | |
... | |
<!-- Japanese specific resources --> | |
<qresource prefix="/" lang="ja"> | |
<file alias="qtquickcontrols2.conf">i18n/qtquickcontrols2_ja_JP.conf</file> | |
</qresource> | |
</RCC> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
id: fields_layout | |
readonly property bool _small_width: UITheme.is_width_small(parent.width) | |
readonly property int column_count: (_small_width ? 1 : 2) | |
// ... | |
columns: fields_layout.column_count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QTranslator translator; | |
const QStringList uiLanguages = QLocale::system().uiLanguages(); | |
for (const QString &locale : uiLanguages) { | |
const QString baseName = "myapp_" + QLocale(locale).name(); | |
if (translator.load(":/i18n/" + baseName)) { | |
app.installTranslator(&translator); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment