[gnome-software] Fixes #678. Wrong rating systems selected based in language instead of territory
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Fixes #678. Wrong rating systems selected based in language instead of territory
- Date: Thu, 13 Jun 2019 09:59:16 +0000 (UTC)
commit ed981f1d26f9a2c086eeccdee2909959de64f908
Author: Jordi Mas <jmas softcatala org>
Date: Thu Jun 13 09:59:04 2019 +0000
Fixes #678. Wrong rating systems selected based in language instead of territory
src/gs-content-rating.c | 142 +++++++++++++++++++++++-------------------------
src/gs-self-test.c | 33 ++++++-----
2 files changed, 84 insertions(+), 91 deletions(-)
---
diff --git a/src/gs-content-rating.c b/src/gs-content-rating.c
index 9ce57dab..b27a2337 100644
--- a/src/gs-content-rating.c
+++ b/src/gs-content-rating.c
@@ -619,125 +619,119 @@ GsContentRatingSystem
gs_utils_content_rating_system_from_locale (const gchar *locale)
{
g_autofree gchar *locale_copy = g_strdup (locale);
- const gchar *language, *territory;
+ const gchar *territory;
/* Default to IARC for locales which can’t be parsed. */
- if (!parse_locale (locale_copy, &language, &territory, NULL, NULL))
+ if (!parse_locale (locale_copy, NULL, &territory, NULL, NULL))
return GS_CONTENT_RATING_SYSTEM_IARC;
/* Argentina */
- if (g_strcmp0 (language, "ar") == 0)
+ if (g_strcmp0 (territory, "AR") == 0)
return GS_CONTENT_RATING_SYSTEM_INCAA;
/* Australia */
- if (g_strcmp0 (language, "au") == 0)
+ if (g_strcmp0 (territory, "AU") == 0)
return GS_CONTENT_RATING_SYSTEM_ACB;
/* Brazil */
- if (g_strcmp0 (language, "pt") == 0 &&
- g_strcmp0 (territory, "BR") == 0)
+ if (g_strcmp0 (territory, "BR") == 0)
return GS_CONTENT_RATING_SYSTEM_DJCTQ;
/* Taiwan */
- if (g_strcmp0 (language, "zh") == 0 &&
- g_strcmp0 (territory, "TW") == 0)
+ if (g_strcmp0 (territory, "TW") == 0)
return GS_CONTENT_RATING_SYSTEM_GSRR;
/* Europe (but not Finland or Germany), India, Israel,
* Pakistan, Quebec, South Africa */
- if ((g_strcmp0 (language, "en") == 0 &&
- g_strcmp0 (territory, "GB") == 0) ||
- g_strcmp0 (language, "gb") == 0 ||
- g_strcmp0 (language, "al") == 0 ||
- g_strcmp0 (language, "ad") == 0 ||
- g_strcmp0 (language, "am") == 0 ||
- g_strcmp0 (language, "at") == 0 ||
- g_strcmp0 (language, "az") == 0 ||
- g_strcmp0 (language, "by") == 0 ||
- g_strcmp0 (language, "be") == 0 ||
- g_strcmp0 (language, "ba") == 0 ||
- g_strcmp0 (language, "bg") == 0 ||
- g_strcmp0 (language, "hr") == 0 ||
- g_strcmp0 (language, "cy") == 0 ||
- g_strcmp0 (language, "cz") == 0 ||
- g_strcmp0 (language, "dk") == 0 ||
- g_strcmp0 (language, "ee") == 0 ||
- g_strcmp0 (language, "fr") == 0 ||
- g_strcmp0 (language, "ge") == 0 ||
- g_strcmp0 (language, "gr") == 0 ||
- g_strcmp0 (language, "hu") == 0 ||
- g_strcmp0 (language, "is") == 0 ||
- g_strcmp0 (language, "it") == 0 ||
- g_strcmp0 (language, "kz") == 0 ||
- g_strcmp0 (language, "xk") == 0 ||
- g_strcmp0 (language, "lv") == 0 ||
- g_strcmp0 (language, "fl") == 0 ||
- g_strcmp0 (language, "lu") == 0 ||
- g_strcmp0 (language, "lt") == 0 ||
- g_strcmp0 (language, "mk") == 0 ||
- g_strcmp0 (language, "mt") == 0 ||
- g_strcmp0 (language, "md") == 0 ||
- g_strcmp0 (language, "mc") == 0 ||
- g_strcmp0 (language, "me") == 0 ||
- g_strcmp0 (language, "nl") == 0 ||
- g_strcmp0 (language, "no") == 0 ||
- g_strcmp0 (language, "pl") == 0 ||
- g_strcmp0 (language, "pt") == 0 ||
- g_strcmp0 (language, "ro") == 0 ||
- g_strcmp0 (language, "sm") == 0 ||
- g_strcmp0 (language, "rs") == 0 ||
- g_strcmp0 (language, "sk") == 0 ||
- g_strcmp0 (language, "si") == 0 ||
- g_strcmp0 (language, "es") == 0 ||
- g_strcmp0 (language, "se") == 0 ||
- g_strcmp0 (language, "ch") == 0 ||
- g_strcmp0 (language, "tr") == 0 ||
- g_strcmp0 (language, "ua") == 0 ||
- g_strcmp0 (language, "va") == 0 ||
- g_strcmp0 (language, "in") == 0 ||
- g_strcmp0 (language, "il") == 0 ||
- g_strcmp0 (language, "pk") == 0 ||
- g_strcmp0 (language, "za") == 0)
+ if ((g_strcmp0 (territory, "GB") == 0) ||
+ g_strcmp0 (territory, "AL") == 0 ||
+ g_strcmp0 (territory, "AD") == 0 ||
+ g_strcmp0 (territory, "AM") == 0 ||
+ g_strcmp0 (territory, "AT") == 0 ||
+ g_strcmp0 (territory, "AZ") == 0 ||
+ g_strcmp0 (territory, "BY") == 0 ||
+ g_strcmp0 (territory, "BE") == 0 ||
+ g_strcmp0 (territory, "BA") == 0 ||
+ g_strcmp0 (territory, "BG") == 0 ||
+ g_strcmp0 (territory, "HR") == 0 ||
+ g_strcmp0 (territory, "CY") == 0 ||
+ g_strcmp0 (territory, "CZ") == 0 ||
+ g_strcmp0 (territory, "DK") == 0 ||
+ g_strcmp0 (territory, "EE") == 0 ||
+ g_strcmp0 (territory, "FR") == 0 ||
+ g_strcmp0 (territory, "GE") == 0 ||
+ g_strcmp0 (territory, "GR") == 0 ||
+ g_strcmp0 (territory, "HU") == 0 ||
+ g_strcmp0 (territory, "IS") == 0 ||
+ g_strcmp0 (territory, "IT") == 0 ||
+ g_strcmp0 (territory, "LZ") == 0 ||
+ g_strcmp0 (territory, "XK") == 0 ||
+ g_strcmp0 (territory, "LV") == 0 ||
+ g_strcmp0 (territory, "FL") == 0 ||
+ g_strcmp0 (territory, "LU") == 0 ||
+ g_strcmp0 (territory, "LT") == 0 ||
+ g_strcmp0 (territory, "MK") == 0 ||
+ g_strcmp0 (territory, "MT") == 0 ||
+ g_strcmp0 (territory, "MD") == 0 ||
+ g_strcmp0 (territory, "MC") == 0 ||
+ g_strcmp0 (territory, "ME") == 0 ||
+ g_strcmp0 (territory, "NL") == 0 ||
+ g_strcmp0 (territory, "NO") == 0 ||
+ g_strcmp0 (territory, "PL") == 0 ||
+ g_strcmp0 (territory, "PT") == 0 ||
+ g_strcmp0 (territory, "RO") == 0 ||
+ g_strcmp0 (territory, "SM") == 0 ||
+ g_strcmp0 (territory, "RS") == 0 ||
+ g_strcmp0 (territory, "SK") == 0 ||
+ g_strcmp0 (territory, "SI") == 0 ||
+ g_strcmp0 (territory, "ES") == 0 ||
+ g_strcmp0 (territory, "SE") == 0 ||
+ g_strcmp0 (territory, "CH") == 0 ||
+ g_strcmp0 (territory, "TR") == 0 ||
+ g_strcmp0 (territory, "UA") == 0 ||
+ g_strcmp0 (territory, "VA") == 0 ||
+ g_strcmp0 (territory, "IN") == 0 ||
+ g_strcmp0 (territory, "IL") == 0 ||
+ g_strcmp0 (territory, "PK") == 0 ||
+ g_strcmp0 (territory, "ZA") == 0)
return GS_CONTENT_RATING_SYSTEM_PEGI;
/* Finland */
- if (g_strcmp0 (language, "fi") == 0)
+ if (g_strcmp0 (territory, "FI") == 0)
return GS_CONTENT_RATING_SYSTEM_KAVI;
/* Germany */
- if (g_strcmp0 (language, "de") == 0)
+ if (g_strcmp0 (territory, "DE") == 0)
return GS_CONTENT_RATING_SYSTEM_USK;
/* Iran */
- if (g_strcmp0 (language, "ir") == 0)
+ if (g_strcmp0 (territory, "IR") == 0)
return GS_CONTENT_RATING_SYSTEM_ESRA;
/* Japan */
- if (g_strcmp0 (language, "jp") == 0)
+ if (g_strcmp0 (territory, "JP") == 0)
return GS_CONTENT_RATING_SYSTEM_CERO;
/* New Zealand */
- if (g_strcmp0 (language, "nz") == 0)
+ if (g_strcmp0 (territory, "NZ") == 0)
return GS_CONTENT_RATING_SYSTEM_OFLCNZ;
/* Russia: Content rating law */
- if (g_strcmp0 (language, "ru") == 0)
+ if (g_strcmp0 (territory, "RU") == 0)
return GS_CONTENT_RATING_SYSTEM_RUSSIA;
/* Singapore */
- if (g_strcmp0 (language, "sg") == 0)
+ if (g_strcmp0 (territory, "SQ") == 0)
return GS_CONTENT_RATING_SYSTEM_MDA;
/* South Korea */
- if (g_strcmp0 (language, "kr") == 0)
+ if (g_strcmp0 (territory, "KR") == 0)
return GS_CONTENT_RATING_SYSTEM_GRAC;
/* USA, Canada, Mexico */
- if ((g_strcmp0 (language, "en") == 0 &&
- g_strcmp0 (territory, "US") == 0) ||
- g_strcmp0 (language, "us") == 0 ||
- g_strcmp0 (language, "ca") == 0 ||
- g_strcmp0 (language, "mx") == 0)
+ if ((g_strcmp0 (territory, "US") == 0) ||
+ g_strcmp0 (territory, "CA") == 0 ||
+ g_strcmp0 (territory, "MX") == 0)
return GS_CONTENT_RATING_SYSTEM_ESRB;
/* everything else is IARC */
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index 0e38e49d..be6408df 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -52,27 +52,27 @@ gs_content_rating_from_locale (void)
GsContentRatingSystem expected_system;
} vectors[] = {
/* Simple tests to get coverage of each rating system: */
- { "ar", GS_CONTENT_RATING_SYSTEM_INCAA },
- { "au", GS_CONTENT_RATING_SYSTEM_ACB },
+ { "es_AR", GS_CONTENT_RATING_SYSTEM_INCAA },
+ { "en_AU", GS_CONTENT_RATING_SYSTEM_ACB },
{ "pt_BR", GS_CONTENT_RATING_SYSTEM_DJCTQ },
{ "zh_TW", GS_CONTENT_RATING_SYSTEM_GSRR },
{ "en_GB", GS_CONTENT_RATING_SYSTEM_PEGI },
- { "am", GS_CONTENT_RATING_SYSTEM_PEGI },
- { "bg", GS_CONTENT_RATING_SYSTEM_PEGI },
- { "fi", GS_CONTENT_RATING_SYSTEM_KAVI },
- { "de", GS_CONTENT_RATING_SYSTEM_USK },
- { "ir", GS_CONTENT_RATING_SYSTEM_ESRA },
- { "jp", GS_CONTENT_RATING_SYSTEM_CERO },
- { "nz", GS_CONTENT_RATING_SYSTEM_OFLCNZ },
- { "ru", GS_CONTENT_RATING_SYSTEM_RUSSIA },
- { "sg", GS_CONTENT_RATING_SYSTEM_MDA },
- { "kr", GS_CONTENT_RATING_SYSTEM_GRAC },
+ { "hy_AM", GS_CONTENT_RATING_SYSTEM_PEGI },
+ { "bg_BG", GS_CONTENT_RATING_SYSTEM_PEGI },
+ { "fi_FI", GS_CONTENT_RATING_SYSTEM_KAVI },
+ { "de_DE", GS_CONTENT_RATING_SYSTEM_USK },
+ { "az_IR", GS_CONTENT_RATING_SYSTEM_ESRA },
+ { "jp_JP", GS_CONTENT_RATING_SYSTEM_CERO },
+ { "en_NZ", GS_CONTENT_RATING_SYSTEM_OFLCNZ },
+ { "ru_RU", GS_CONTENT_RATING_SYSTEM_RUSSIA },
+ { "en_SQ", GS_CONTENT_RATING_SYSTEM_MDA },
+ { "ko_KR", GS_CONTENT_RATING_SYSTEM_GRAC },
{ "en_US", GS_CONTENT_RATING_SYSTEM_ESRB },
- { "us", GS_CONTENT_RATING_SYSTEM_ESRB },
- { "ca", GS_CONTENT_RATING_SYSTEM_ESRB },
- { "mx", GS_CONTENT_RATING_SYSTEM_ESRB },
+ { "en_US", GS_CONTENT_RATING_SYSTEM_ESRB },
+ { "en_CA", GS_CONTENT_RATING_SYSTEM_ESRB },
+ { "es_MX", GS_CONTENT_RATING_SYSTEM_ESRB },
/* Fallback (arbitrarily chosen Venezuela since it seems to use IARC): */
- { "ve", GS_CONTENT_RATING_SYSTEM_IARC },
+ { "es_VE", GS_CONTENT_RATING_SYSTEM_IARC },
/* Locale with a codeset: */
{ "nl_NL.iso88591", GS_CONTENT_RATING_SYSTEM_PEGI },
/* Locale with a codeset and modifier: */
@@ -87,7 +87,6 @@ gs_content_rating_from_locale (void)
for (gsize i = 0; i < G_N_ELEMENTS (vectors); i++) {
g_test_message ("Test %" G_GSIZE_FORMAT ": %s", i, vectors[i].locale);
-
g_assert_cmpint (gs_utils_content_rating_system_from_locale (vectors[i].locale), ==,
vectors[i].expected_system);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]