Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-91225

Webengine default locale not transferred to JS

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.15
    • 5.12
    • WebEngine
    • None
    • Linux/Other display system
    • I1c09798abdb523b80f0b7a3d69fa8d7a08c7c09a

    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

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            davidsz Szabolcs David
            andy99 A -
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes