jsakamoto / Toolbelt.Blazor.I18nText

The class library that provides the ability to localize texts on your Blazor app!
Mozilla Public License 2.0
246 stars 23 forks source link

Stops working properly with large number of items #52

Open BillyCool opened 2 years ago

BillyCool commented 2 years ago

Hello,

I'm trying out this library in a Blazor WASM project with a JSON file with ~20K items. The first ~16K items are localized correctly, but anything after that gives me a seemingly random localization, not the one I'm requesting.

Using the latest version, v.11.1.4. Is this a limitation of the library?

jsakamoto commented 2 years ago

@BillyCool Thank you for reporting. Honestly, I've never considered the scale of JSON files. So I'm not sure about the limitation of the file size of JSON files even though this is my product. Could you provide your JSON file that includes ~20K items? (You can attach any files to this GitHub issue thread by drag & drop files.) I'd like to investigate it.

BillyCool commented 2 years ago

Hey there, Since opening this I did more tests with a simple JSON file that is just numbers in ascending order up to 50K to see if I can figure out a pattern. I noticed that using that file, I can render correctly up to 24741, which is not consistent with the 16K figure I got earlier with a different file, so perhaps it is sensitive to the length of the JSON file and not the raw number of items.

Using the attached file (rename to .json):

... 24740 - 24740 24741 - 24741 24742 - A whole lot of gibberish 24743 - 24744 - 1 24745 - 10 24746 - 100 24747 - 1000 24748 - 10000 24749 - 10001 24750 - 10003 24751 - 10004 ..

Numbers.en.txt

jsakamoto commented 2 years ago

@BillyCool I've investigated this problem. Unfortunately, this strange behavior seems to be a bug of the reflection feature by the .NET IL interpreter on a WebAssembly.

The "I18n Text" library assigns field values of a text table object from a JSON file using the reflection feature. If the text object class has tons of fields, that reflection feature looks like it doesn't work expectedly on Blazor WebAssembly.

If you run your code on Blazor Server, it will work fine even if the text object class has 50,000 fields.

You can verify that behavior by the sample code I published on the following link.

https://github.com/sample-by-jsakamoto/Blazor-TheClassHavingOver10KFields

It will work fine if you run the Blazor Server edition of that sample code. image

However, the Blazor WebAssembly edition will not work correctly. image

I have no idea what I can do about this problem for now. I guess that splitting your text table into some JSON files is the only workaround.