aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sources/pyside6/PySide6/QtCore/typesystem_core_common.xml21
-rw-r--r--sources/pyside6/PySide6/glue/qtcore.cpp25
2 files changed, 45 insertions, 1 deletions
diff --git a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
index 4ecd1a48d..153de1bf2 100644
--- a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
+++ b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
@@ -1330,10 +1330,31 @@
<modify-function signature="toString(qulonglong)const" remove="all"/>
<modify-function signature="toString(ushort)const" remove="all"/>
<modify-function signature="toString(unsigned int)const" remove="all"/>
+ <modify-function signature="system()" remove="all"/>
<!--### -->
<extra-includes>
<include file-name="QDate" location="global"/>
</extra-includes>
+ <add-function signature="system()" return-type="QLocale" static="yes">
+ <inject-code class="target" position="beginning" file="../glue/qtcore.cpp"
+ snippet="qlocale_system"/>
+ <inject-documentation mode="append" format="target">
+ Returns a QLocale object initialized to the system locale.
+
+ The system locale may use system-specific sources for locale data, where available,
+ otherwise falling back on QLocale's built-in database entry for the language, script and
+ territory the system reports.
+
+ For example, on Windows, this locale will use the decimal/grouping characters and
+ date/time formats specified in the system configuration panel.
+
+ .. note:: Qt for Python on macOS will not reflect the user's region and language
+ preferences though QLocale::system(), but will instead reflect the environment
+ variables POSIX uses to specify locale, similar to Python's locale module.
+
+ See also c().
+ </inject-documentation>
+ </add-function>
<modify-function signature="toTime(QString,QLocale::FormatType)const">
<modify-argument index="2">
<rename to="format"/>
diff --git a/sources/pyside6/PySide6/glue/qtcore.cpp b/sources/pyside6/PySide6/glue/qtcore.cpp
index a706042b4..80aaca96a 100644
--- a/sources/pyside6/PySide6/glue/qtcore.cpp
+++ b/sources/pyside6/PySide6/glue/qtcore.cpp
@@ -1848,4 +1848,27 @@ auto callback = [callable]() -> void
Py_INCREF(callable);
%RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(callback);
%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0);
-// @snipped qrunnable_create
+// @snippet qrunnable_create
+
+// @snippet qlocale_system
+// For darwin systems, QLocale::system() involves looking at the Info.plist of the application
+// bundle to detect the system localization. In the case of Qt for Python, the application bundle
+// is the used Python framework. To enable retreival of localized string, the property list key
+// CFBunldeAllowMixedLocalizations should be set to True inside the Info.plist file. Otherwise,
+// CFBundleDevelopmentRegion will be used to find the language preference of the user, which in the
+// case of Python is always english.
+// This is a hack until CFBunldeAllowMixedLocalizations will be set in the Python framework
+// installation in darwin systems.
+// Upstream issue in CPython: https://github.com/python/cpython/issues/108269
+#ifdef Q_OS_DARWIN
+ Shiboken::AutoDecRef locale(PyImport_ImportModule("locale"));
+ Shiboken::AutoDecRef getLocale(PyObject_GetAttrString(locale, "getlocale"));
+ Shiboken::AutoDecRef systemLocale(PyObject_CallObject(getLocale, nullptr));
+ Shiboken::AutoDecRef localeCode(PyUnicode_AsUTF8String(PyTuple_GetItem(systemLocale, 0)));
+ QString localeCodeStr = PySide::pyStringToQString(localeCode);
+ %RETURN_TYPE %0 = QLocale(localeCodeStr);
+#else
+ %RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME();
+#endif
+%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0);
+// @snippet qlocale_system