You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. The core thing is DX. We want compiler to work as seamless as possible.
4
+
2. It should work at least with turbopack (since it's next default bundler), webpack and vite.
5
+
3. HMR should work, whenever we update the code the state of the app should be kept as it owuld be without the compiler.
6
+
4. There should be a way to override the translations
7
+
5. We should be able to translate the attributes, the most obvious ones are alt and aria-label, aria-description and
8
+
such, but we may also add a way to translate other string attributes too.
9
+
6. We should keep translations calls to the minimum.
10
+
7. We start with react, but it would be nice to apply the same approach to other frameworks. Like vue and astro. So the
11
+
system should be flexible.
12
+
8. The translations should be possible to commit in the repo, so we can version them. Maybe we can also consider
13
+
conforming to the existing standard?
4
14
5
-
### Dev mode
15
+
##Overall architecture
6
16
7
-
- When the app is started we should extract translatable text from the code and inject our translation functions.
8
-
- When the user changes the code, we should re-extract the text and update the translation functions.
9
-
- If a non source language is used (e.g. sources are in english, and user switches to the german) we want to start translations and update the app when they are ready.
17
+
Given that we still may want translations in the dev mode, but we want to keep them to minimum and do not interfere with
18
+
the development flow, we may consider the following approach:
10
19
11
-
### Build mode
20
+
1. Do not translate the text unless explicitly requested.
21
+
2. Allow using pseudolocalization for even more simple checks. It shows which part of the UI can be translated by
22
+
compiler, and also using varying width of the text highlights part of the interface not ready for varying languages.
12
23
13
-
- During build we need to extract all the translatable text from the code and inject our translation functions.
14
-
- While the build is in progress, we should perform the translation and create files with translations.
15
-
- When the build ends we should make sure that all the translations are in place.
16
-
- Ideally split translations into multiple chunks, according to the js chunks maybe.
24
+
This leads us to the question, how to lazily request the translations in the dev mode.
25
+
Let's work with the SPA apps as an example (since SSR apps may have more options).
26
+
Both currently rendered components and the locale are client side.
27
+
Cache for translations is stored in the filesystem in the project.
28
+
So the way to receive a request from the browser to the host that will get the translations and store the cache.
17
29
18
-
In the end we should have a built app with all the translations in place.
30
+
The most straightforward way to do this is to use the usual web server. App will send a request for translations when needed,
31
+
server components can do the same. This adds a bit of latency but keeps the code uniform.
19
32
20
-
## Problems of the current implementation
33
+
With this approach we get couple more questions:
21
34
22
-
We want to avoid fetching translations if they are not needed. To achieve this, we need to ask for translations if they are missing.
23
-
We also want to cache the translations to avoid unnecessary requests, by default, the cache is on the user machine.
24
-
But client side components in the browser can't access the user machine to save the cache.
35
+
- How to start the server
36
+
- How to make the client aware about server's address
37
+
- How to batch the calls, both client and server side.
25
38
26
-
This can be solved by adding separate route/middleware on the user machine that can be called from the client and will serve the translations.
27
-
We can use Vite middleware and Next routeHandler to do this.
39
+
How to start the server
40
+
While it sounds simple, it's not that simple if you don't want to create any external scripts.
41
+
We have at least three environments:
28
42
29
-
- The approaches differ for different bundlers
30
-
- We do not want to ask the user to add the extra route handlers to their app.
43
+
- Next turbopack: no startup hooks.
44
+
- Next webpack: there is compiler.hooks.watchRun. Well, watchRun runs on every script compilation during hot reload.
45
+
- Vite: buildStart.
31
46
32
-
## Possible solution
47
+
So next with turbopack is the most complex case.
33
48
34
-
Use a separate server that will serve the translations. It can be started by the compiler. Then client components can fetch the translations from the server.
49
+
It shows which part of the UI can be translated by
0 commit comments