Skip to content

Commit 5c8bac1

Browse files
committed
add huld docs
1 parent 5a477f3 commit 5c8bac1

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Localization / Translations (HULD)
2+
3+
Hercules servers are able to provide some sort of multi-language thanks to a feature
4+
called Hercules Ultimate Localization Design (HULD for short).
5+
6+
7+
## How it works
8+
9+
Translations are stored in PO files, a standard format for translations. Those files
10+
are stored in Hercules and follow a structure that imitates the NPC folder (plus
11+
a few other files).
12+
13+
During startup, Hercules loads those files as additional languages and whenever
14+
a NPC message is displayed, the player's current language is used.
15+
16+
A default language is set in the configs, and additional languages may be selected
17+
by each player by using the `@lang` command.
18+
19+
20+
## Generating translation files
21+
22+
In order to start translating the NPCs and other translatable messages, you must
23+
first generate the translation files.
24+
25+
To do that:
26+
27+
1. Build your server, including HPM Hook plugins
28+
2. Build the `generate-translations.c` plugin (see [HPM](./hercules-plugin-manager.md))
29+
3. Run `./map-server --load-plugin HPMHooking --load-plugin generate-translations --generate-translations` this will:
30+
1. Start map-server with "HPM Hooking" and "generate-translations" plugins loaded
31+
2. Ask map-server to actually generate the translation files
32+
4. Once it complete, map-server will automatically shut down, this is expected.
33+
5. You can now see a folder called `generated_translations` in your repository root
34+
6. This folder contains everything you need to translate, see [Adding a language](#adding-a-language)
35+
36+
37+
## Adding a language
38+
39+
Once you have the translation files folder (either downloaded from somewhere or generated with [Generating translations](#generating-translation-files)),
40+
you need to add the folder path to `db/translations.conf`.
41+
42+
For example, if you have the `Spanish` language files at `db/Spanish/`, your
43+
`db/translations.conf` should look like this:
44+
45+
```
46+
translations: (
47+
"db/Spanish",
48+
)
49+
```
50+
51+
From now on, `@lang Spanish` will give a player the Spanish translation.
52+
53+
54+
## Default language
55+
56+
The server's default language is defined in `conf/map/map-server.conf`:
57+
58+
```
59+
// When employing more than one language (see db/translations.conf),
60+
// this setting is used as a fallback
61+
default_language: "English"
62+
```
63+
64+
Following the example above, you could change the value here to `Spanish` for players
65+
to start their characters having the Spanish translation. (They could switch later on)
66+
67+
68+
## Translatable strings
69+
70+
By default, Hercules will pick every string used in `mes`, `mesf` and `select` commands,
71+
but you can explicitily tell Hercules that strings in other parts of your script
72+
must also be translated by using the `_()` macro.
73+
74+
For example:
75+
76+
```HercScript
77+
.@status1$ = "Closed"; // This won't be translated
78+
.@status2$ = _("Available"); // This will be translated
79+
```
80+
81+
82+
## Caveats
83+
84+
### Global messages
85+
86+
Messages sent to many players at once, like broadcasts will use the attached player
87+
language.
88+
89+
This is for performance reasons, since sending messages in each player language
90+
would require building separate packets/messages for each player (or group of players).
91+
92+
93+
### "Unattached" messages
94+
95+
When a message is sent by a script that doesn't have a player attached,
96+
the message will be sent in the server's default language.
97+
98+
This is for performance reasons, since sending messages in the default language
99+
would require building separate packets/messages for each player (or group of players).
100+
Additionally, since no player is attached, there is no player language to use.
101+
102+
```HercScript
103+
prontera,150,150,0 script test huld 4_F_SISTER,{
104+
mes("Text with player attached. In player language");
105+
announce(_("Text in player language for everyone."), bc_all);
106+
initnpctimer();
107+
close();
108+
109+
OnTimer1500:
110+
// Player is not attached here.
111+
npctalk("Hi, i'm talking in server default language.");
112+
end;
113+
}
114+
115+
```
116+
117+
118+
### Player gender
119+
120+
There is no way to have variation by player gender for the same message.
121+
122+
One strategy to work around that is to include a space at the end of the message
123+
for one of the genders, for example:
124+
125+
```HercScript
126+
if (Sex == SEX_MALE) {
127+
mes("Hello");
128+
} else {
129+
mes("Hello ");
130+
}
131+
132+
```
133+
134+
This would generate 2 messages for translation.

0 commit comments

Comments
 (0)