Skip to content
This repository was archived by the owner on Dec 20, 2024. It is now read-only.

Commit 8311ce4

Browse files
committed
add better localization documentation
1 parent 7e8c875 commit 8311ce4

File tree

2 files changed

+193
-14
lines changed

2 files changed

+193
-14
lines changed

docs/LOCALIZATION.md

Lines changed: 192 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,50 @@
11
# Localization Documentation
22

3-
If you want to translate Dauntless Builder into a new language (or fix a language string) check out src/i18n.ts and
4-
src/translations.
3+
Localization in Dauntless Builder is essentially split into two parts:
54

6-
In order to create a translation for an item, edit its yaml file like this:
5+
- App Localization - Strings on the website itself
6+
- Item Data Localization - Item name, description, effects etc.
7+
8+
and is powered by [i18next](https://www.i18next.com/).
9+
10+
The English localization is the source of all truths and is used as a fallback if the current user localization
11+
does not contain an entry.
12+
13+
## App Localization
14+
15+
These localization entries are handled by one big JSON file per language and can be found in `src/translations`.
16+
17+
Here is an outtake of the English language file `src/translations/en.json`:
18+
19+
```json
20+
{
21+
// ...
22+
"app-name": "Dauntless Builder",
23+
// ...
24+
"components": {
25+
"build-menu": {
26+
"added-build-to-favorites": "Added build \"{{name}}\" to favorites."
27+
// ...
28+
}
29+
}
30+
// ...
31+
}
32+
```
33+
34+
Every entry is generally made up of two parts, an identifier (for instance **app-name**) and the associated translation
35+
(in this case **Dauntless Builder**). Identifiers can be split up into sub objects and are referenced in by using a dot
36+
as a separator (components.build-menu.added-build-to-favorites).
37+
38+
Generally if you want to translate something into another language you'd go into the language file of your language, for
39+
instance French would be `src/translations/fr.json` copy over the identifier and add a different translation.
40+
41+
The translation part can also contain variables which are referenced by surrounding them with two curly braces (see {{name}}).
42+
43+
## Item Data Localization
44+
45+
These localization entries are contained within the item data entries.
46+
47+
Lets translate an item!
748

849
```yaml
950
name: Agents of Decay
@@ -23,18 +64,74 @@ unique_effects:
2364
icon: /assets/icons/abilities/AgarusLegendaryWeaponAbility.png
2465
description: |
2566
Legendary Ability: Revive all Slayers in a large radius, granting them healing over time and immunity to stagger. Usable while downed.
67+
```
68+
69+
as you can (maybe) see this item does not feature any translations (yet) by the fact that the **i18n** item is missing.
70+
71+
There are three values here that need to be translated **name**, **description** and the **unique_effect description**.
72+
Everything else is just data.
73+
74+
Lets start by adding the i18n object with a name set for German:
2675
76+
```yaml
77+
# ...
78+
i18n:
79+
de:
80+
name: German Name
81+
```
82+
83+
The first level below **i18n** is reserved for language identifiers (see src/i18n.ts for more information) and right below
84+
that we have the identifier we want to overwrite for said language.
85+
86+
Let's add the other entries:
87+
88+
```yaml
89+
# ...
90+
i18n:
91+
de:
92+
name: German Name
93+
description: German Description
94+
unique_effect:
95+
- description: German Unique Effect Description
96+
```
97+
98+
similarly we can add as many language as we want, which would make the finished entry look like something like this:
99+
100+
```yaml
101+
name: Agents of Decay
102+
description: A Slayer's aether strikers forged with Agarus trophies.
103+
icon: /assets/icons/weapons/agarus/AgentsOfDecay.png
104+
type: Aether Strikers
105+
damage: Blunt
106+
elemental: Terra
107+
cells: [Prismatic, Prismatic]
108+
power:
109+
base: 100
110+
powerSurged: 120
111+
bond:
112+
elemental: Terra
113+
unique_effects:
114+
- name: AgarusLegendaryAbility
115+
icon: /assets/icons/abilities/AgarusLegendaryWeaponAbility.png
116+
description: |
117+
Legendary Ability: Revive all Slayers in a large radius, granting them healing over time and immunity to stagger. Usable while downed.
27118
i18n:
28119
de:
29-
name: New item name in German
30-
description: New description that has been overwritten!
31-
unique_effects:
32-
- description: SCHMETTERLING!
120+
name: German Name
121+
description: German Description
122+
unique_effect:
123+
- description: German Unique Effect Description
33124
ja:
34-
name: 新しいアイテム
125+
name: Japanese Name
126+
description: Japanese Description
127+
unique_effect:
128+
- description: Japanese Unique Effect Description
35129
```
36130
37-
This will create new translation entries in src/translations/items.
131+
Keep in mind to see the changes in the frontend you need to generate translation files
132+
(which will be later located in src/translations/items) using the `yarn build:i18n` command.
133+
134+
### Using variables in translation entries
38135

39136
You might notice that this is kinda terrible if the entry contains data like for instance this example:
40137

@@ -43,12 +140,10 @@ unique_effects:
43140
- name: CharrogSpentStaminaFireDamage
44141
description: >-
45142
After spending 150 stamina, next attack emits a cone of flame that deals +100 blaze damage to each unique target within the cone
46-
value: 100
47143
powerSurged: false
48144
- name: CharrogSpentStaminaFireDamage
49145
description: >-
50146
After spending 150 stamina, next attack emits a cone of flame that deals +200 blaze damage to each unique target within the cone
51-
value: 200
52147
powerSurged: true
53148
```
54149

@@ -62,16 +157,100 @@ unique_effects:
62157
- name: CharrogSpentStaminaFireDamage
63158
description: &charrogUeDescription >-
64159
After spending {{stamina}} stamina, next attack emits a cone of flame that deals +{{blazeDamage}} blaze damage to each unique target within the cone
65-
value: 100
66160
powerSurged: false
67161
values:
68162
stamina: 150
69163
blazeDamage: 100
70164
- name: CharrogSpentStaminaFireDamage
71165
description: *charrogUeDescription
72-
value: 200
73166
powerSurged: true
74167
values:
75168
stamina: 150
76169
blazeDamage: 200
77170
```
171+
172+
## Adding a new language
173+
174+
You read what is written above this and want to start contributing but notice your language is missing?
175+
176+
Adding a new language is fairly easy!
177+
178+
Lets say we're adding support for Sindarin (for sake of the example we'll use **si** as the language code).
179+
180+
First lets start by creating the file `src/translations/si.json`
181+
182+
```json
183+
{
184+
"app-name": "Dauntless tamo"
185+
}
186+
```
187+
188+
(Hint: https://www.elfdict.com/wt/508140)
189+
190+
Next we'll head into `src/i18n.ts` (note the comments):
191+
192+
```ts
193+
import de from "./translations/de.json";
194+
import en from "./translations/en.json";
195+
import fr from "./translations/fr.json";
196+
import enItems from "./translations/items/items.en.json";
197+
// ...
198+
199+
// First lets head to the import block for localizations and add our new file
200+
import si from "./translations/si.json";
201+
202+
// next lets head to the resources object and add our language here as well
203+
const resources = {
204+
// since we don't have item translations yet we'll only add the app localizations for now
205+
si: { translation: si },
206+
en: { translation: { ...en, ...enItems } },
207+
fr: { translation: { ...fr, ...frItems } },
208+
ja: { translation: { ...ja, ...jaItems } },
209+
};
210+
211+
// next lets add our language to the Language enum with the language code as a value:
212+
export enum Language {
213+
English = "en",
214+
German = "de",
215+
Japanese = "ja",
216+
French = "fr",
217+
218+
// This
219+
Sindarin = "si",
220+
}
221+
222+
// next we'll add a language native name here aka what the language is named when referenced by natives
223+
const nativeLanguageNames = {
224+
[Language.English]: "English",
225+
[Language.German]: "Deutsch",
226+
[Language.Japanese]: "日本語",
227+
[Language.French]: "Français",
228+
// see here:
229+
[Language.Sindarin]: "Edhellen",
230+
};
231+
232+
// since we just added this language, we should add it to the beta languages list which will warn the user
233+
// that the localization for this language is incomplete.
234+
const betaLanguages = [
235+
Language.German,
236+
Language.Japanese,
237+
Language.French,
238+
// here!
239+
Language.Sindarin,
240+
];
241+
242+
// next we'll add our language to the muiLocaleComponent, sadly Sindarin is not (yet) supported by Material UI, maybe you
243+
// should create an issue there?
244+
export const muiLocaleComponent = () =>
245+
match(i18n.languages[0])
246+
.with(Language.English, () => enUS)
247+
.with(Language.German, () => deDE)
248+
.with(Language.Japanese, () => jaJP)
249+
.with(Language.French, () => frFR)
250+
// would be here if it would exist :(
251+
.with(Language.Sindarin, () => siSi) // keep in mind that siSi in this case is an import from material ui
252+
.otherwise(() => enUS);
253+
```
254+
255+
And is all you need to do. Now you should be able to select Sindarin in the settings and the title should be
256+
replaced with "Dauntless tamo".

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ export const githubUrl = "https://github.com/atomicptr/dauntless-builder";
33
export const matrixChannelUrl = "https://matrix.to/#/#dauntlessbuilder:matrix.org";
44
export const discordServerUrl = "https://discord.gg/hkMvhsfPjH";
55
export const translationDocumentationUrl =
6-
"https://github.com/atomicptr/dauntless-builder/blob/master/docs/contributing/TRANSLATION.md";
6+
"https://github.com/atomicptr/dauntless-builder/blob/master/docs/LOCALIZATION.md";
77
export const licenseUrl = "https://github.com/atomicptr/dauntless-builder/blob/master/LICENSE";

0 commit comments

Comments
 (0)