From 5406448be01aba6a4f3b4ff8f44365e37da855fc Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sat, 14 May 2022 17:10:48 +0200 Subject: [PATCH] Use singular localization form when plural form is not provided (closes #1878) --- changelog/68_UNRELEASED_xxxx-xx-xx.md | 1 + public/js/grocy.js | 5 +++++ services/LocalizationService.php | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/changelog/68_UNRELEASED_xxxx-xx-xx.md b/changelog/68_UNRELEASED_xxxx-xx-xx.md index fef4405a..8c264f20 100644 --- a/changelog/68_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/68_UNRELEASED_xxxx-xx-xx.md @@ -11,6 +11,7 @@ - New product option "Move on open" (defaults to disabled) - When enabled, on marking the product as opened, the corresponding amount will be moved to the products default consume location - (Thanks @RosemaryOrchard) +- Optimized that when the plural form(s) of a quantity unit is/are not provided, the singular form is used to display plural amounts - Fixed "Automatically add products that are below their defined min. stock amount to the shopping list" (stock setting) was only done when consuming products, not when opening them ### Shopping list diff --git a/public/js/grocy.js b/public/js/grocy.js index e58d7525..a7c6ff59 100644 --- a/public/js/grocy.js +++ b/public/js/grocy.js @@ -257,6 +257,11 @@ __n = function(number, singularForm, pluralForm, isQu = false) } } + if (pluralForm.isEmpty()) + { + pluralForm = singularForm; + } + if (isQu) { return Grocy.TranslatorQu.n__(singularForm, pluralForm, Math.abs(number), Math.abs(number)) diff --git a/services/LocalizationService.php b/services/LocalizationService.php index c758303d..d076bde4 100644 --- a/services/LocalizationService.php +++ b/services/LocalizationService.php @@ -78,6 +78,11 @@ class LocalizationService { $this->CheckAndAddMissingTranslationToPot($singularForm); + if (empty($pluralForm)) + { + $pluralForm = $singularForm; + } + if ($isQu) { return sprintf($this->TranslatorQu->ngettext($singularForm, $pluralForm, abs(floatval($number))), $number); @@ -218,6 +223,7 @@ class LocalizationService $translation = new Translation('', $quantityUnit['name']); $translation->setTranslation($quantityUnit['name']); $translation->setPlural($quantityUnit['name_plural']); + $translation->setPluralTranslations(preg_split('/\r\n|\r|\n/', $quantityUnit['plural_forms'])); $this->PoQu[] = $translation;