1
1
# Localization Documentation
2
2
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:
5
4
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!
7
48
8
49
``` yaml
9
50
name : Agents of Decay
@@ -23,18 +64,74 @@ unique_effects:
23
64
icon : /assets/icons/abilities/AgarusLegendaryWeaponAbility.png
24
65
description : |
25
66
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:
26
75
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.
27
118
i18n :
28
119
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
33
124
ja :
34
- name : 新しいアイテム
125
+ name : Japanese Name
126
+ description : Japanese Description
127
+ unique_effect :
128
+ - description : Japanese Unique Effect Description
35
129
` ` `
36
130
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
38
135
39
136
You might notice that this is kinda terrible if the entry contains data like for instance this example :
40
137
@@ -43,12 +140,10 @@ unique_effects:
43
140
- name: CharrogSpentStaminaFireDamage
44
141
description: >-
45
142
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
47
143
powerSurged: false
48
144
- name: CharrogSpentStaminaFireDamage
49
145
description: >-
50
146
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
52
147
powerSurged: true
53
148
` ` `
54
149
@@ -62,16 +157,100 @@ unique_effects:
62
157
- name: CharrogSpentStaminaFireDamage
63
158
description: &charrogUeDescription >-
64
159
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
66
160
powerSurged: false
67
161
values:
68
162
stamina: 150
69
163
blazeDamage: 100
70
164
- name: CharrogSpentStaminaFireDamage
71
165
description: *charrogUeDescription
72
- value : 200
73
166
powerSurged: true
74
167
values:
75
168
stamina: 150
76
169
blazeDamage: 200
77
170
` ` `
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".
0 commit comments