Skip to content

Commit 370bb02

Browse files
committed
docs(localization): add translation guide for contributors
Add a TRANSLATION_GUIDE.md to the localization package that documents: - Current supported languages - Step-by-step instructions for adding a new language - How to register translations in locales.ts and messages.ts - Tips for translators (preserving placeholders, finding missing keys) - Translation structure and how keys are referenced in components This lowers the barrier for community members to contribute translations. Fixes #3000 Signed-off-by: pierreeurope <pierre.europe@pm.me>
1 parent cec11f3 commit 370bb02

1 file changed

Lines changed: 121 additions & 0 deletions

File tree

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Translation Guide for kepler.gl
2+
3+
Thank you for helping translate kepler.gl! This guide explains how to add a new language or update existing translations.
4+
5+
## Current Languages
6+
7+
| Code | Language | File |
8+
|------|----------|------|
9+
| `en` | English | `src/translations/en.ts` |
10+
| `fi` | Suomi (Finnish) | `src/translations/fi.ts` |
11+
| `pt` | Português (Portuguese) | `src/translations/pt.ts` |
12+
| `es` | Español (Spanish) | `src/translations/es.ts` |
13+
| `ca` | Català (Catalan) | `src/translations/ca.ts` |
14+
| `ja` | 日本語 (Japanese) | `src/translations/ja.ts` |
15+
| `cn` | 简体中文 (Simplified Chinese) | `src/translations/cn.ts` |
16+
| `ru` | Русский (Russian) | `src/translations/ru.ts` |
17+
18+
## Adding a New Language
19+
20+
### 1. Create the translation file
21+
22+
Copy `src/translations/en.ts` to `src/translations/<code>.ts` (use the [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) two-letter code):
23+
24+
```bash
25+
cp src/translations/en.ts src/translations/de.ts
26+
```
27+
28+
### 2. Translate all strings
29+
30+
Edit your new file and translate every string value. Keep the keys unchanged:
31+
32+
```typescript
33+
// src/translations/de.ts
34+
import {LOCALES} from '../locales';
35+
36+
export default {
37+
property: {
38+
weight: 'Gewicht',
39+
label: 'Beschriftung',
40+
fillColor: 'Füllfarbe',
41+
// ... translate all entries
42+
},
43+
// ...
44+
};
45+
```
46+
47+
**Tips:**
48+
- Use `src/translations/en.ts` as the reference for all keys
49+
- Keep placeholders like `{mapboxToken}` and `{errorMessage}` unchanged
50+
- Preserve HTML entities and formatting strings
51+
- For keys you're unsure about, leave the English text and add a `// TODO: translate` comment
52+
53+
### 3. Register the language
54+
55+
**a.** Add the locale to `src/locales.ts`:
56+
57+
```typescript
58+
export const LOCALES = {
59+
en: 'English',
60+
// ... existing locales
61+
de: 'Deutsch' // <-- add your language
62+
};
63+
```
64+
65+
**b.** Import and add the translation in `src/messages.ts`:
66+
67+
```typescript
68+
import de from './translations/de'; // <-- add import
69+
70+
export const messages = {
71+
// ... existing entries
72+
de: flattenMessages(de) // <-- add entry
73+
};
74+
```
75+
76+
### 4. Test your translation
77+
78+
Set the locale in a kepler.gl instance:
79+
80+
```javascript
81+
import {LOCALE_CODES} from '@kepler.gl/localization';
82+
83+
const customizedKeplerGlReducer = keplerGlReducer
84+
.initialState({
85+
uiState: {
86+
locale: LOCALE_CODES.de
87+
}
88+
});
89+
```
90+
91+
Or switch languages at runtime using the locale panel in the map controls (globe icon).
92+
93+
## Updating Existing Translations
94+
95+
When new English strings are added, other translation files may fall behind. To find missing translations:
96+
97+
1. Compare your translation file against `en.ts` to identify missing keys
98+
2. Search for `// TODO` comments in existing translation files
99+
3. Check for keys that still have English values in non-English files
100+
101+
## Translation Structure
102+
103+
Translations use a nested object structure that gets flattened by `flattenMessages()`:
104+
105+
```typescript
106+
{
107+
property: {
108+
weight: 'weight', // becomes 'property.weight'
109+
label: 'label' // becomes 'property.label'
110+
},
111+
toolbar: {
112+
exportImage: 'Export Image' // becomes 'toolbar.exportImage'
113+
}
114+
}
115+
```
116+
117+
In components, strings are referenced via `<FormattedMessage id="property.weight" />` or the `intl.formatMessage()` API.
118+
119+
## Questions?
120+
121+
Open an issue on [GitHub](https://github.com/keplergl/kepler.gl/issues) with the `localization` label.

0 commit comments

Comments
 (0)