diff --git a/static/js/translations.js b/static/js/translations.js index 3ba54cb775..86d04909a2 100644 --- a/static/js/translations.js +++ b/static/js/translations.js @@ -39,6 +39,7 @@ i18next.use(XHR) detection: detectionOptions, cache: cacheOptions, fallbackLng: 'en', + returnEmptyString: false, // Empty string is not a valid translation. }, function () { var i; initialized = true; diff --git a/zerver/management/commands/compilemessages.py b/zerver/management/commands/compilemessages.py index cb2a17c433..008db51936 100644 --- a/zerver/management/commands/compilemessages.py +++ b/zerver/management/commands/compilemessages.py @@ -115,7 +115,7 @@ class Command(compilemessages.Command): with open(self.get_json_filename(locale_path, locale)) as reader: for key, value in ujson.load(reader).items(): total += 1 - if key == value: + if value == '': not_translated += 1 return (total - not_translated) * 100 // total diff --git a/zerver/management/commands/makemessages.py b/zerver/management/commands/makemessages.py index a5534a9fba..f89d812733 100644 --- a/zerver/management/commands/makemessages.py +++ b/zerver/management/commands/makemessages.py @@ -217,8 +217,8 @@ class Command(makemessages.Command): yield os.path.join(path, self.get_namespace()) - def get_new_strings(self, old_strings, translation_strings): - # type: (Mapping[str, str], List[str]) -> Dict[str, str] + def get_new_strings(self, old_strings, translation_strings, locale): + # type: (Mapping[str, str], List[str], str) -> Dict[str, str] """ Missing strings are removed, new strings are added and already translated strings are not touched. @@ -226,7 +226,11 @@ class Command(makemessages.Command): new_strings = {} # Dict[str, str] for k in translation_strings: k = k.replace('\\n', '\n') - new_strings[k] = old_strings.get(k, k) + if locale == 'en': + # For English language, translation is equal to the key. + new_strings[k] = old_strings.get(k, k) + else: + new_strings[k] = old_strings.get(k, "") plurals = {k: v for k, v in old_strings.items() if k.endswith('_plural')} for plural_key, value in plurals.items(): @@ -250,7 +254,8 @@ class Command(makemessages.Command): new_strings = { force_text(k): v for k, v in self.get_new_strings(old_strings, - translation_strings).items() + translation_strings, + locale).items() } with open(output_path, 'w') as writer: json.dump(new_strings, writer, indent=2, sort_keys=True)