Merge branch 'feat/translations-races'
This commit is contained in:
commit
c055455027
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -303,7 +303,7 @@ namespace RacesOfValheim
|
|||
titleObj.transform.SetParent(selectionPanel.transform, false);
|
||||
Text titleText = titleObj.AddComponent<Text>();
|
||||
titleText.font = GUIManager.Instance.AveriaSerifBold;
|
||||
titleText.text = "Choose your Race";
|
||||
titleText.text = ModText.Get("rov_menu_choose_race");
|
||||
titleText.fontSize = 50;
|
||||
titleText.alignment = TextAnchor.MiddleCenter;
|
||||
titleText.color = Color.white;
|
||||
|
|
@ -346,7 +346,7 @@ namespace RacesOfValheim
|
|||
btnOkTxtObj.transform.SetParent(btnOkObj.transform, false);
|
||||
Text btnOkTxt = btnOkTxtObj.AddComponent<Text>();
|
||||
btnOkTxt.font = GUIManager.Instance.AveriaSerifBold;
|
||||
btnOkTxt.text = "OK";
|
||||
btnOkTxt.text = ModText.Get("rov_menu_ok");
|
||||
btnOkTxt.fontSize = 24;
|
||||
btnOkTxt.alignment = TextAnchor.MiddleCenter;
|
||||
btnOkTxt.color = Color.white;
|
||||
|
|
@ -371,7 +371,7 @@ namespace RacesOfValheim
|
|||
btnBackTxtObj.transform.SetParent(btnBackObj.transform, false);
|
||||
Text btnBackTxt = btnBackTxtObj.AddComponent<Text>();
|
||||
btnBackTxt.font = GUIManager.Instance.AveriaSerifBold;
|
||||
btnBackTxt.text = "Back";
|
||||
btnBackTxt.text = ModText.Get("rov_menu_back");
|
||||
btnBackTxt.fontSize = 24;
|
||||
btnBackTxt.alignment = TextAnchor.MiddleCenter;
|
||||
btnBackTxt.color = Color.white;
|
||||
|
|
@ -379,34 +379,40 @@ namespace RacesOfValheim
|
|||
btnBackTxtRect.anchorMin = Vector2.zero; btnBackTxtRect.anchorMax = Vector2.one;
|
||||
btnBackTxtRect.offsetMin = Vector2.zero; btnBackTxtRect.offsetMax = Vector2.zero;
|
||||
|
||||
void CreateRaceButtonWithConfirm(string label, Vector2 position, Sprite iconSprite, string description, UnityEngine.Events.UnityAction onConfirm)
|
||||
// The race ID picks the texts and is what gets saved; the button, the title and the
|
||||
// description only ever show the translated name. See ModText.RaceName for why the two
|
||||
// must never be the same string.
|
||||
void CreateRaceButtonWithConfirm(string raceId, Vector2 position, Sprite iconSprite, UnityEngine.Events.UnityAction onConfirm, params object[] descArgs)
|
||||
{
|
||||
CreateRaceButton(label, position, iconSprite, selectionPanel.transform, () => {
|
||||
string name = ModText.RaceName(raceId);
|
||||
CreateRaceButton(raceId, name, position, iconSprite, selectionPanel.transform, () => {
|
||||
selectionPanel.SetActive(false);
|
||||
confirmationPanel.SetActive(true);
|
||||
confTitleText.text = label;
|
||||
confDescText.text = description;
|
||||
confTitleText.text = name;
|
||||
confDescText.text = ModText.RaceDescription(raceId, descArgs);
|
||||
btnOk.onClick.RemoveAllListeners();
|
||||
btnOk.onClick.AddListener(onConfirm);
|
||||
});
|
||||
}
|
||||
|
||||
// Row 1 (y = 100)
|
||||
CreateRaceButtonWithConfirm("Human", new Vector2(-450, 100), GetHumanIcon(), "The versatile founders of Midgard. Balanced stats with no specific weaknesses.", SelectHuman);
|
||||
CreateRaceButtonWithConfirm("Fenrir", new Vector2(-150, 100), GetFenrirIcon(), "Cursed by the blood of the wolf. Fast and deadly, but vulnerable to silver.", SelectFenrir);
|
||||
CreateRaceButtonWithConfirm("Skadi", new Vector2(150, 100), GetSkadiIcon(), "Children of the mountains. Resistant to frost, at home in the freezing cold.", SelectSkadi);
|
||||
CreateRaceButtonWithConfirm("Skeleton", new Vector2(450, 100), GetSkeletonIcon(), "Undead warriors. Immune to poison, but brittle against blunt trauma.", SelectSkeleton);
|
||||
|
||||
CreateRaceButtonWithConfirm("Human", new Vector2(-450, 100), GetHumanIcon(), SelectHuman);
|
||||
CreateRaceButtonWithConfirm("Fenrir", new Vector2(-150, 100), GetFenrirIcon(), SelectFenrir);
|
||||
CreateRaceButtonWithConfirm("Skadi", new Vector2(150, 100), GetSkadiIcon(), SelectSkadi);
|
||||
CreateRaceButtonWithConfirm(SkeletonVisuals.RaceId, new Vector2(450, 100), GetSkeletonIcon(), SelectSkeleton);
|
||||
|
||||
// Row 2 (y = -20)
|
||||
CreateRaceButtonWithConfirm("Aswid", new Vector2(-450, -20), GetAswidIcon(), "Fierce night stalker. Strong and resilient, transforms into a bat.", SelectAswid);
|
||||
CreateRaceButtonWithConfirm("Furling", new Vector2(-150, -20), GetFurlingIcon(), "Cunning goblin-like creatures. Agile and resourceful.", SelectFurling);
|
||||
CreateRaceButtonWithConfirm("Trol", new Vector2(150, -20), GetTrolIcon(), $"Massive brute strength. Towering over others, at peace with the Black Forest - but fire burns a Trol {(TrolConfig.FireWeaknessMultiplier.Value - 1f) * 100f:0}% harder than anyone else.", SelectTrol);
|
||||
CreateRaceButtonWithConfirm("Draugh", new Vector2(450, -20), GetDraughIcon(), "A decaying undead warrior fueled by dark magic and extreme metal.", SelectDraugh);
|
||||
CreateRaceButtonWithConfirm("Aswid", new Vector2(-450, -20), GetAswidIcon(), SelectAswid);
|
||||
CreateRaceButtonWithConfirm("Furling", new Vector2(-150, -20), GetFurlingIcon(), SelectFurling);
|
||||
// $1 in the Trol's description is how much harder fire burns it, read from the config.
|
||||
CreateRaceButtonWithConfirm("Trol", new Vector2(150, -20), GetTrolIcon(), SelectTrol,
|
||||
((TrolConfig.FireWeaknessMultiplier.Value - 1f) * 100f).ToString("0"));
|
||||
CreateRaceButtonWithConfirm(DraughVisuals.RaceId, new Vector2(450, -20), GetDraughIcon(), SelectDraugh);
|
||||
|
||||
// Row 3 (y = -140)
|
||||
CreateRaceButtonWithConfirm("Dvergar", new Vector2(-450, -140), GetDvergarIcon(), "Small, stubborn smiths of the deep. Frail of frame, but masters of metal, mine and market.", SelectDvergar);
|
||||
CreateRaceButtonWithConfirm("Trenta", new Vector2(-150, -140), GetTrentaIcon(), "Tree-born folk, kin to root and leaf. Patient and hard to fell.", SelectTrenta);
|
||||
CreateRaceButtonWithConfirm("Sverm", new Vector2(150, -140), GetSvermIcon(), "Chitin-born swarm kin. Armoured from birth and never slowed, venomous, at peace with every crawling thing - but blunt trauma and fire find the seams.", SelectSverm);
|
||||
CreateRaceButtonWithConfirm(DvergarConfig.RaceId, new Vector2(-450, -140), GetDvergarIcon(), SelectDvergar);
|
||||
CreateRaceButtonWithConfirm(TrentaConfig.RaceId, new Vector2(-150, -140), GetTrentaIcon(), SelectTrenta);
|
||||
CreateRaceButtonWithConfirm(SvermConfig.RaceId, new Vector2(150, -140), GetSvermIcon(), SelectSverm);
|
||||
|
||||
GUIManager.BlockInput(true);
|
||||
}
|
||||
|
|
@ -481,9 +487,9 @@ namespace RacesOfValheim
|
|||
return null;
|
||||
}
|
||||
|
||||
private void CreateRaceButton(string label, Vector2 position, Sprite iconSprite, Transform parentTransform, UnityEngine.Events.UnityAction onClick)
|
||||
private void CreateRaceButton(string raceId, string label, Vector2 position, Sprite iconSprite, Transform parentTransform, UnityEngine.Events.UnityAction onClick)
|
||||
{
|
||||
GameObject btnObj = new GameObject(label + "Button");
|
||||
GameObject btnObj = new GameObject(raceId + "Button");
|
||||
btnObj.transform.SetParent(parentTransform, false);
|
||||
RectTransform btnRect = btnObj.AddComponent<RectTransform>();
|
||||
btnRect.sizeDelta = new Vector2(250, 80);
|
||||
|
|
|
|||
|
|
@ -138,18 +138,33 @@
|
|||
<Warning Text="BepInEx plugins folder not found at $(PLUGINS_PATH) - the DLL was built but not deployed." Condition="!Exists('$(PLUGINS_PATH)')" />
|
||||
<Message Text="Deploying $(TargetName).dll to $(PLUGINS_PATH)" Importance="high" Condition="Exists('$(PLUGINS_PATH)')" />
|
||||
<Copy SourceFiles="$(TargetDir)$(TargetName).dll" DestinationFolder="$(PLUGINS_PATH)\" Condition="Exists('$(PLUGINS_PATH)')" />
|
||||
<!-- The texts. Jotunn finds any Translations\<Language>\*.json anywhere under plugins, so
|
||||
they go in a folder of the mod's own rather than a bare plugins\Translations another mod
|
||||
could be writing into too. -->
|
||||
<Copy SourceFiles="@(TranslationFile)" DestinationFiles="@(TranslationFile->'$(PLUGINS_PATH)\RacesOfValheim\Translations\%(RecursiveDir)%(Filename)%(Extension)')" Condition="Exists('$(PLUGINS_PATH)')" />
|
||||
</Target>
|
||||
|
||||
<ItemGroup>
|
||||
<TranslationFile Include="$(ProjectDir)Translations\**\*.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PackageThunderstore" AfterTargets="Build" Condition="'$(Configuration)'=='Release'">
|
||||
<PropertyGroup>
|
||||
<PackageOutputDir>$(REPO_ROOT)dist\</PackageOutputDir>
|
||||
</PropertyGroup>
|
||||
<MakeDir Directories="$(PackageOutputDir)" Condition="!Exists('$(PackageOutputDir)')" />
|
||||
<!-- Nexus users unzip straight into plugins, so the texts travel inside a RacesOfValheim
|
||||
folder there; Thunderstore already gives every package a folder of its own. -->
|
||||
<PropertyGroup>
|
||||
<NexusStaging>$(IntermediateOutputPath)nexus\</NexusStaging>
|
||||
</PropertyGroup>
|
||||
<RemoveDir Directories="$(NexusStaging)" />
|
||||
<Copy SourceFiles="@(TranslationFile)" DestinationFiles="@(TranslationFile->'$(NexusStaging)RacesOfValheim\Translations\%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||
<Message Text="Packaging Thunderstore and Nexus zips into $(PackageOutputDir)" Importance="high" />
|
||||
<!-- The version is read back out of manifest.json rather than duplicated here, so
|
||||
manifest.json stays the single place a release is numbered. Written with string
|
||||
concatenation because MSBuild would eat a PowerShell $(...) subexpression. -->
|
||||
<Exec Command="powershell -NoProfile -Command "$v = (Get-Content '$(ProjectDir)..\manifest.json' -Raw | ConvertFrom-Json).version_number; Compress-Archive -Path '$(TargetDir)$(TargetName).dll', '$(ProjectDir)..\manifest.json', '$(ProjectDir)..\README.md', '$(ProjectDir)Package\icon.png' -DestinationPath ('$(PackageOutputDir)RacesOfValheim_Thunderstore_' + $v + '.zip') -Force; Compress-Archive -Path '$(TargetDir)$(TargetName).dll' -DestinationPath ('$(PackageOutputDir)RacesOfValheim_Nexus_' + $v + '.zip') -Force"" />
|
||||
<Exec Command="powershell -NoProfile -Command "$v = (Get-Content '$(ProjectDir)..\manifest.json' -Raw | ConvertFrom-Json).version_number; Compress-Archive -Path '$(TargetDir)$(TargetName).dll', '$(ProjectDir)..\manifest.json', '$(ProjectDir)..\README.md', '$(ProjectDir)Package\icon.png', '$(ProjectDir)Translations' -DestinationPath ('$(PackageOutputDir)RacesOfValheim_Thunderstore_' + $v + '.zip') -Force; Compress-Archive -Path '$(TargetDir)$(TargetName).dll', '$(NexusStaging)RacesOfValheim' -DestinationPath ('$(PackageOutputDir)RacesOfValheim_Nexus_' + $v + '.zip') -Force"" />
|
||||
</Target>
|
||||
|
||||
|
||||
|
|
|
|||
38
JotunnModStub/Translations/English/races.json
Normal file
38
JotunnModStub/Translations/English/races.json
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"rov_menu_choose_race": "Choose your Race",
|
||||
"rov_menu_ok": "OK",
|
||||
"rov_menu_back": "Back",
|
||||
|
||||
"rov_race_human_name": "Human",
|
||||
"rov_race_human_desc": "The versatile founders of Midgard. Balanced stats with no specific weaknesses.",
|
||||
|
||||
"rov_race_fenrir_name": "Fenrir",
|
||||
"rov_race_fenrir_desc": "Cursed by the blood of the wolf. Fast and deadly, but vulnerable to silver.",
|
||||
|
||||
"rov_race_skadi_name": "Skadi",
|
||||
"rov_race_skadi_desc": "Children of the mountains. Resistant to frost, at home in the freezing cold.",
|
||||
|
||||
"rov_race_skeleton_name": "Skeleton",
|
||||
"rov_race_skeleton_desc": "Undead warriors. Immune to poison, but brittle against blunt trauma.",
|
||||
|
||||
"rov_race_aswid_name": "Aswid",
|
||||
"rov_race_aswid_desc": "Fierce night stalker. Strong and resilient, transforms into a bat.",
|
||||
|
||||
"rov_race_furling_name": "Furling",
|
||||
"rov_race_furling_desc": "Cunning goblin-like creatures. Agile and resourceful.",
|
||||
|
||||
"rov_race_trol_name": "Trol",
|
||||
"rov_race_trol_desc": "Massive brute strength. Towering over others, at peace with the Black Forest - but fire burns a Trol $1% harder than anyone else.",
|
||||
|
||||
"rov_race_draugh_name": "Draugh",
|
||||
"rov_race_draugh_desc": "A decaying undead warrior fueled by dark magic and extreme metal.",
|
||||
|
||||
"rov_race_dvergar_name": "Dvergar",
|
||||
"rov_race_dvergar_desc": "Small, stubborn smiths of the deep. Frail of frame, but masters of metal, mine and market.",
|
||||
|
||||
"rov_race_trenta_name": "Trenta",
|
||||
"rov_race_trenta_desc": "Tree-born folk, kin to root and leaf. Patient and hard to fell.",
|
||||
|
||||
"rov_race_sverm_name": "Sverm",
|
||||
"rov_race_sverm_desc": "Chitin-born swarm kin. Armoured from birth and never slowed, venomous, at peace with every crawling thing - but blunt trauma and fire find the seams."
|
||||
}
|
||||
38
JotunnModStub/Translations/Italian/races.json
Normal file
38
JotunnModStub/Translations/Italian/races.json
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"rov_menu_choose_race": "Scegli la tua razza",
|
||||
"rov_menu_ok": "OK",
|
||||
"rov_menu_back": "Indietro",
|
||||
|
||||
"rov_race_human_name": "Umano",
|
||||
"rov_race_human_desc": "I versatili fondatori di Midgard. Statistiche equilibrate, senza debolezze particolari.",
|
||||
|
||||
"rov_race_fenrir_name": "Fenrir",
|
||||
"rov_race_fenrir_desc": "Maledetti dal sangue del lupo. Veloci e letali, ma vulnerabili all'argento.",
|
||||
|
||||
"rov_race_skadi_name": "Skadi",
|
||||
"rov_race_skadi_desc": "Figli delle montagne. Resistenti al gelo, a casa loro nel freddo più rigido.",
|
||||
|
||||
"rov_race_skeleton_name": "Scheletro",
|
||||
"rov_race_skeleton_desc": "Guerrieri non morti. Immuni al veleno, ma fragili contro i colpi contundenti.",
|
||||
|
||||
"rov_race_aswid_name": "Aswid",
|
||||
"rov_race_aswid_desc": "Feroce cacciatore notturno. Forte e resistente, si trasforma in pipistrello.",
|
||||
|
||||
"rov_race_furling_name": "Furling",
|
||||
"rov_race_furling_desc": "Astute creature simili a goblin. Agili e piene di risorse.",
|
||||
|
||||
"rov_race_trol_name": "Trol",
|
||||
"rov_race_trol_desc": "Forza bruta smisurata. Sovrasta tutti gli altri ed è in pace con la Foresta Nera, ma il fuoco brucia un Trol il $1% in più di chiunque altro.",
|
||||
|
||||
"rov_race_draugh_name": "Draugh",
|
||||
"rov_race_draugh_desc": "Un guerriero non morto in decomposizione, alimentato da magia oscura e metallo estremo.",
|
||||
|
||||
"rov_race_dvergar_name": "Dvergar",
|
||||
"rov_race_dvergar_desc": "Piccoli e testardi fabbri del profondo. Fragili nel fisico, ma maestri di metallo, miniera e mercato.",
|
||||
|
||||
"rov_race_trenta_name": "Trenta",
|
||||
"rov_race_trenta_desc": "Popolo nato dagli alberi, parente di radici e foglie. Paziente e difficile da abbattere.",
|
||||
|
||||
"rov_race_sverm_name": "Sverm",
|
||||
"rov_race_sverm_desc": "Stirpe dello sciame nata dalla chitina. Corazzata dalla nascita e mai rallentata, velenosa, in pace con ogni cosa che striscia, ma i colpi contundenti e il fuoco trovano le giunture."
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue