SunkenlandLocalizationAPI
Sunkenland Localization API is a shared localization library for Sunkenland BepInEx mods.
模組介紹 作者原文
Note: This description is bilingual. The Chinese section is provided below the English section.
說明:本描述爲中英雙語版本,中文內容位於英文內容下方。
Sunkenland Localization API (English)
Sunkenland Localization API is a shared localization library for Sunkenland mods.
What This Mod Does
- Lets compatible mods load their own external JSON language files.
- Uses Sunkenland's active language and refreshes registered mod text after a language change.
- Supports localized config sections, setting names, descriptions, dropdown values, ordering, and slider steps.
For Players
This mod is an API/dependency. It does not add gameplay features by itself.
Install it only when another mod lists Sunkenland Localization API as a requirement.
For Mod Authors
Reference SunkenlandLocalizationAPI.dll and add a hard BepInEx dependency:
using BepInEx;
using BepInEx.Configuration;
using SunkenlandLocalizationAPI.Api;
[BepInDependency(SunkenlandLocalizationAPI.PluginInfo.PLUGIN_GUID)]
public sealed class MyPlugin: BaseUnityPlugin
{
private void Awake()
{
Config.Bind("General", "Enabled", true, I18n.Localizer.Config("config.enabled", 10, "General", "config.general", 10));
LocalizationApi.LanguageChanged += OnLanguageChanged;
}
private static void OnLanguageChanged(string language)
{
// Refresh this mod's existing UI text here.
}
}
Load the JSON file from the directory containing your mod DLL. This also works with generated r2modman and mod-manager folder names:
using System.IO;
using System.Reflection;
using SunkenlandLocalizationAPI.Api;
internal static class I18n
{
private const string FileName = "MyMod.Localization.json";
private static readonly ModLocalizer _localizer = Load();
internal static ModLocalizer Localizer
{
get { return _localizer; }
}
internal static string Text(string key, params object args)
{
return _localizer.GetLocalizedText(key, args);
}
private static ModLocalizer Load()
{
string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
ModLocalizer localizer = LocalizationApi.For(PluginInfo.PLUGIN_GUID);
localizer.RegisterJson(Path.Combine(directory, FileName));
return localizer;
}
}
The Config call uses.name and.description. Enum and acceptable-list values use a normalized lowercase suffix, so SafeMode resolves to.safe_mode automatically:
Config.Bind("General", "Mode", MyMode.SafeMode, I18n.Localizer.Config("config.mode", 20, "General", "config.general", 10));
Pass an AcceptableValueRange and sliderStep to declare a custom range-slider step in the same call:
Config.Bind("Display", "Scale", 100, I18n.Localizer.Config("config.scale", 10, "Display", "config.display", 20, new AcceptableValueRange(50, 200), sliderStep: 5d));
Single JSON file example:
{
"en": {
"config.general": "General",
"config.enabled.name": "Enabled",
"config.enabled.description": "Enable this mod.",
"config.mode.name": "Mode",
"config.mode.description": "Select the operating mode.",
"config.mode.safe_mode": "Safe"
},
"zh-Hans": {
"config.general": "常規",
"config.enabled.name": "啓用",
"config.enabled.description": "啓用此模組。",
"config.mode.name": "模式",
"config.mode.description": "選擇運行模式。",
"config.mode.safe_mode": "安全"
}
}
Every localization file must contain an en object. If the current language or requested key is missing, the API tries en; if the key is still missing, it returns the key itself.
Supported Locale Codes
- English: en
- Chinese (Simplified): zh-Hans
- French: fr
- German: de
- Japanese: ja
- Korean: ko
- Russian: ru
- Spanish: es
- Turkish: tr
Compatibility
- Game version: Beta 0.8.41+
Bug Reports & Feature Suggestions
If you have any questions or feature suggestions, please submit them through GitHub Issues, contact me on Discord at iceboxcool, or email me at 764884112@qq.com or ibox2333@gmail.com.
If you enjoy my mods, feel free to support me! / 如果你喜歡我的模組,請支持我一下吧!
Sunkenland Localization API (中文)
Sunkenland Localization API 是爲 Sunkenland 模組提供的共享本地化庫。
主要功能
- 讓兼容模組加載各自獨立的外置 JSON 語言文件。
安裝與使用 安裝:按包內說明操作
- 解壓本站下載的壓縮包,先讀包內的 readme / 說明檔案。
- 多數模組依賴遊戲的模組載入器:常見做法是用社群模組管理器(如 r2modman)選中本遊戲安裝,由管理器自動處理載入器與依賴。
- 手動安裝時,把模組檔案放進遊戲目錄下對應的 Mod / plugins 資料夾。
- 啟動遊戲確認載入成功;帶「前置依賴」的模組需要把依賴一併安裝。
不同模組的安裝位置差異較大,包內說明是最可靠的依據。
下面這些內容需要先安裝,否則該模組不會生效: