OmixVisualization / qtjambi

QtJambi is a wrapper for using Qt in Java.
http://www.qtjambi.io
Other
365 stars 43 forks source link

Internationalization Issue #189

Closed Bili-TianX closed 9 months ago

Bili-TianX commented 9 months ago

Is your feature request related to a problem? Please describe.

Yes. I created a .pro file:

SOURCES = src/main/kotlin/top/bilitianx/Window.kt

source code:

// Window.kt
package top.bilitianx

import io.qt.widgets.*

class Window : QWidget() {
    private val button = QPushButton(tr("Button"), this)
}

and run the command:

lupdate 1.pro -ts 1.ts

After I finished the translation, I run:

lrelease.exe 1.ts -qm 1.qm

Then I copied it to the resources folder and run my program. However, it didn't work.


I found out that it was because the "context" in the ts file was wrong.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<context>
    <name>Window</name>
    <message>
        <location filename="src/main/kotlin/top/bilitianx/Window.kt" line="6"/>
        <source>Button</source>
        <translation type="unfinished"></translation>
    </message>
</context>
</TS>
public static @NonNull String tr(@Nullable String source) {
    String scope = classToScope(QtJambi_LibraryUtilities.internal.callerClassProvider().get());
    return QCoreApplication.translate(scope, source);
}

Actually, the scope variable in Java code is "top.bilitianx.Window", not "Window".

Describe the solution you'd like

Specifically develop a program that does what lupdate.exe does, but for Java/Kotlin in particular.

Describe alternatives you've considered

As described above.

omix commented 9 months ago

Unfortunately, this issue is caused by lupdate, as it is not able to interpret Kotlin source code. Recreating lupdate for Kotlin outweights the capacities of this project. Feel free to request this feature from Qt.

Bili-TianX commented 9 months ago

Unfortunately, this issue is caused by lupdate, as it is not able to interpret Kotlin source code. Recreating lupdate for Kotlin outweights the capacities of this project. Feel free to request this feature from Qt.

I tried Java and it worked properly. Maybe I will correct the ts file manually for developing Kotlin project in the future. Thank you!