Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Is FormatProvider used ? #534

Open
StefH opened this issue Dec 5, 2022 · 3 comments
Open

[Question] Is FormatProvider used ? #534

StefH opened this issue Dec 5, 2022 · 3 comments
Labels

Comments

@StefH
Copy link
Collaborator

StefH commented Dec 5, 2022

Related to this old question:
#344

The model:

var culture = CultureInfo.CreateSpecificCulture("en-US");
var jsonSettings = new JsonSerializerSettings
        {
            Culture = culture
        };
var model = JsonConvert.DeserializeObject("{ \"id\": 0.005 }", jsonSettings);

The template:

"test {{id}}"

Handlebars created like:

var config = new HandlebarsConfiguration
{
    FormatProvider = culture
};
var handlebars = HandlebarsDotNet.Handlebars.Create(config);

Execute the template:

var template = Handlebars.Compile(text);
var result = template(model);

And the result is:

"test 0,005" // <-- It's formatted using my local culture (Dutch) and not en-US?
@StefH StefH added the question label Dec 5, 2022
@StefH
Copy link
Collaborator Author

StefH commented Dec 9, 2022

@zjklee or @rexm : do you have an idea on this?

@Nisden

This comment was marked as outdated.

@Nisden
Copy link
Contributor

Nisden commented Dec 23, 2022

@StefH Please ignore my first "solution" the actual solution is to deserialize into an ExpandObject, that still allows you to support dynamic values.

So your code should look like the following

var culture = CultureInfo.CreateSpecificCulture("en-US");
var model = JsonConvert.DeserializeObject<ExpandObject>("{ \"id\": 0.005 }");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants