ericpaulbishop / gargoyle

Gargoyle Router Management Utility
http://www.gargoyle-router.com
465 stars 222 forks source link

Misconversion of units in other languages #989

Closed obsy closed 1 year ago

obsy commented 1 year ago

First, let's see the login page and limits in English and another language: Zrzut ekranu z 2023-05-25 07-19-23 Zrzut ekranu z 2023-05-25 07-19-57

I have a daily limit of 100GB, now I'm using 60MB, the English page shows the units used in the same units as the limit but not Polish page.

See function parseBytes: https://github.com/ericpaulbishop/gargoyle/blob/master/package/gargoyle/files/www/js/common.js#L1035 It has hard-coded units, e.g. GBytes. But in other language we use different text (Polish: 100 GB, French: 100 GO) so GB doesn't match GBytes.

lantis1008 commented 1 year ago

Now that 1.14 is out, I'll bring in your other PR and look to solve this one. Apologies for the delay.

lantis1008 commented 1 year ago
--- a/package/gargoyle/files/www/js/common.js
+++ b/package/gargoyle/files/www/js/common.js
@@ -1035,17 +1035,17 @@ function resetProofreadFields(inputIds)
 function parseBytes(bytes, units, abbr, dDgt)
 {
        var parsed;
-       units = units != "KBytes" && units != "MBytes" && units != "GBytes" && units != "TBytes" ? "mixed" : units;
+       units = ["KBytes","MBytes","GBytes","TBytes",UI.KBy,UI.MBy,UI.GBy,UI.TBy].indexOf(units) < 0 ? "mixed" : units;
        spcr = abbr==null||abbr==0 ? " " : "";
-       if( (units == "mixed" && bytes > 1024*1024*1024*1024) || units == "TBytes")
+       if( (units == "mixed" && bytes > 1024*1024*1024*1024) || ["TBytes",UI.TBy].indexOf(units) >= 0)
        {
                parsed = (bytes/(1024*1024*1024*1024)).toFixed(dDgt||3) + spcr + (abbr?UI.TB:UI.TBy);
        }
-       else if( (units == "mixed" && bytes > 1024*1024*1024) || units == "GBytes")
+       else if( (units == "mixed" && bytes > 1024*1024*1024) || ["GBytes",UI.GBy].indexOf(units) >= 0)
        {
                parsed = (bytes/(1024*1024*1024)).toFixed(dDgt||3) + spcr + (abbr?UI.GB:UI.GBy);
        }
-       else if( (units == "mixed" && bytes > 1024*1024) || units == "MBytes" )
+       else if( (units == "mixed" && bytes > 1024*1024) || ["MBytes",UI.MBy].indexOf(units) >= 0)
        {
                parsed = (bytes/(1024*1024)).toFixed(dDgt||3) + spcr + (abbr?UI.MB:UI.MBy);
        }

Can you please test the above? Looks fine on my end. I tested login screen with quotas, conntrack page and bandwidth page.

obsy commented 1 year ago

Ok, looks like it's working fine.

lantis1008 commented 1 year ago

Thanks, should be fixed by 6bd0c24773b7386bdbacfecdcd61b50db357f8f2