UnityCsvUtil icon indicating copy to clipboard operation
UnityCsvUtil copied to clipboard

CultureInfo parsing/seralizing.

Open LiamKarlMitchell opened this issue 3 years ago • 1 comments

A note when working with decimal numbers or potentially other formatted texts and encoding/decoding. "Currency Symbols, Date/Time, Numbers" probably.

May want to ensure using an explicit CultureInfo when reading/saving data to text files e.g. ToString or parsing on numbers might have different formatting depending on the local OS language settings. Which can cause data to bug out or not be compatible between different culture infos.

E.g. '100.123,0'

one thousand dot two In Spain, you'll see 1.000'2 In Mexico will be seen as 1,000.2 In New Zealand will be seen as 1000.02

See: https://fastspring.com/blog/how-to-format-30-currencies-from-countries-all-over-the-world/

This could perhaps be provided as a way to set in the code. Or just a note in the readme to the user.

This can set the threads culture info. But could be a good idea to make it able to be set by the user of the code with a default to OS set locale/culture.

System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo( "en-US" );
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo( "en-US" );

LiamKarlMitchell avatar Apr 09 '21 20:04 LiamKarlMitchell

As with #9 this is about deploying a CSV to end users where the culture may be different, which isn't really the intended usage of this library (it was intended for dev iteration, because CSVs are too easy to change in the wild). Given that a developer will be creating a CSV in their own culture settings it made sense to load using those same settings, but yes this doesn't work when deployed.

If you want to make that work the culture should be an optional parameter to the Save/Load functions, not a constant, so that a dev in Spain can use their own format and then deploy that and have it load correctly in e.g. en-US as well.

As previously mentioned I'm not working on this library anymore because I've moved away from Unity. I suggest forking for your use and a PR is welcome if you make this an optional parameter in the Load/Save calls.

sinbad avatar Apr 12 '21 09:04 sinbad