feat(text): the race menu reads its texts from translation files
First step of moving every piece of text out of the code so modders can translate the mod. The texts live in Translations/<Language>/*.json, one file per kind of text, which Jotunn finds on its own and falls back to English for. ModText reads them; values take Valheim's $1, $2 placeholders. This step covers the race selection menu: title, buttons, every race's name and description, in English and Italian. The race ID and the name on screen are now separate strings. The ID is what the save and the ZDO hold, so it must never be translated. The files are deployed to plugins\RacesOfValheim\Translations and packed into both release zips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a835a58003
commit
73b67cd6ce
5 changed files with 169 additions and 22 deletions
50
JotunnModStub/ModText.cs
Normal file
50
JotunnModStub/ModText.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
using System.Linq;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// Every piece of text the mod shows, read from the translation files instead of the code.
|
||||
///
|
||||
/// The files are JSON under Translations/<Language>/, one per kind of text, next to the DLL.
|
||||
/// Jotunn finds them on its own: it searches the whole plugins folder for any .json whose
|
||||
/// grandparent folder is called "Translations", takes the language from the folder name
|
||||
/// (Valheim's own names: English, Italian, German...), and falls back to English for any key a
|
||||
/// language leaves out. A key missing from English too shows up on screen as [key].
|
||||
///
|
||||
/// Keys go in the files without the leading $ and are read here the same way. Values take
|
||||
/// Valheim's own placeholders, $1, $2..., filled from the arguments in order, so a translator
|
||||
/// can move a number to wherever their grammar wants it.
|
||||
/// </summary>
|
||||
internal static class ModText
|
||||
{
|
||||
public static string Get(string key, params object[] args)
|
||||
{
|
||||
if (Localization.instance == null) return "[" + key + "]";
|
||||
|
||||
string[] words = args.Select(a => a?.ToString() ?? "").ToArray();
|
||||
return Localization.instance.Localize("$" + key, words);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A race's name as the player reads it. Only ever for display.
|
||||
///
|
||||
/// The race ID ("Skadi", "Trol"...) is a different thing and never goes through here: it is
|
||||
/// written into the character save and the ZDO, and compared all over the code. Translate
|
||||
/// that and a character saved under one language stops being recognised under another.
|
||||
/// </summary>
|
||||
public static string RaceName(string raceId)
|
||||
{
|
||||
return Get(RaceKey(raceId) + "_name");
|
||||
}
|
||||
|
||||
public static string RaceDescription(string raceId, params object[] args)
|
||||
{
|
||||
return Get(RaceKey(raceId) + "_desc", args);
|
||||
}
|
||||
|
||||
private static string RaceKey(string raceId)
|
||||
{
|
||||
return "rov_race_" + raceId.ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue