Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qlocale_wasm.cpp
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:critical reason:data-parser
4
5#include "qlocale_p.h"
6
7#include <emscripten.h>
8
9QT_BEGIN_NAMESPACE
10
11#ifndef QT_NO_SYSTEMLOCALE
12
13namespace {
14
15QStringList navigatorLanguages()
16{
17 // Read navigator.languages using EM_ASM_PTR instead of emscripten::val. The
18 // latter does not support being used from static constructors (emscripten #23170)
19 char *joined = reinterpret_cast<char *>(EM_ASM_PTR({
20 return stringToNewUTF8(navigator.languages.join("\n"));
21 }));
22 const QStringList qtLanguages =
23 QString::fromUtf8(joined).split(u'\n', Qt::SkipEmptyParts);
24 free(joined);
25 return qtLanguages;
26}
27
28}
29
30QVariant QSystemLocale::query(QueryType query, QVariant &&in) const
31{
32 Q_UNUSED(in);
33
34 switch (query) {
35 case QSystemLocale::UILanguages:
36 return QVariant(navigatorLanguages());
37 default:
38 break;
39 }
40
41 return QVariant();
42}
43
44QLocale QSystemLocale::fallbackLocale() const
45{
46 const QStringList languages = navigatorLanguages();
47 if (languages.isEmpty())
48 return QLocale(u"en-US");
49 return QLocale(languages[0]);
50}
51
52#endif // QT_NO_SYSTEMLOCALE
53
54QT_END_NAMESPACE