i18n: Add new markup for lazy translation of giphy ratings.

Also, it adds phrases such as 'rated Y' to the ignored list.
Otherwise, the linter would require to write it as 'rated y'.
This commit is contained in:
Daniil Fadeev 2023-03-02 19:00:49 +04:00 committed by Tim Abbott
parent d335cb34af
commit d606f5ba42
3 changed files with 22 additions and 7 deletions

View File

@ -106,6 +106,12 @@ IGNORED_PHRASES = [
r"your-organization-url",
# Used in invite modal
r"or",
# Used in GIPHY integration setting. GIFs Rating.
r"rated Y",
r"rated G",
r"rated PG",
r"rated PG13",
r"rated R",
# Used in GIPHY popover.
r"GIFs",
r"GIPHY",

View File

@ -315,7 +315,7 @@ def fetch_initial_state_data(
state["server_avatar_changes_disabled"] = settings.AVATAR_CHANGES_DISABLED
state["server_name_changes_disabled"] = settings.NAME_CHANGES_DISABLED
state["server_web_public_streams_enabled"] = settings.WEB_PUBLIC_STREAMS_ENABLED
state["giphy_rating_options"] = realm.GIPHY_RATING_OPTIONS
state["giphy_rating_options"] = realm.get_giphy_rating_options()
state["server_emoji_data_url"] = emoji.data_url()

View File

@ -650,34 +650,43 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub
default=VIDEO_CHAT_PROVIDERS["jitsi_meet"]["id"]
)
# Please access this via get_giphy_rating_options.
GIPHY_RATING_OPTIONS = {
"disabled": {
"name": "GIPHY integration disabled",
"name": gettext_lazy("GIPHY integration disabled"),
"id": 0,
},
# Source: https://github.com/Giphy/giphy-js/blob/master/packages/fetch-api/README.md#shared-options
"y": {
"name": "Allow GIFs rated Y (Very young audience)",
"name": gettext_lazy("Allow GIFs rated Y (Very young audience)"),
"id": 1,
},
"g": {
"name": "Allow GIFs rated G (General audience)",
"name": gettext_lazy("Allow GIFs rated G (General audience)"),
"id": 2,
},
"pg": {
"name": "Allow GIFs rated PG (Parental guidance)",
"name": gettext_lazy("Allow GIFs rated PG (Parental guidance)"),
"id": 3,
},
"pg-13": {
"name": "Allow GIFs rated PG13 (Parental guidance - under 13)",
"name": gettext_lazy("Allow GIFs rated PG13 (Parental guidance - under 13)"),
"id": 4,
},
"r": {
"name": "Allow GIFs rated R (Restricted)",
"name": gettext_lazy("Allow GIFs rated R (Restricted)"),
"id": 5,
},
}
def get_giphy_rating_options(self) -> Dict[str, Dict[str, object]]:
"""Wrapper function for GIPHY_RATING_OPTIONS that ensures evaluation
of the lazily evaluated `name` field without modifying the original."""
return {
rating_type: {"name": str(rating["name"]), "id": rating["id"]}
for rating_type, rating in self.GIPHY_RATING_OPTIONS.items()
}
# maximum rating of the GIFs that will be retrieved from GIPHY
giphy_rating = models.PositiveSmallIntegerField(default=GIPHY_RATING_OPTIONS["g"]["id"])