Resource Loading
How translation files are loaded depends on where your translation resources are stored:
Static File Backend
Put translation files in your project and the plugin loads them directly. This is the most common approach.
CSR and SSR use different loading mechanisms, but the configuration is exactly the same:
- CSR: The browser fetches translation files through HTTP, such as
GET /locales/zh/translation.json. - SSR: The server reads files directly from disk without making HTTP requests.
The plugin automatically chooses the right mechanism based on the runtime environment. You only need to configure loadPath once.
Resource file location:
To store files in another directory, configure server.publicDir. The relationship between server.publicDir and backend.loadPath is:
server.publicDir: Decides which local directory is exposed as static assets, that is, where files are placed.backend.loadPath: Decides which URL i18next requests for translation files, or which path the server reads from.
Custom Backend
When translation resources are not local files but come from a remote API, database, or translation platform, load them with an async function.
Step 1: declare it enabled in modern.config.ts
Step 2: implement the loader function in modern.runtime.ts
Loader parameter type:
When using a custom backend, translation resources are loaded asynchronously. You can use isResourcesReady to show a loading state before loading is complete. See Best Practices -> Loading State Handling.
Chained Backend
Use local files and a custom backend together to implement "show local translations quickly first, then update asynchronously with the latest translations":
- When the page loads, translations are loaded from local files and displayed immediately.
- The custom backend loads the latest translations asynchronously in the background. After it completes, the page updates automatically.
cacheHitMode option (controls how the two backends cooperate):