Details
Description
Hello everyone!
Javascript locale API is not respecting used locale.
// main.cpp int main(int argc, char **argv) { qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard")); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); QGuiApplication app(argc, argv); int num = 1234567890; QLocale::setDefault(QLocale("de_CH")); qDebug() << "locale:" << QLocale().name() << " num:" << QLocale().toString(num); QtWebEngine::initialize(); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("./main.qml"))); QQuickWindow *window = qobject_cast<QQuickWindow*>(engine.rootObjects().first()); window->show(); return app.exec(); } // main.qml Text { property var num: 1234567890 anchors.centerIn: parent Component.onCompleted: { console.log("num2: " + num.toLocaleString(Qt.locale())) } } WebEngineView { anchors.fill: parent profile: profile url: "file:///home/andy/DEV/native/projects/QT/egl/html/index.html" } WebEngineProfile { id: profile httpAcceptLanguage: "de-CH" }
application output: locale: "de_CH" num: "1'234'567'890" qml: num2: 1'234'567'890.00
Both of the application's output are correct, which is fine.
index.html <script type="text/javascript"> function GetCurrentLocale() { console.log("locale: " + navigator.language || navigator.userLanguage); var number = 1234567890; console.log("number.toLocaleString()); } </script>
The "navigator.language || navigator.userLanguage" will return value from "httpAcceptLanguage", which is "de-CH". If it's not set, value is "de".
But the number is still formatted as "DE" "1.234.567.890" and not "-CH". So looks like, that javascript is not respecting set locale.
Regards,
Andy