Reputation: 84
We have a Web.API application where we have to supported a Dutch and English language. For that we have set the culture as “nl” or “en” based on the user request.
But, we have facing the issue in “NumberDecimalSeparator” because for “en” it’s “.” and for “nl” it’s “,”. Now When user want to post or get any data for “nl” language then value should be display/posted as “,” and for “en” language it should display/posted as “.”.
Does anyone have idea on that How we can handle this ?
I am using Linq query and I have to display retried data based on language.
Thank you in advance..
Linq Query as bellow
var test = await (from x in db.instance.Where(x => x.ID == 36)
select new GeofenceAttributeModel()
{
Address = x.geofenceattribute != null ? x.geofenceattribute.Address : string.Empty,
Latitude = x.geofenceattribute != null && x.geofenceattribute.Latitude.HasValue ? x.geofenceattribute.Latitude : null,
Longitude = x.geofenceattribute != null && x.geofenceattribute.Longitude.HasValue ? x.geofenceattribute.Longitude : null,
RadiusInMtr = x.geofenceattribute != null ? x.geofenceattribute.RadiusInMtr.ToString() : string.Empty
}).FirstOrDefaultAsync();
Upvotes: 0
Views: 584
Reputation: 18013
Welcome to globalization support.
A rule of thumb: use the current locale only when it is parsed or displayed in the UI (eg. web browser).
In every other case (storing data, communication between components in textual formats, including json or XML body of posts) use invariant culture. At server side it should be completely transparent whether the UI uses Dutch or English or any other culture.
Never serialize numbers and datetime values with the local culture; otherwise, when you have to deserialize your data you cannot tell anymore whether a comma is a decimal sign or thousand separator, for example.
In your code RadiusInMtr.ToString()
uses the system's local culture (Thread.CurrentThread.CurrentCulture
). It is OK only if the string is displayed in the UI. If you use this string to transfer some data to another component, use ToString(CultureInfo.InvariantCulture)
instead. And specify the culture when you parse the string similarly.
Upvotes: 3