[gnome-software/localize-strings] Allow to localize ESRB content rating strings



commit ee7c59345d1b77f75943a3bc33d5350d17c2aeb9
Author: Jordi Mas <jmas softcatala org>
Date:   Sat May 25 21:41:51 2019 +0200

    Allow to localize ESRB content rating strings

 src/gs-content-rating.c | 155 ++++++++++++++++++++++++++----------------------
 src/gs-content-rating.h |   2 +-
 src/gs-details-page.c   |   2 +-
 3 files changed, 85 insertions(+), 74 deletions(-)
---
diff --git a/src/gs-content-rating.c b/src/gs-content-rating.c
index d4118d00..9ce57dab 100644
--- a/src/gs-content-rating.c
+++ b/src/gs-content-rating.c
@@ -8,8 +8,8 @@
 #include "config.h"
 
 #include <glib/gi18n.h>
+#include <glib/gprintf.h>
 #include <string.h>
-
 #include "gs-content-rating.h"
 
 const gchar *
@@ -358,172 +358,183 @@ gs_content_rating_key_value_to_str (const gchar *id, AsContentRatingValue value)
        return NULL;
 }
 
+static char *
+get_esrb_string (gchar *source, gchar *translate)
+{
+       if (g_strcmp0 (source, translate) == 0)
+               return g_strdup (source);
+       /* TRANSLATORS: This is the formatting of English and localized name
+          of the rating e.g. "Adults Only (solo adultos)" */
+       return g_strdup_printf (_("%s (%s)"), source, translate);
+}
+
 /* data obtained from https://en.wikipedia.org/wiki/Video_game_rating_system */
-const gchar *
+gchar *
 gs_utils_content_rating_age_to_str (GsContentRatingSystem system, guint age)
 {
        if (system == GS_CONTENT_RATING_SYSTEM_INCAA) {
                if (age >= 18)
-                       return "+18";
+                       return g_strdup ("+18");
                if (age >= 13)
-                       return "+13";
-               return "ATP";
+                       return g_strdup ("+13");
+               return g_strdup ("ATP");
        }
        if (system == GS_CONTENT_RATING_SYSTEM_ACB) {
                if (age >= 18)
-                       return "R18+";
+                       return g_strdup ("R18+");
                if (age >= 15)
-                       return "MA15+";
-               return "PG";
+                       return g_strdup ("MA15+");
+               return g_strdup ("PG");
        }
        if (system == GS_CONTENT_RATING_SYSTEM_DJCTQ) {
                if (age >= 18)
-                       return "18";
+                       return g_strdup ("18");
                if (age >= 16)
-                       return "16";
+                       return g_strdup ("16");
                if (age >= 14)
-                       return "14";
+                       return g_strdup ("14");
                if (age >= 12)
-                       return "12";
+                       return g_strdup ("12");
                if (age >= 10)
-                       return "10";
-               return "L";
+                       return g_strdup ("10");
+               return g_strdup ("L");
        }
        if (system == GS_CONTENT_RATING_SYSTEM_GSRR) {
                if (age >= 18)
-                       return "限制";
+                       return g_strdup ("限制");
                if (age >= 15)
-                       return "輔15";
+                       return g_strdup ("輔15");
                if (age >= 12)
-                       return "輔12";
+                       return g_strdup ("輔12");
                if (age >= 6)
-                       return "保護";
-               return "普通";
+                       return g_strdup ("保護");
+               return g_strdup ("普通");
        }
        if (system == GS_CONTENT_RATING_SYSTEM_PEGI) {
                if (age >= 18)
-                       return "18";
+                       return g_strdup ("18");
                if (age >= 16)
-                       return "16";
+                       return g_strdup ("16");
                if (age >= 12)
-                       return "12";
+                       return g_strdup ("12");
                if (age >= 7)
-                       return "7";
+                       return g_strdup ("7");
                if (age >= 3)
-                       return "3";
+                       return g_strdup ("3");
                return NULL;
        }
        if (system == GS_CONTENT_RATING_SYSTEM_KAVI) {
                if (age >= 18)
-                       return "18+";
+                       return g_strdup ("18+");
                if (age >= 16)
-                       return "16+";
+                       return g_strdup ("16+");
                if (age >= 12)
-                       return "12+";
+                       return g_strdup ("12+");
                if (age >= 7)
-                       return "7+";
+                       return g_strdup ("7+");
                if (age >= 3)
-                       return "3+";
+                       return g_strdup ("3+");
                return NULL;
        }
        if (system == GS_CONTENT_RATING_SYSTEM_USK) {
                if (age >= 18)
-                       return "18";
+                       return g_strdup ("18");
                if (age >= 16)
-                       return "16";
+                       return g_strdup ("16");
                if (age >= 12)
-                       return "12";
+                       return g_strdup ("12");
                if (age >= 6)
-                       return "6";
-               return "0";
+                       return g_strdup ("6");
+               return g_strdup ("0");
        }
        /* Reference: http://www.esra.org.ir/ */
        if (system == GS_CONTENT_RATING_SYSTEM_ESRA) {
                if (age >= 18)
-                       return "+18";
+                       return g_strdup ("+18");
                if (age >= 15)
-                       return "+15";
+                       return g_strdup ("+15");
                if (age >= 12)
-                       return "+12";
+                       return g_strdup ("+12");
                if (age >= 7)
-                       return "+7";
+                       return g_strdup ("+7");
                if (age >= 3)
-                       return "+3";
+                       return g_strdup ("+3");
                return NULL;
        }
        if (system == GS_CONTENT_RATING_SYSTEM_CERO) {
                if (age >= 18)
-                       return "Z";
+                       return g_strdup ("Z");
                if (age >= 17)
-                       return "D";
+                       return g_strdup ("D");
                if (age >= 15)
-                       return "C";
+                       return g_strdup ("C");
                if (age >= 12)
-                       return "B";
-               return "A";
+                       return g_strdup ("B");
+               return g_strdup ("A");
        }
        if (system == GS_CONTENT_RATING_SYSTEM_OFLCNZ) {
                if (age >= 18)
-                       return "R18";
+                       return g_strdup ("R18");
                if (age >= 16)
-                       return "R16";
+                       return g_strdup ("R16");
                if (age >= 15)
-                       return "R15";
+                       return g_strdup ("R15");
                if (age >= 13)
-                       return "R13";
-               return "G";
+                       return g_strdup ("R13");
+               return g_strdup ("G");
        }
        if (system == GS_CONTENT_RATING_SYSTEM_RUSSIA) {
                if (age >= 18)
-                       return "18+";
+                       return g_strdup ("18+");
                if (age >= 16)
-                       return "16+";
+                       return g_strdup ("16+");
                if (age >= 12)
-                       return "12+";
+                       return g_strdup ("12+");
                if (age >= 6)
-                       return "6+";
-               return "0+";
+                       return g_strdup ("6+");
+               return g_strdup ("0+");
        }
        if (system == GS_CONTENT_RATING_SYSTEM_MDA) {
                if (age >= 18)
-                       return "M18";
+                       return g_strdup ("M18");
                if (age >= 16)
-                       return "ADV";
-               return "General";
+                       return g_strdup ("ADV");
+               return get_esrb_string ("General", _("General"));
        }
        if (system == GS_CONTENT_RATING_SYSTEM_GRAC) {
                if (age >= 18)
-                       return "18";
+                       return g_strdup ("18");
                if (age >= 15)
-                       return "15";
+                       return g_strdup ("15");
                if (age >= 12)
-                       return "12";
-               return "ALL";
+                       return g_strdup ("12");
+               return get_esrb_string ("ALL", _("ALL"));
        }
        if (system == GS_CONTENT_RATING_SYSTEM_ESRB) {
                if (age >= 18)
-                       return "Adults Only";
+                       return get_esrb_string ("Adults Only", _("Adults Only"));
                if (age >= 17)
-                       return "Mature";
+                       return get_esrb_string ("Mature", _("Mature"));
                if (age >= 13)
-                       return "Teen";
+                       return get_esrb_string ("Teen", _("Teen"));
                if (age >= 10)
-                       return "Everyone 10+";
+                       return get_esrb_string ("Everyone 10+", _("Everyone 10+"));
                if (age >= 6)
-                       return "Everyone";
-               return "Early Childhood";
+                       return get_esrb_string ("Everyone", _("Everyone"));
+
+               return get_esrb_string ("Early Childhood", _("Early Childhood"));
        }
        /* IARC = everything else */
        if (age >= 18)
-               return "18+";
+               return g_strdup ("18+");
        if (age >= 16)
-               return "16+";
+               return g_strdup ("16+");
        if (age >= 12)
-               return "12+";
+               return g_strdup ("12+");
        if (age >= 7)
-               return "7+";
+               return g_strdup ("7+");
        if (age >= 3)
-               return "3+";
+               return g_strdup ("3+");
        return NULL;
 }
 
diff --git a/src/gs-content-rating.h b/src/gs-content-rating.h
index 1e539999..a69873f4 100644
--- a/src/gs-content-rating.h
+++ b/src/gs-content-rating.h
@@ -33,7 +33,7 @@ typedef enum {
        GS_CONTENT_RATING_SYSTEM_LAST
 } GsContentRatingSystem;
 
-const gchar *gs_utils_content_rating_age_to_str (GsContentRatingSystem system,
+gchar *gs_utils_content_rating_age_to_str (GsContentRatingSystem system,
                                                 guint age);
 GsContentRatingSystem gs_utils_content_rating_system_from_locale (const gchar *locale);
 const gchar *gs_content_rating_key_value_to_str (const gchar *id,
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index 2e31b0aa..87f00f12 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -1689,7 +1689,7 @@ gs_details_page_refresh_content_rating (GsDetailsPage *self)
        AsContentRating *content_rating;
        GsContentRatingSystem system;
        guint age = 0;
-       const gchar *display = NULL;
+       g_autofree gchar *display = NULL;
        const gchar *locale;
 
        /* get the content rating system from the locale */


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