Translate mod text: Difference between revisions
More actions
Bonsaibauer (talk | contribs) Create en-GB source page for translation |
Bonsaibauer (talk | contribs) Marked this version for translation |
||
| Line 15: | Line 15: | ||
<translate> | <translate> | ||
<!--T:1--> | |||
Translate visible Modloader text and Lua text from the same locale files in the mod folder. Read the Modloader language through <code>shroudforge.locale()</code>, added by PR #42. | Translate visible Modloader text and Lua text from the same locale files in the mod folder. Read the Modloader language through <code>shroudforge.locale()</code>, added by PR #42. | ||
== Locale files == | == Locale files == <!--T:2--> | ||
<!--T:3--> | |||
Add one file under <code>locales/<code>.json</code> for each language. Current codes from the Modloader language selector are <code>de</code>, <code>de-AT</code>, <code>de-CH</code>, <code>en-GB</code>, <code>en-US</code>, <code>es</code>, <code>fr</code>, <code>hi</code>, <code>it</code>, <code>ja</code>, <code>nl</code>, <code>pl</code>, <code>sv</code>, and <code>zh</code>. The filename matches its code exactly. These files sit beside <code>mod.json</code> and <code>extended.mod.json</code>. | Add one file under <code>locales/<code>.json</code> for each language. Current codes from the Modloader language selector are <code>de</code>, <code>de-AT</code>, <code>de-CH</code>, <code>en-GB</code>, <code>en-US</code>, <code>es</code>, <code>fr</code>, <code>hi</code>, <code>it</code>, <code>ja</code>, <code>nl</code>, <code>pl</code>, <code>sv</code>, and <code>zh</code>. The filename matches its code exactly. These files sit beside <code>mod.json</code> and <code>extended.mod.json</code>. | ||
<!--T:4--> | |||
The schema is published as [https://bonsaibauer.github.io/shroudforge/schemas/mod-locale.schema.json <code>mod-locale.schema.json</code>]. A locale catalog can translate <code>mod.name</code> and <code>mod.description</code>, setting and option labels, groups, actions, changelog lines, and Lua <code>strings</code>. Catalogs may be partial. Entries without a translation keep their source text. | The schema is published as [https://bonsaibauer.github.io/shroudforge/schemas/mod-locale.schema.json <code>mod-locale.schema.json</code>]. A locale catalog can translate <code>mod.name</code> and <code>mod.description</code>, setting and option labels, groups, actions, changelog lines, and Lua <code>strings</code>. Catalogs may be partial. Entries without a translation keep their source text. | ||
<!--T:5--> | |||
<pre> | <pre> | ||
{ | { | ||
| Line 39: | Line 43: | ||
</pre> | </pre> | ||
<!--T:6--> | |||
Setting and option keys stay the same as in <code>extended.mod.json</code>. Group translations follow that file's group order. Action translations use the existing action ID. Saved values do not change. | Setting and option keys stay the same as in <code>extended.mod.json</code>. Group translations follow that file's group order. Action translations use the existing action ID. Saved values do not change. | ||
== Use the same text in Lua == | == Use the same text in Lua == <!--T:7--> | ||
<!--T:8--> | |||
<pre> | <pre> | ||
local locale = shroudforge.locale() | local locale = shroudforge.locale() | ||
| Line 48: | Line 54: | ||
</pre> | </pre> | ||
<!--T:9--> | |||
<code>shroudforge.i18n.get(key, locale, fallback)</code> uses the same loaded catalog as the Modloader. It checks a regional code such as <code>de-AT</code> first, followed by its language <code>de</code>. A missing string returns the fallback text, or the key when no fallback is provided. The lookup does not read files again. PR #42 supplies the language API, and this feature connects it to each mod's catalog. | <code>shroudforge.i18n.get(key, locale, fallback)</code> uses the same loaded catalog as the Modloader. It checks a regional code such as <code>de-AT</code> first, followed by its language <code>de</code>. A missing string returns the fallback text, or the key when no fallback is provided. The lookup does not read files again. PR #42 supplies the language API, and this feature connects it to each mod's catalog. | ||
<!--T:10--> | |||
If <code>shroudforge.locale()</code> returns <code>en</code> because the configuration cannot be read, catalog lookup checks <code>en-GB.json</code> first and then <code>en.json</code>. <code>en-GB</code> is the Modloader's English default. <code>en-US</code> remains available as an explicitly selected variant. | If <code>shroudforge.locale()</code> returns <code>en</code> because the configuration cannot be read, catalog lookup checks <code>en-GB.json</code> first and then <code>en.json</code>. <code>en-GB</code> is the Modloader's English default. <code>en-US</code> remains available as an explicitly selected variant. | ||
<!--T:11--> | |||
Locale files do not require the runtime capability. ShroudForge interface text stays in the shared Modloader translations. | Locale files do not require the runtime capability. ShroudForge interface text stays in the shared Modloader translations. | ||
Latest revision as of 21:38, 6 November 2026
Translate visible Modloader text and Lua text from the same locale files in the mod folder. Read the Modloader language through shroudforge.locale(), added by PR #42.
Locale files
Add one file under locales/<code>.json for each language. Current codes from the Modloader language selector are de, de-AT, de-CH, en-GB, en-US, es, fr, hi, it, ja, nl, pl, sv, and zh. The filename matches its code exactly. These files sit beside mod.json and extended.mod.json.
The schema is published as mod-locale.schema.json. A locale catalog can translate mod.name and mod.description, setting and option labels, groups, actions, changelog lines, and Lua strings. Catalogs may be partial. Entries without a translation keep their source text.
{
"$schema": "https://bonsaibauer.github.io/shroudforge/schemas/mod-locale.schema.json",
"settings": {
"severity": {
"label": "Log level",
"options": { "info": "Information", "warn": "Warning" }
}
},
"groups": [
{ "label": "Logging", "actions": { "write": { "label": "Write message" } } }
],
"strings": { "overlay.ready": "Ready" }
}
Setting and option keys stay the same as in extended.mod.json. Group translations follow that file's group order. Action translations use the existing action ID. Saved values do not change.
Use the same text in Lua
local locale = shroudforge.locale()
local ready = shroudforge.i18n.get("overlay.ready", locale, "Ready")
shroudforge.i18n.get(key, locale, fallback) uses the same loaded catalog as the Modloader. It checks a regional code such as de-AT first, followed by its language de. A missing string returns the fallback text, or the key when no fallback is provided. The lookup does not read files again. PR #42 supplies the language API, and this feature connects it to each mod's catalog.
If shroudforge.locale() returns en because the configuration cannot be read, catalog lookup checks en-GB.json first and then en.json. en-GB is the Modloader's English default. en-US remains available as an explicitly selected variant.
Locale files do not require the runtime capability. ShroudForge interface text stays in the shared Modloader translations.