Skip to content

Added localization#34

Open
hwckent wants to merge 59 commits intoManlyMarco:masterfrom
hwckent:master
Open

Added localization#34
hwckent wants to merge 59 commits intoManlyMarco:masterfrom
hwckent:master

Conversation

@hwckent
Copy link

@hwckent hwckent commented Jun 1, 2025

English translation
Chinese translation
Laying the foundation for localized languages

hwckent added 30 commits June 2, 2025 04:56
Independent language file loading: Instead of putting all languages ​​in one languages.json, create a separate lang_xx.json file for each language (e.g. lang_zh_CN.json, lang_en.json).
Simplified translation dictionary: _translations now directly stores the key-value pairs of the current language.
Language switcher: Added a language selection button in the UI, and supports real-time loading and switching of languages.
Implementing a localized system
English Translation
Chinese Translation
Localized Language
Supported language configuration
hwckent added 22 commits June 4, 2025 04:42
English, Chinese, Korean, Spanish, Brazilian, French, German, Norwegian (Bokmål) and Russian
The languages.json file should be structured like this:
 
  {
  "en": {
    "UI.HeroineList": "Heroine List",
    "UI.StartGameToSeePlayerCheats": "Start the game to see player cheats.",
    "UI.GeneralPlayer": "General Player",
    "UI.FishingSkillLevel": "Fishing Skill Level: {0}",
    "UI.ShanHeartLevel": "Shan Heart Level: {0}",
    "UI.EnableInstantFishing": "Enable Instant Fishing",
    "UI.EnableFreeCrafting": "Enable Free Crafting",
    "UI.EnablePlayerNoclip": "Enable Player Noclip",
    "UI.AllowBuildingAnywhere": "Allow Building Anywhere",
    "UI.AllowBuildingOverlap": "Allow Building Overlap",
    "UI.WarningPermanent": "Warning: These changes are permanent!",
    "UI.UnlimitedInventorySlots": "Unlimited Inventory Slots",
    "UI.ClearInventory": "Clear Inventory",
    "UI.InventoryCleared": "Inventory Cleared!",
    "UI.AddOneItem": "Add 1 of Each Item",
    "UI.AddNinetyNineItems": "Add 99 of Each Item",
    "UI.ItemsAdded": "{0} items added to inventory.",
    "UI.NavigateToPlayer": "Navigate to Player in Object Tree",
    "UI.OpenPlayerInInspector": "Open Player in Inspector",
    "UI.PlayerNoBodyAssigned": "Player has no body assigned, cannot navigate.",
    "UI.Weather": "Weather",
    "UI.Next": "Next",
    "UI.Temperature": "Temperature: {0}°C",
    "UI.GameTime": "Game Time",
    "UI.HSceneControls": "H Scene Controls",
    "UI.MaleGauge": "Male Gauge",
    "UI.FemaleGauge": "Female Gauge",
    "UI.OpenHSceneFlagsInInspector": "Open H Scene Flags in Inspector",
    "UI.HSceneFlagCtrl": "H Scene Flag Ctrl",
    "UI.Heroines": "Heroines",
    "UI.SelectHeroine": "Select Heroine {0}: {1}",
    "UI.SelectHeroineToAccessStats": "Select a heroine from the list to access her stats.",
    "UI.SelectedHeroineName": "Selected Heroine: {0}",
    "UI.Status": "Status",
    "UI.Sickness": "Sickness",
    "UI.Heal": "Heal",
    "UI.DesiresMotivations": "Desires & Motivations",
    "UI.FlavorSkills": "Flavor Skills",
    "UI.ResetTalkTime": "Reset Talk Time",
    "UI.NavigateToActor": "Navigate to Actor in Object Tree",
    "UI.OpenActorInInspector": "Open Actor in Inspector",
    "UI.Actor": "Actor: {0}",
    "UI.InspectExtendedData": "Inspect Extended Data",
    "UI.ExtDataFor": "Extended Data for {0}",
    "UI.Language": "Language",
    "Game.Weather.Clear": "Clear",
    "Game.Weather.Cloudy": "Cloudy",
    "Game.Weather.Rain": "Rain",
    "Game.Weather.Storm": "Storm",
    "Game.Weather.Snow": "Snow",
    "Game.Status.LovePhase": "Love Phase: {0}",
    "Game.Status.SicknessNone": "None",
    "Strength": "Strength",
    "Stamina": "Stamina",
    "Intellect": "Intellect",
    "Spirit": "Spirit",
    "Dexterity": "Dexterity",
    "Agility": "Agility",
    "Perception": "Perception",
    "Luck": "Luck",
    "HP": "HP",
    "MP": "MP",
    "Energy": "Energy",
    "Hunger": "Hunger",
    "Thirst": "Thirst",
    "Purity": "Purity",
    "Stress": "Stress",
    "Hygiene": "Hygiene",
    "Pleasure": "Pleasure",
    "Arousal": "Arousal",
    "Affection": "Affection",
    "Submission": "Submission",
    "Discipline": "Discipline",
    "Curiosity": "Curiosity",
    "Morality": "Morality",
    "Lust": "Lust",
    "Fear": "Fear",
    "PainTolerance": "Pain Tolerance",
    "Speech": "Speech",
    "Combat": "Combat",
    "Survival": "Survival",
    "Crafting": "Crafting",
    "Cooking": "Cooking",
    "Fishing": "Fishing",
    "Hunting": "Hunting",
    "Gardening": "Gardening",
    "Medicine": "Medicine",
    "Exploration": "Exploration",
    "Social": "Social",
    "Stealth": "Stealth"
  },
  "zh_CN": {
    "Heroine list": "女主角列表",
    "Manager.ADV.Instance": "ADV管理器实例",
    // ... // ... Other Chinese translations (can be kept for completeness)
  }
}
Create a languages.json file, its structure should look like this:
{
  "zh_CN": {
    "Heroine list": "女主角列表",
    "Manager.ADV.Instance": "ADV管理器实例",
    // ... 其他中文翻译
    "General / Player": "通用 / 玩家",
    "Fishing skill lvl: ": "钓鱼技能等级:",
    "Shan heart lvl: ": "沙恩好感度等级:",
    "Enable instant fishing": "启用即时钓鱼",
    "Enable free crafting": "启用自由制作",
    "Enable player noclip": "启用玩家穿墙",
    "Allow building anywhere": "允许随处建造",
    "Allow building items to overlap": "允许物品重叠建造",
    "Warning: These can't be turned off!": "警告:这些无法关闭!",
    "Unlimited inventory slots": "无限物品栏位",
    "Clear player inventory": "清空玩家物品栏",
    "Your inventory has been cleared.": "你的物品栏已被清空。",
    "Get +1 of all items": "获得所有物品+1",
    "+99": "+99",
    "items have been added to your inventory": "件物品已添加到你的物品栏。",
    "Navigate to Player's GameObject": "导航到玩家的游戏对象",
    "Player has no body assigned": "玩家未分配身体",
    "Open Player in inspector": "在检查器中打开玩家",
    "Weather: ": "天气:",
    "Weather.Clear": "晴朗",
    "Weather.Rain": "下雨",
    "Weather.Cloudy": "多云",
    // ... 根据你的 Weather 枚举添加其他天气类型
    "Clear": "晴朗",
    "Next": "下一个",
    "Temperature: ": "温度:",
    "Game time:": "游戏时间:",
    "H scene controls": "H场景控制",
    "Male Gauge: ": "男性欲望值:",
    "Female Gauge: ": "女性欲望值:",
    "Open HScene Flags in inspector": "在检查器中打开H场景旗标",
    "Heroines": "女主角",
    "Select a heroine to access her stats": "选择一个女主角来查看其状态",
    "Selected heroine name: ": "已选择女主角名称:",
    "Status": "状态",
    "Love phase: ": "爱恋阶段:",
    "Sickness: ": "疾病:",
    "Heal": "治疗",
    "Desires & Motivations": "欲望与动机",
    "Flavor skills": "风味技能",
    "Reset talk time": "重置对话时间",
    "Navigate to Actor's GameObject": "导航到角色的游戏对象",
    "Actor has no body assigned": "角色未分配身体",
    "Open Actor in inspector": "在检查器中打开角色",
    "Inspect extended data": "检查扩展数据",
    "ExtData for ": "扩展数据:"
  },
  "en": {
    "Heroine list": "Heroine list",
    "Manager.ADV.Instance": "Manager.ADV.Instance",
    // ... Other English translations (these can be omitted if English is the default, but are kept for completeness)
  }
}
@hwckent
Copy link
Author

hwckent commented Jun 3, 2025

老实说,我对此并不确定,这增加了很多额外的复杂性和需要维护的新事物。

目前推荐的插件翻译方式是使用自动翻译器,就像KK_ExpressionControl等日语插件一样。它不需要对插件进行任何代码更改,并且可以非常轻松地添加新语言。

@hwckent
Copy link
Author

hwckent commented Jun 3, 2025

Introduced Newtonsoft.Json: This is a widely used .NET library for serializing and deserializing JSON, which is very suitable for loading external language files.
Externalized language data: The text of the plugin interface is localized by loading translations from the languages.json file. This means that you can easily add or modify translations without recompiling the plugin.
T(string key) translation function: This is a concise and efficient implementation that finds the translation of the corresponding language by the key name. If the translation is not found, it will fall back to the original key name, which is helpful for debugging and identifying missing translations.
Language selector (DrawLanguageSelector): Added a language switch button in the GUI, so that users can easily choose to display Chinese or English, which greatly improves the user experience.
Globally apply translations: You replace all hard-coded English strings with T("key") to ensure that most of the text in the plugin interface can be translated.
Error handling: Added exception handling when the languages.json file fails to load, and logs, which improves the robustness of the plugin.

hwckent added 2 commits June 4, 2025 07:57
Improved the default setting of expected language options when loading languages.json fails or the file does not exist
@ManlyMarco ManlyMarco self-assigned this Jun 4, 2025
@ceshizhuanyong895
Copy link

I'm not sure about this one to be honest, this adds a lot of extra complexity and new things to maintain.

The currently recommended way of translating the plugin is by using AutoTranslator, as is done for Japanese plugins like KK_ExpressionControl. It doesn't require any code changes in the plugin and allows adding new languages very easily.

@ManlyMarco Hello, I’ve tested and found that XUnity.AutoTranslator-IL2CPP currently does not support IMGUI translation. May I ask if there are any alternative solutions available?

@ManlyMarco
Copy link
Owner

@ceshizhuanyong895 I don't know of anything other than modifying the plugin dll itself at this time.

@ceshizhuanyong895
Copy link

@ceshizhuanyong895 I don't know of anything other than modifying the plugin dll itself at this time.

Got it, I understand. Looking forward to seeing the masterpieces from all the talented experts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants