|
1 | | -// src/i18n/config.ts |
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2025 Porpoiseful LLC |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
2 | 17 |
|
3 | | -// Core i18next library. |
| 18 | +/** |
| 19 | + * @fileoverview Configuration for i18n |
| 20 | + * @author [email protected] (Alan Smith) |
| 21 | + * |
| 22 | + * This is mostly borrowed with a few adaptations from |
| 23 | + * https://phrase.com/blog/posts/localizing-react-apps-with-i18next/ |
| 24 | + */ |
4 | 25 | import i18n from "i18next"; |
5 | 26 | import HttpApi from "i18next-http-backend"; |
6 | | -// Bindings for React: allow components to |
7 | | -// re-render when language changes. |
8 | 27 | import { initReactI18next } from "react-i18next"; |
9 | 28 |
|
10 | 29 | i18n |
11 | | - // Wire up the backend as a plugin. |
| 30 | + // Add backend as a plugin so we can load the needed translation at runtime |
12 | 31 | .use(HttpApi) |
13 | | - // Add React bindings as a plugin. |
| 32 | + // Add React bindings as a plugin so it will re-render when language changes |
14 | 33 | .use(initReactI18next) |
15 | | - // Initialize the i18next instance. |
16 | 34 | .init({ |
17 | 35 | // Config options |
18 | 36 |
|
19 | 37 | // Specifies the default language (locale) used |
20 | 38 | // when a user visits our site for the first time. |
21 | | - // We use English here, but feel free to use |
22 | | - // whichever locale you want. |
23 | 39 | lng: "en", |
24 | 40 |
|
25 | | - // Fallback locale used when a translation is |
26 | | - // missing in the active locale. Again, use your |
27 | | - // preferred locale here. |
| 41 | + // Fallback locale used when a translation is missing. |
28 | 42 | fallbackLng: "en", |
29 | 43 |
|
30 | | - // Normally, we want `escapeValue: true` as it |
31 | | - // ensures that i18next escapes any code in |
32 | | - // translation messages, safeguarding against |
33 | | - // XSS (cross-site scripting) attacks. However, |
34 | | - // React does this escaping itself, so we turn |
35 | | - // it off in i18next. |
| 44 | + // Normally, we want `escapeValue: true` as it ensures that i18next escapes any code in |
| 45 | + // translation messages, safeguarding against XSS (cross-site scripting) attacks. However, |
| 46 | + // React does this escaping itself, so we turn it off in i18next. |
36 | 47 | interpolation: { |
37 | 48 | escapeValue: false, |
38 | 49 | }, |
|
0 commit comments