Skip to content

Commit

Permalink
Added Localization folder example
Browse files Browse the repository at this point in the history
  • Loading branch information
Metious committed Mar 27, 2023
1 parent 7ee825f commit dc8c2b8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Example mod/Example mod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,13 @@
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.1.0" />
<PackageReference Include="PolySharp" Version="1.12.1" />
</ItemGroup>
<Target Name="CopyToOutputPath" AfterTargets="Build">
<ItemGroup>
<LocalizationFiles Include="Localization\*.*" />
</ItemGroup>
<Copy
SourceFiles="@(LocalizationFiles)"
DestinationFolder="$(OutDir)\Localization"
SkipUnchangedFiles="true" />
</Target>
</Project>
4 changes: 4 additions & 0 deletions Example mod/Localization/English.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"TitaniumClone": "Titanium Clone",
"Tooltip_TitaniumClone": "Titanium clone that makes me go yes."
}
4 changes: 4 additions & 0 deletions Example mod/Localization/Spanish.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"TitaniumClone": "Clon de Titanio",
"Tooltip_TitaniumClone": "Clon de Titanio que me hace decir que sí"
}
12 changes: 11 additions & 1 deletion Example mod/LocalizationExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,22 @@ public class LocalizationExample : BaseUnityPlugin

private void Awake()
{
#if LOCALIZATION_FOLDER
/*
* Registers a folder as localization folder.
* This folder must contain json files that are named after the language they translate.
* For example, English translation must be named English.json and Spanish translation must be named Spanish.json.
* SML expects this folder to be located in the mod folder at ModName/Localization by default.
*/
LanguageHandler.RegisterLocalizationFolder();
#else
// Register our English language entries to the English language
LanguageHandler.RegisterLocalization("English", _languageEntriesEng);

// Register our Spanish language entries to the Spanish language
LanguageHandler.RegisterLocalization("Spanish", _languageEntriesEsp);

#endif

/*
* Create a CustomPrefab instance for our Titanium Clone. Must be set to null or empty if you registered language entries
* for them earlier like we did.
Expand Down

0 comments on commit dc8c2b8

Please sign in to comment.