libmalcontent-ui: Update content rating formatting code

This incorporates commit 7d00c4d84b2a47dd815dc88da1a82dc54800d4b6 from
gnome-software, which allows the ESRB strings to be localised.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
Philip Withnall 2020-05-21 12:30:05 +01:00
parent 77b8704cb4
commit 396dd3c039
3 changed files with 89 additions and 74 deletions

View File

@ -373,171 +373,183 @@ gs_content_rating_key_value_to_str (const gchar *id, MctAppFilterOarsValue value
}
/* data obtained from https://en.wikipedia.org/wiki/Video_game_rating_system */
const gchar *
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 */
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;
}

View File

@ -47,7 +47,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,

View File

@ -374,7 +374,7 @@ static void
update_oars_level (MctUserControls *self)
{
GsContentRatingSystem rating_system;
const gchar *rating_age_category;
g_autofree gchar *rating_age_category = NULL;
guint maximum_age;
gsize i;
gboolean all_categories_unset;
@ -407,7 +407,10 @@ update_oars_level (MctUserControls *self)
/* Unrestricted? */
if (rating_age_category == NULL || all_categories_unset)
rating_age_category = _("All Ages");
{
g_clear_pointer (&rating_age_category, g_free);
rating_age_category = g_strdup (_("All Ages"));
}
gtk_label_set_label (self->oars_button_label, rating_age_category);
}