diff --git a/grocy.openapi.json b/grocy.openapi.json index 403c536b..f72b4a09 100644 --- a/grocy.openapi.json +++ b/grocy.openapi.json @@ -1244,6 +1244,9 @@ "name": { "type": "string" }, + "name_plural": { + "type": "string" + }, "description": { "type": "string" }, diff --git a/helpers/extensions.php b/helpers/extensions.php index a23a73af..82a66ff2 100644 --- a/helpers/extensions.php +++ b/helpers/extensions.php @@ -168,3 +168,13 @@ function GetUserDisplayName($user) return $displayName; } + +function Pluralize($number, $singularForm, $pluralForm) +{ + $text = $singularForm; + if ($number != 1 && $pluralForm !== null && !empty($pluralForm)) + { + $text = $pluralForm; + } + return $text; +} diff --git a/localization/de.php b/localization/de.php index db943ea8..31d303d3 100644 --- a/localization/de.php +++ b/localization/de.php @@ -2,7 +2,6 @@ return array( 'Stock overview' => 'Bestand', - '#1 products with #2 units in stock' => '#1 Produkte (#2 Einheiten) vorrätig', '#1 products expiring within the next #2 days' => '#1 Produkte laufen innerhalb der nächsten #2 Tage ab', '#1 products are already expired' => '#1 Produkte sind bereits abgelaufen', '#1 products are below defined min. stock amount' => '#1 Produkte sind unter Mindestbestand', @@ -194,6 +193,18 @@ return array( 'Price' => 'Preis', 'in #1 per purchase quantity unit' => 'in #1 pro Einkaufsmengeneinheit', 'The price cannot be lower than #1' => 'Der Preis darf nicht niedriger als #1 sein', + '#1 product expires within the next #2 days' => '#1 Produkt läuft innerhalb der nächsten #2 Tage ab', + '#1 product is already expired' => '#1 Produkt ist bereits abgelaufen', + '#1 product is below defined min. stock amount' => '#1 Produkt ist unter Mindestbestand', + 'Unit' => 'Einheit', + 'Units' => 'Einheiten', + '#1 habit is due to be done within the next #2 days' => '#1 Gewohnheit steht in den nächsten #2 Tagen an', + '#1 habit is overdue to be done' => '#1 Gewohnheit ist überfällig', + '#1 battery ist due to be charged within the next #2 days' => '#1 Batterie muss in den nächsten #2 Tagen geladen werden', + '#1 battery ist overdue to be charged' => '#1 Batterie ist überfällig', + '#1 unit was automatically added and will apply in addition to the amount entered here' => '#1 Einheit wurde automatisch hinzugefügt und gilt zusätzlich der hier eingegebenen Menge', + 'in singular form' => 'in der Einzahl', + 'in plural form' => 'in der Mehrzahl', //Constants 'manually' => 'Manuell', diff --git a/localization/it.php b/localization/it.php index 8ca0b331..7a36f846 100644 --- a/localization/it.php +++ b/localization/it.php @@ -2,7 +2,6 @@ return array( 'Stock overview' => 'Dispensa', - '#1 products with #2 units in stock' => '#1 prodotti stano per finire(#2 unità)', '#1 products expiring within the next #2 days' => '#1 prodotti scadranno tra #2 giorni', '#1 products are already expired' => '#1 prodotti scaduti', '#1 products are below defined min. stock amount' => '#1 prodotti sotto il limite minimo', diff --git a/localization/no.php b/localization/no.php index 6161a44f..261bba80 100644 --- a/localization/no.php +++ b/localization/no.php @@ -2,7 +2,6 @@ return array( 'Stock overview' => 'Husholdning', - '#1 products with #2 units in stock' => '#1 Produkter med #2 i husholdningen', '#1 products expiring within the next #2 days' => '#1 Produkter som går ut på dato innen de neste #2 dagene', '#1 products are already expired' => '#1 Produkt som har gått ut på dato', '#1 products are below defined min. stock amount' => '#1 Produkt under minimum husholdningsnivå', diff --git a/migrations/0030.sql b/migrations/0030.sql new file mode 100644 index 00000000..425795cf --- /dev/null +++ b/migrations/0030.sql @@ -0,0 +1,2 @@ +ALTER TABLE quantity_units +ADD name_plural TEXT; diff --git a/public/js/grocy.js b/public/js/grocy.js index d8e3e410..421cb200 100644 --- a/public/js/grocy.js +++ b/public/js/grocy.js @@ -19,6 +19,16 @@ U = function(relativePath) return Grocy.BaseUrl.replace(/\/$/, '') + relativePath; } +Pluralize = function(number, singularForm, pluralForm) +{ + var text = singularForm; + if (number != 1 && pluralForm !== null && !pluralForm.isEmpty()) + { + text = pluralForm; + } + return text; +} + if (!Grocy.ActiveNav.isEmpty()) { var menuItem = $('#sidebarResponsive').find("[data-nav-for-page='" + Grocy.ActiveNav + "']"); diff --git a/public/viewjs/components/productcard.js b/public/viewjs/components/productcard.js index f7acfac8..aa9fcace 100644 --- a/public/viewjs/components/productcard.js +++ b/public/viewjs/components/productcard.js @@ -5,10 +5,11 @@ Grocy.Components.ProductCard.Refresh = function(productId) Grocy.Api.Get('stock/get-product-details/' + productId, function(productDetails) { + var stockAmount = productDetails.stock_amount || '0'; $('#productcard-product-name').text(productDetails.product.name); - $('#productcard-product-stock-amount').text(productDetails.stock_amount || '0'); + $('#productcard-product-stock-amount').text(stockAmount); $('#productcard-product-stock-qu-name').text(productDetails.quantity_unit_stock.name); - $('#productcard-product-stock-qu-name2').text(productDetails.quantity_unit_stock.name); + $('#productcard-product-stock-qu-name2').text(Pluralize(stockAmount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural)); $('#productcard-product-last-purchased').text((productDetails.last_purchased || L('never')).substring(0, 10)); $('#productcard-product-last-purchased-timeago').text($.timeago(productDetails.last_purchased || '')); $('#productcard-product-last-used').text((productDetails.last_used || L('never')).substring(0, 10)); diff --git a/views/batteriesoverview.blade.php b/views/batteriesoverview.blade.php index b95119ab..440bae49 100644 --- a/views/batteriesoverview.blade.php +++ b/views/batteriesoverview.blade.php @@ -12,8 +12,8 @@