summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/core_bind.cpp5
-rw-r--r--core/core_bind.h1
-rw-r--r--core/os/os.cpp6
-rw-r--r--core/os/os.h1
4 files changed, 13 insertions, 0 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index 58aecf39aa..e029b85450 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -286,6 +286,10 @@ String OS::get_locale() const {
return ::OS::get_singleton()->get_locale();
}
+String OS::get_locale_language() const {
+ return ::OS::get_singleton()->get_locale_language();
+}
+
String OS::get_model_name() const {
return ::OS::get_singleton()->get_model_name();
}
@@ -547,6 +551,7 @@ void OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("delay_usec", "usec"), &OS::delay_usec);
ClassDB::bind_method(D_METHOD("delay_msec", "msec"), &OS::delay_msec);
ClassDB::bind_method(D_METHOD("get_locale"), &OS::get_locale);
+ ClassDB::bind_method(D_METHOD("get_locale_language"), &OS::get_locale_language);
ClassDB::bind_method(D_METHOD("get_model_name"), &OS::get_model_name);
ClassDB::bind_method(D_METHOD("is_userfs_persistent"), &OS::is_userfs_persistent);
diff --git a/core/core_bind.h b/core/core_bind.h
index 8e95629695..a5d5a7c8ce 100644
--- a/core/core_bind.h
+++ b/core/core_bind.h
@@ -178,6 +178,7 @@ public:
Vector<String> get_cmdline_args();
String get_locale() const;
+ String get_locale_language() const;
String get_model_name() const;
diff --git a/core/os/os.cpp b/core/os/os.cpp
index dc3fe29dca..7505f3ff34 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -231,6 +231,12 @@ String OS::get_locale() const {
return "en";
}
+// Non-virtual helper to extract the 2 or 3-letter language code from
+// `get_locale()` in a way that's consistent for all platforms.
+String OS::get_locale_language() const {
+ return get_locale().left(3).replace("_", "");
+}
+
// Helper function to ensure that a dir name/path will be valid on the OS
String OS::get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separator) const {
Vector<String> invalid_chars = String(": * ? \" < > |").split(" ");
diff --git a/core/os/os.h b/core/os/os.h
index f585483300..c027428477 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -243,6 +243,7 @@ public:
RenderThreadMode get_render_thread_mode() const { return _render_thread_mode; }
virtual String get_locale() const;
+ String get_locale_language() const;
String get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separator = false) const;
virtual String get_godot_dir_name() const;