From 76f4b0c0f376939dc2e613945842c47fca5bad2d Mon Sep 17 00:00:00 2001 From: Piotr Kawula Date: Thu, 7 Mar 2024 09:36:41 +0100 Subject: [PATCH] Fixed #35278 -- Fixed returning possibly undefined from and functions. --- django/views/templates/i18n_catalog.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/django/views/templates/i18n_catalog.js b/django/views/templates/i18n_catalog.js index b1fe4a9aac..4d168840fd 100644 --- a/django/views/templates/i18n_catalog.js +++ b/django/views/templates/i18n_catalog.js @@ -33,7 +33,13 @@ if (typeof value === 'undefined') { return msgid; } else { - return (typeof value === 'string') ? value : value[0]; + if (typeof value === 'string') { + return value; + } + + const text = value[0]; + + return typeof text === 'string' ? text : msgid; } }; @@ -42,7 +48,17 @@ if (typeof value === 'undefined') { return (count == 1) ? singular : plural; } else { - return value.constructor === Array ? value[django.pluralidx(count)] : value; + if (value.constructor === Array) { + const text = value[django.pluralidx(count)]; + + if (typeof text === 'undefined') { + return (count == 1) ? singular : plural; + } else { + return text; + } + } + + return value; } };