Skip to content

Instantly share code, notes, and snippets.

@define-private-public
Last active December 15, 2024 07:28
Show Gist options
  • Select an option

  • Save define-private-public/f01ff2f9bbb74eded144558a2e02966c to your computer and use it in GitHub Desktop.

Select an option

Save define-private-public/f01ff2f9bbb74eded144558a2e02966c to your computer and use it in GitHub Desktop.

Revisions

  1. define-private-public revised this gist Oct 10, 2022. 2 changed files with 3 additions and 1 deletion.
    2 changes: 2 additions & 0 deletions RenderSettingsForm.qml
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    id: fields_layout

    readonly property bool _small_width: UITheme.is_width_small(parent.width)
    readonly property int column_count: (_small_width ? 1 : 2)

    2 changes: 1 addition & 1 deletion qlocale_main.cpp
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    QLocale::setDefault(QLocale::German);
    QLocale::setDefault(QLocale::German);
  2. define-private-public revised this gist Oct 10, 2022. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions RenderSettingsForm.qml
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    readonly property bool _small_width: UITheme.is_width_small(parent.width)
    readonly property int column_count: (_small_width ? 1 : 2)
    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
  3. define-private-public revised this gist Oct 10, 2022. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions RenderSettingsForm.qml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    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
  4. define-private-public revised this gist Oct 10, 2022. 4 changed files with 25 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions Messages.qml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    // 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')

    // ...
    5 changes: 5 additions & 0 deletions qlocal_translation_forcing_main.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    // Find this line
    const QString baseName = "myapp_" + QLocale(locale).name();

    // Change it to this
    const QString baseName = "myapp_" + QLocale().name();
    1 change: 1 addition & 0 deletions qlocale_main.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    QLocale::setDefault(QLocale::German);
    9 changes: 9 additions & 0 deletions translation_installer.main.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    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;
    }
    }
  5. define-private-public revised this gist Oct 10, 2022. 1 changed file with 14 additions and 14 deletions.
    28 changes: 14 additions & 14 deletions myapp_de_DE.ts
    Original file line number Diff line number Diff line change
    @@ -2,19 +2,19 @@
    <!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>
    <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>
  6. define-private-public revised this gist Oct 10, 2022. 3 changed files with 43 additions and 0 deletions.
    16 changes: 16 additions & 0 deletions CMakeLists.1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    # `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
    )
    7 changes: 7 additions & 0 deletions CMakeLists.2.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    # Specify your translations
    qt_add_translations(myapp
    TS_FILES
    i18n/myapp_de_DE.ts
    i18n/myapp_ja_JP.ts
    )
    add_dependencies(myapp release_translations)
    20 changes: 20 additions & 0 deletions myapp_de_DE.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    <?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>
  7. define-private-public revised this gist Oct 10, 2022. 2 changed files with 16 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions qtquickcontrols2_ja_JP.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    [Controls]
    Style=Basic

    [Basic]
    Font\PointSize=15
    11 changes: 11 additions & 0 deletions rcc.qrc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    <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>
  8. define-private-public created this gist Oct 10, 2022.
    2 changes: 2 additions & 0 deletions qstringliteral_example.1.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    auto lbl = new QLabel("Hi Mom!");
    QString filePath = "data.csv";
    4 changes: 4 additions & 0 deletions qstringliteral_example.2.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    auto lbl = new QLabel(tr("Hi Mom!"));
    QString filePath = QStringLiteral("data.csv");

    qDebug() << "Doing this with qDebug() is still okay though!"