From a55cb36d21eec227eeddd372b5b270d7d4542f32 Mon Sep 17 00:00:00 2001 From: Truong David Date: Thu, 4 Apr 2019 15:54:31 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=90(search)=20replace=20gettext=20by?= =?UTF-8?q?=20ugettext=5Flazy=20in=20the=20defaults=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some section titles on the search page are not translating properly with gettext. Using ugettext_lazy instead fixes the problem. --- src/richie/apps/search/defaults.py | 2 +- .../search/test_query_courses_edge_cases.py | 24 ++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/richie/apps/search/defaults.py b/src/richie/apps/search/defaults.py index 6279366ca4..53b8cc3207 100644 --- a/src/richie/apps/search/defaults.py +++ b/src/richie/apps/search/defaults.py @@ -3,7 +3,7 @@ """ from django.conf import settings from django.utils.functional import lazy -from django.utils.translation import gettext as _ +from django.utils.translation import ugettext_lazy as _ # The React i18n library only works with ISO15897 locales (e.g. fr_FR) # Django also supports ISO639-1 language codes without a region (e.g. fr) which is sufficient diff --git a/tests/apps/search/test_query_courses_edge_cases.py b/tests/apps/search/test_query_courses_edge_cases.py index 89cb88ca3d..927e75576b 100644 --- a/tests/apps/search/test_query_courses_edge_cases.py +++ b/tests/apps/search/test_query_courses_edge_cases.py @@ -1,7 +1,7 @@ """Tests for environment ElasticSearch support.""" -# pylint: disable=too-many-lines import json import random +from http.cookies import SimpleCookie from unittest import mock from django.conf import settings @@ -104,6 +104,28 @@ def prepare_index(self, courses): ) indices_client.refresh() + def test_query_courses_filter_box_titles_french(self, *_): + """ + Filter box titles should be in french when the language cookie is set. + """ + + self.prepare_index([]) + self.client.cookies = SimpleCookie({"django_language": "fr"}) + response = self.client.get(f"/api/v1.0/courses/") + self.assertEqual(response.status_code, 200) + content = json.loads(response.content) + self.assertEqual( + [v["human_name"] for v in content["filters"].values()], + [ + "Nouveaux cours", + "Disponibilité", + "Sujets", + "Niveaux", + "Établissements", + "Langues", + ], + ) + def test_query_courses_rare_facet_force(self, *_): """ A facet that is selected in the querystring should always be included in the result's