S
S
Stanislav Menshov2019-07-17 14:49:41
JavaScript
Stanislav Menshov, 2019-07-17 14:49:41

How to correctly organize language support for the Clients - Server (RESTFULL) application?

Hello! Came for the advice of architects.
There is a task to internationalize an application with the architecture Server (RESTFULL API) -> Clients (WEB, Mobile, Desktop).
Application: Binary Options System
Purpose : to internationalize the application.
Data sources: MongoDB document-oriented storage. The data is stored in BSON format as a list without nesting . The storage does not provide dynamic strings of the string, long, blob types, only dynamics with the decimal type. This data does not need localization
Why internationalization is needed: it is needed for comfortable use of the application by service users.
Functional requirements: Only static data (not Input) should be localized on the application server side and/or its clients (web, desktop, mobile). It should also be possible to template strings. The client (browser, mobile application) determines the user's region.
Management: It should be possible to edit language lists for both the programmer and the database administrator. At the initial level, it will be enough to manage through the database directly.
Question : how to do it? On clients or server? To give the server ready-made data with the necessary translation or to give codes for translation on clients? There may be many clients.
It should all be easy to maintain and expand.
Technology stack:
Clients: JS, JSON
Server: NodeJS, MongoDb, Redis

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Shumov, 2019-07-17
@SWEBB

There are a lot of ways - from adding headers with the preferred language to query parameters. Depends on what and how to work with. Understand your data, as they say

V
Vladimir Korotenko, 2019-07-19
@firedragon

Code for C#, but I think the idea is clear. As for the headers, I think it’s not worth it, sending something like
X-Lang: en
is perverted in my opinion, you will have to configure these headers also for reverse proxy.
More about formatted strings. Store everything on the server as placeholders. On the client, just format. Of the pluses, if the line changes, then all clients will receive it automatically.
For example:

var localizableDict = { 
   pageTitle: "Page title",
  copyright:  " {{ copyDate }} ©" // выберите какой нибудь template engine для форматирования
}

Accordingly, requests go like this:
GET /api/v1/documents/ en /search/some+search
GET /api/v1/documents/ ru /search/some+search
[Authorize]
        [HttpGet]
        [Route("{lang}/search/{query}")]
        [Route("{lang}/search")]
        public async Task<IActionResult> Search([FromRoute] string lang="en", string query = "")
        {
            try
            {
                var user = await _ctx.Users.GetUserByName(User.Identity.Name);
                var appUser = Mapper.Map<ApplicationUser>(user);               
                if(lang == "en"){
                       // todo: apply localization
                 }
                return Json(appUser);
            }
            catch (Exception e)
            {
                _logger.LogError($"Search error. {e.Message}");
                return BadRequest();
            }
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question