summaryrefslogtreecommitdiff
path: root/core/os
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2021-09-16 09:27:56 +0200
committerRémi Verschelde <rverschelde@gmail.com>2021-09-16 09:34:58 +0200
commitdef99c7baf1880e3efc0b60b9eb035be8a7edb14 (patch)
tree2bb81dec2237e4559fbb3b63a8ff56fc8f7a09d0 /core/os
parent73ec378c6431fc2e86c1116505b61f5064d3cd4d (diff)
Implement `OS::get_locale_language()` helper method
This method extracts the 2 or 3-letter language code from `OS::get_locale()`, making it easier for users to identify the "main" language code for users that might have different OS locales due to different OS or region, but should be matched to the same translation (e.g. "generic" Spanish). Fixes #40703.
Diffstat (limited to 'core/os')
-rw-r--r--core/os/os.cpp6
-rw-r--r--core/os/os.h1
2 files changed, 7 insertions, 0 deletions
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;