From 584bec70c7c7dd8e052aa45dcac642773543cad6 Mon Sep 17 00:00:00 2001 From: "neiljp (Neil Pilgrim)" Date: Wed, 20 Mar 2019 17:07:37 +0000 Subject: [PATCH] i18n: Log error & return "Unknown" if invalid code in get_language_name. Previously this could return None. --- zerver/lib/i18n.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/zerver/lib/i18n.py b/zerver/lib/i18n.py index f51ac95c75..377b0150fc 100644 --- a/zerver/lib/i18n.py +++ b/zerver/lib/i18n.py @@ -7,10 +7,11 @@ from django.utils.translation import ugettext as _ from django.utils.lru_cache import lru_cache from itertools import zip_longest -from typing import Any, List, Dict, Optional +from typing import Any, List, Dict import os import ujson +import logging def with_language(string: str, language: str) -> str: """ @@ -67,11 +68,13 @@ def get_language_list_for_templates(default_language: str) -> List[Dict[str, Dic return formatted_list -def get_language_name(code: str) -> Optional[str]: +def get_language_name(code: str) -> str: for lang in get_language_list(): if code in (lang['code'], lang['locale']): return lang['name'] - return None + # Log problem, but still return a name + logging.error("Unknown language code '%s'" % (code,)) + return "Unknown" def get_available_language_codes() -> List[str]: language_list = get_language_list()