Categories
Mastering Development

How can I implement i18n as a JSON object in a .Net EF Core?

I am making a Web API .Net Core 3.1 application that serves data from a MySQL database with OData protocol.

My question is how can I add internationalization functionality (i.e. i18n) to a specific column without any foreign keys, by using JSON structure?

For example I would like to define an entity model like this:

    public partial class City
    {
        public City(){}

        public ulong Id { get; set; }
        public string Name { get; set; }
        public string CountryId { get; set; }
        public DateTime? CreatedAt { get; set; }
        public DateTime? UpdatedAt { get; set; }

        public virtual Country Country { get; set; }
    }

and then the data in Name column would be stored like the following for en and de locales:

{"en":"Cologne","de":"Köln"}

And then when the current locale is de the Köln and when the en is set as the current locale then Cologne fetch in the time of reading data!

Also when we store the data, the passed string is stored in the relevant property in the JSON format. For example if the locale is set to es and user passes Kolne then we have to have the following data in the DB:

{"en":"Cologne","de":"Köln","es":"Kolne"}

What I am looking for is some solutions like this one which is suggested for Laravel and store the translations exactly in the way that I explained (i.e. in a JSON object and in a single column without any foreign keys)!

I am looking for some kind of NuGet that do this process automatically.

Please notice this question is not about i18n JSON files!!! and is about JSON objects in database!

Leave a Reply

Your email address will not be published. Required fields are marked *