[retro-gtk] environment: Implement RETRO_ENVIRONMENT_GET_LANGUAGE



commit f827acced83bc0e28432918a541a3af22713074d
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Sat Apr 28 09:56:22 2018 +0200

    environment: Implement RETRO_ENVIRONMENT_GET_LANGUAGE

 retro-gtk/retro-environment.c | 70 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 69 insertions(+), 1 deletion(-)
---
diff --git a/retro-gtk/retro-environment.c b/retro-gtk/retro-environment.c
index 82a9d18..5b88788 100644
--- a/retro-gtk/retro-environment.c
+++ b/retro-gtk/retro-environment.c
@@ -7,6 +7,27 @@
 #include "retro-input-private.h"
 #include "retro-pixdata-private.h"
 
+enum RetroLanguage {
+  RETRO_LANGUAGE_ENGLISH = 0,
+  RETRO_LANGUAGE_JAPANESE,
+  RETRO_LANGUAGE_FRENCH,
+  RETRO_LANGUAGE_SPANISH,
+  RETRO_LANGUAGE_GERMAN,
+  RETRO_LANGUAGE_ITALIAN,
+  RETRO_LANGUAGE_DUTCH,
+  RETRO_LANGUAGE_PORTUGUESE_BRAZIL,
+  RETRO_LANGUAGE_PORTUGUESE_PORTUGAL,
+  RETRO_LANGUAGE_RUSSIAN,
+  RETRO_LANGUAGE_KOREAN,
+  RETRO_LANGUAGE_CHINESE_TRADITIONAL,
+  RETRO_LANGUAGE_CHINESE_SIMPLIFIED,
+  RETRO_LANGUAGE_ESPERANTO,
+  RETRO_LANGUAGE_POLISH,
+  RETRO_LANGUAGE_VIETNAMESE,
+  RETRO_LANGUAGE_ARABIC,
+  RETRO_LANGUAGE_DEFAULT = RETRO_LANGUAGE_ENGLISH,
+};
+
 enum RetroLogLevel {
   RETRO_LOG_LEVEL_DEBUG = 0,
   RETRO_LOG_LEVEL_INFO,
@@ -126,6 +147,51 @@ get_input_device_capabilities (RetroCore *self,
   return TRUE;
 }
 
+static gboolean
+get_language (RetroCore *self,
+              unsigned  *language)
+{
+  static const struct { const gchar *locale_prefix; enum RetroLanguage language; } values[] = {
+    { "ar_", RETRO_LANGUAGE_ARABIC },
+    { "de_", RETRO_LANGUAGE_GERMAN },
+    { "en_", RETRO_LANGUAGE_ENGLISH },
+    { "eo", RETRO_LANGUAGE_ESPERANTO },
+    { "es_", RETRO_LANGUAGE_SPANISH },
+    { "fr_", RETRO_LANGUAGE_FRENCH },
+    { "it_", RETRO_LANGUAGE_ITALIAN },
+    { "jp_", RETRO_LANGUAGE_JAPANESE },
+    { "ko_", RETRO_LANGUAGE_KOREAN },
+    { "nl_", RETRO_LANGUAGE_DUTCH },
+    { "pl_", RETRO_LANGUAGE_POLISH },
+    { "pt_BR", RETRO_LANGUAGE_PORTUGUESE_BRAZIL },
+    { "pt_PT", RETRO_LANGUAGE_PORTUGUESE_PORTUGAL },
+    { "ru_", RETRO_LANGUAGE_RUSSIAN },
+    { "vi_", RETRO_LANGUAGE_VIETNAMESE },
+    { "zh_CN", RETRO_LANGUAGE_CHINESE_SIMPLIFIED },
+    { "zh_HK", RETRO_LANGUAGE_CHINESE_TRADITIONAL },
+    { "zh_SG", RETRO_LANGUAGE_CHINESE_SIMPLIFIED },
+    { "zh_TW", RETRO_LANGUAGE_CHINESE_TRADITIONAL },
+    { NULL, RETRO_LANGUAGE_DEFAULT },
+  };
+
+  const gchar *locale = g_getenv ("LANG");
+  gsize i = 0;
+
+  if (locale == NULL) {
+    *language = RETRO_LANGUAGE_DEFAULT;
+
+    return TRUE;
+  }
+
+  while (values[i].locale_prefix != NULL &&
+         !g_str_has_prefix (locale, values[i].locale_prefix))
+    i++;
+
+  *language = values[i].language;
+
+  return TRUE;
+}
+
 static gboolean
 get_libretro_path (RetroCore    *self,
                    const gchar **libretro_directory)
@@ -329,6 +395,9 @@ environment_core_command (RetroCore *self,
   case RETRO_ENVIRONMENT_GET_INPUT_DEVICE_CAPABILITIES:
     return get_input_device_capabilities (self, (guint64 *) data);
 
+  case RETRO_ENVIRONMENT_GET_LANGUAGE:
+    return get_language (self, (unsigned *) data);
+
   case RETRO_ENVIRONMENT_GET_LIBRETRO_PATH:
     return get_libretro_path (self, (const gchar **) data);
 
@@ -387,7 +456,6 @@ environment_core_command (RetroCore *self,
     return shutdown (self);
 
   case RETRO_ENVIRONMENT_GET_CAMERA_INTERFACE:
-  case RETRO_ENVIRONMENT_GET_LANGUAGE:
   case RETRO_ENVIRONMENT_GET_LOCATION_INTERFACE:
   case RETRO_ENVIRONMENT_GET_PERF_INTERFACE:
   case RETRO_ENVIRONMENT_GET_SENSOR_INTERFACE:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]