ASP.NET Core 3.1, i18n - Localization of user content

Viewed 475

I have absolutely no experience in designing multilingual applications and I thought I'd start a learning project. I am looking for best practices on how to implement it properly. Of course, I have an idea how I would do it.

Let's imagine a very simple CMS system, where the user can create a website and add pages to it. So, with only one language support, a very simple database would look like this:

  • PageID (int), primary key - the unique ID of the page
  • Title (text) - the page's title
  • Content (text) - the page's content

And if I want to support multiple languages, I would add a new field:

  • Language (text) - the page's language, represented as an IETF language tag (eg. hu-HU, en-US)

Also, I would change the key, making it a complex primary key (PageID, Language). An example database would look like this:

| PageID | Language | Title    | Content                 |
|--------|----------|----------|-------------------------|
| 1      | hu-HU    | Cím      | Ide jön a tartalom      |
| 1      | en-US    | Title    | Here goes the content   |
| 2      | hu-HU    | Rólunk   | A mi célunk az, hogy... |
| 2      | en-US    | About us | Our goal is...          |

I would like to use the Accept-Language header to determine in which language do I need to send the content to the client. This is pretty straightforward with such a simple value, like

Accept-Language: hu-HU

Since Accept-Language is a prioritized list, I would take the intersection of the two sets (the header's list and the languages supported by my system), and take the highest priority language from it - assuming that we always have a non-empty intersection. But here it gets really difficult (for me, at least).

  1. What should I do if the Accept-Language is "hu,en"? I will not have an exact match in the database in this case (since I have "hu-HU" and "en-US"). Or even worse, the header is "en", but in the database I have "en-US" and "en-GB"?

  2. Should the application configuration have a setting for the supported languages? I think it would be a good idea, since the application can enforce the user to create the content for every language, but it can get quite difficult to add a new language to the system. But if it's not stored in configuration, it is possible that the user creates the content for hu-HU, but not for en-US.

  3. What should I do if the client requests the content in a language which is not supported by the system? My idea is to have a "default language" setting in the application configuration for such cases.

  4. Is there any support in ASP.NET Core 3.1 that can help me out?

  5. Umm... is this the way it is usually implemented, or am I at a completely wrong direction?

0 Answers
Related