#include "third_party/blink/renderer/platform/text/platform_locale.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/blink/renderer/platform/wtf/thread_specific.h"
+#if BUILDFLAG(IS_TIZEN)
+#include <vconf/vconf.h>
+#include "base/trace_event/trace_event.h"
+#endif
namespace blink {
String copied_code = language_code;
// Platform::defaultLocale() might provide a language code with '_'.
copied_code.Replace('_', '-');
+#if BUILDFLAG(IS_TIZEN)
+ size_t dot_position = copied_code.find('.');
+ if (dot_position > 0)
+ copied_code.Truncate(dot_position);
+#endif
return copied_code;
}
+#if BUILDFLAG(IS_TIZEN)
+static bool language_changed_ = false;
+static bool language_changed_callback_registered_ = false;
+static void PlatformLanguageChanged(keynode_t*, void* data) {
+ language_changed_ = true;
+}
+#endif
+
// Main thread static AtomicString. This can be safely shared across threads.
const AtomicString* g_platform_language = nullptr;
DCHECK(g_platform_language->Impl()->IsStatic())
<< "global language string is used from multiple threads, and must be "
"static";
+#if BUILDFLAG(IS_TIZEN)
+ DEFINE_STATIC_LOCAL(AtomicString, g_vconf_language, ());
+ if (language_changed_) {
+ // Update the platform language from vconf
+ char* lang = vconf_get_str(VCONFKEY_LANGSET);
+ if (lang) {
+ g_vconf_language = AtomicString(CanonicalizeLanguageIdentifier(lang));
+ TTRACE_WEB("PlatformLanguage, get vconf language: %s",
+ g_vconf_language.GetString().Utf8().c_str());
+ free(lang);
+ }
+ language_changed_ = false;
+ }
+
+ if (!g_vconf_language.empty())
+ return g_vconf_language;
+#endif
return *g_platform_language;
}
} // namespace
+#if BUILDFLAG(IS_TIZEN)
+void StopListeningLanguageChange() {
+ if (language_changed_callback_registered_)
+ vconf_ignore_key_changed(VCONFKEY_LANGSET, PlatformLanguageChanged);
+
+ language_changed_callback_registered_ = false;
+}
+#endif
+
void InitializePlatformLanguage() {
DCHECK(IsMainThread());
+#if BUILDFLAG(IS_TIZEN)
+ if (!language_changed_callback_registered_) {
+ // Register a callback to handle the platform language change
+ vconf_notify_key_changed(VCONFKEY_LANGSET, PlatformLanguageChanged,
+ nullptr);
+ language_changed_callback_registered_ = true;
+ language_changed_ = true;
+ }
+#endif
DEFINE_STATIC_LOCAL(
// We add the platform language as a static string for two reasons:
// 1. it can be shared across threads.