cookbook icon indicating copy to clipboard operation
cookbook copied to clipboard

Fix unicode fraction conversion

Open christianlupus opened this issue 1 year ago • 9 comments

Description When using unicode fractions, the web UI reports the ingredient to not be parsable but in fact it is parsable and correctly calculated.

Reproduction Steps to reproduce the behavior:

  1. Create or edit a recipe
  2. Add an ingredient with a unicode fraction, e.g. ¾
  3. Save and view the recipe
  4. Change the recipe yield to trigger recalculation

Expected behavior No warning is shown to the user

Actual behavior A warning sign is shown to the user indicating a problem with the calculation (see screenshots).

Screenshots grafik

After changing the yield amount: grafik

Browser Firefox

Versions Nextcloud server version: 30 Cookbook version: 0.11.1 Database system: MySQL


Maybe @Weissnix4711 or @j0hannesr0th, can you have a look at this? Ideally, I would say that the same Regex is used to check and to do the actual calculation to avoid such conflicts. That would mean some restructuring but should be managable.

christianlupus avatar Sep 12 '24 14:09 christianlupus

Hi @christianlupus I'll have a look at this one.

Do you want to support the common Unicode fractions or custom Unicode fractions like ⁷⁷⁄₇₈ too?

j0hannesr0th avatar Sep 12 '24 14:09 j0hannesr0th

Uhh, maybe I fucked the regex

Weissnix4711 avatar Sep 12 '24 15:09 Weissnix4711

In the PR there was a discussion to mainly look for x/2, x/4, and x/16 as far as I remember.

I suggest you two align a bit to avoid duplicate work.

christianlupus avatar Sep 12 '24 15:09 christianlupus

Ahh and one more point: I want to push out a release tomorrow. On Saturday there is a NC server release and we need a new cookbook version ready as otherwise these will complain.

I am okay with delaying this until after the release. Just be warned that I am not going to be able to do much about this in the next few hours. :wink:

christianlupus avatar Sep 12 '24 15:09 christianlupus

Yeah ideally we should probably use the same regex, but the easy solution is this:

diff --git a/src/js/yieldCalculator.js b/src/js/yieldCalculator.js
index bfe2da97..47bf75d3 100644
--- a/src/js/yieldCalculator.js
+++ b/src/js/yieldCalculator.js
@@ -11,7 +11,7 @@ function isValidIngredientSyntax(ingredient) {
         It may optionally have a unit but must be proceeded by a single whitespace and further text.
     */
     const ingredientSyntaxRegExp =
-        /^(?:(?:\d+\s)?(?:\d+\/\d+|\p{No})|\d+(?:\.\d+)?)[a-zA-z]*\s.*$/;
+        /^(?:(?:\d+\s)?(?:\d+\/\d+|\p{No})|\d+(?:\.\d+)?)[a-zA-z]*\s.*$/u;
 
     /*
         The ingredientMultipleSeperatorsRegExp is used to check whether the string contains

I missed the u flag.

Weissnix4711 avatar Sep 13 '24 09:09 Weissnix4711

Feel free to give it a go from my side. Ideally there is some error handling involved if we update the regex (for whatever reason), this is not breaking again.

christianlupus avatar Sep 13 '24 11:09 christianlupus

@christianlupus

off-topic but visible from your screenshots in the original issue description above.

The message in german is using repeated negation and therefor may not sound logic to me or other native speakers: https://github.com/nextcloud/cookbook/blob/5c7f7f0ad0956c4e5f3c1d0b9cdb83a864c4bc16/l10n/de.js#L247

(i) Die Menge der Zutat kann aufgrund einer nicht unterstützten Syntax nicht neu berechnet werden. Bitte stelle sicher, dass die Syntax diesem Format folgt: Menge Einheit Zutat und dass eine bestimmte Anzahl von Portionen eingegegeben ist, damit diese Funktion korrekt funktioniert. Beispiele: 200 g Karotten oder 1 Prise Salz.

There is already a shorter and fixed version in the translation file(s) too: https://github.com/nextcloud/cookbook/blob/5c7f7f0ad0956c4e5f3c1d0b9cdb83a864c4bc16/l10n/de.js#L209

(i) Die Menge der Zutat kann aufgrund einer falschen Syntax nicht neu berechnet werden. Bitte ändere sie in diese Syntax: Menge Einheit Zutat. Beispiele: 200 g Karotten oder 1 Prise Salz

Maybe the second line 247 has been introduced by a merge resolution and supersedes the earlier line 209 in effect.

stefan123t avatar Nov 26 '24 21:11 stefan123t

@stefan123t this must be fixed in Transifex. See https://docs.nextcloud.com/server/latest/developer_manual/basics/front-end/l10n.html#adding-translations

christianlupus avatar Dec 02 '24 15:12 christianlupus

@christianlupus the new message was introduced in https://github.com/nextcloud/cookbook/commit/163ea4126e6b66ea39ca89383e2987bcd0603edd merged by @j0hannesr0th

Agreed many of the translations did not yet implement the new message and a proper translation for that. Though the old message should be removed from each and every cookbook/l10n/*.{json,js} translation file too.

stefan123t avatar Dec 03 '24 01:12 stefan123t

Is this still being worked on?

locrianz avatar Nov 26 '25 17:11 locrianz