Pathoschild / SMAPI

The modding API for Stardew Valley.
https://smapi.io/
GNU Lesser General Public License v3.0
1.71k stars 258 forks source link

Expose the Translate component #954

Closed lycc193 closed 1 month ago

lycc193 commented 1 month ago

In the current version, as a third-party developer wanting to add translations for a specific mod, one can only provide translation files (e.g., zh.json) and have players manually copy/overwrite them into the relevant directory, which is highly inconvenient. Additionally, there is no way to monitor version control for localized translations (due to the absence of a manifest file).

Upon reviewing the source code, it was found that smapi itself allows third-party modifications to a mod's localization entries, but smapi has set them as internal, which currently only allows cp (content patcher) to access them normally. It is hoped that the relevant interfaces can be exposed public or, at the least, be made accessible through cp for third-party content packs to load translations.

example:

{
    "Changes":{
        "Action":"Load",
        "Targe":"mod_uuid/locale/zh"
        "FromFile":"asset/xxxx/zh.json"
    }
}

Related Links: loading language files

internal translator

internal mod metadata

only cp

Pathoschild commented 1 month ago

Hi! Mods can't directly change other mods by design, since that leads to a fragile mod ecosystem and makes technical support difficult (e.g. players reporting bugs on the original mod due to changes from a third party).

I recommend submitting the translations to the original mod instead. That way they're simple and built-in for players, and the original author can maintain them as needed (e.g. adding placeholder text for new translations).

If you want to discuss the idea some more, I suggest asking in #making-mods on the Stardew Valley Discord. There's a lot more mod authors there who can provide their own feedback, since very few people watch issues here.

lycc193 commented 1 month ago

? Other similar game's mod launchers all provide interfaces for external loading of translations, but Stardew Valley is the only one that doesn't allow it.

For example, Minecraft, Factorio, Terraria, etc.

lycc193 commented 1 month ago

Loading translation files alone should not modify the content of the mod itself, so how could it lead to errors?

lycc193 commented 1 month ago

Meanwhile, the current content patcher (CP) allows for modifications to other mods' resource files, including but not limited to NPC textures, dialogues, etc., through third-party mods due to its loading mechanism. However, translation files are loaded through SMAPI, which CP cannot load, resulting in the inability to externally load language files while still allowing external modifications to the mod itself.

Pathoschild commented 1 month ago

Content packs can't edit other mods' files, including their textures and text. What they can do is apply edits to the same game assets which another mod targets (e.g. apply edits to an NPC's dialogue after another mod does), which you can do with translations too.

Stardew Valley is a different game with its own modding community and history. It's always interesting to compare what it does with other games' modding APIs, but they're not directly comparable. (That said, I'd be surprised if every other modding API let you directly edit third-party mods.)

Currently you're only talking to me though. If you want to discuss more widely with other mod authors, #making-mods on the Stardew Valley Discord is the best place to do it.

lycc193 commented 1 month ago

But in fact, other mods can be modified through the use of the "action":"editdata" parameter. In the new version of CP, due to the loading mechanism, all mod contents are loaded into the global environment, and target can refer to other mods, not just the original content. For instance, this mod modifies NPC content that belongs only to SVE.

However, language files, specifically, due to their loading through SMAPI rather than CP, still have to be installed through unpacking rather than as an independent mod.

lycc193 commented 1 month ago

In fact, due to copyright reasons, for mods that have been abandoned, other games can only rely on the interfaces provided by the API to conduct third-party repairs. While games like Stardew Valley, which directly perform decompilation for error repairs or transplants for high-level versions, are exceptionally special cases.

Pathoschild commented 1 month ago

You can edit an NPC's data once it's added to the game, because then it's part of the game. You can't edit the internal data which the mod uses to add that game asset though. For example, see Let other mods edit your internal assets on the wiki.

For example, let's say mod A does this:

{
    "Action": "EditData",
    "Target": "Characters/Dialogue/Abigail",
    "Entries": {
        "Sun_25": "Huh. I think that would get old fast."
    }
}

Mod B can then edit Characters/Dialogue/Abigail too and change the same entry, but it can't change the original mod's files or patches. Mod B isn't editing mod A, it's just layering its own changes onto the same game data.

In Stardew Valley, mod authors are encouraged to make their mods open-source. That lets the community submit fixes directly, or post updated versions if the mods become abandoned. If a mod is abandoned and not open-source, another mod author can create a new mod to replace it (and hopefully make it open-source). Directly patching another mod to fix it isn't common practice in Stardew Valley (aside from the auto-fixes built into SMAPI and Content Patcher).

lycc193 commented 1 month ago

Regardless of the process, the result achieved the purpose of modifying the mod by a third party. Even for modifications of this level, the translation files cannot be directly manipulated; they must be decompressed into the local directory.

Pathoschild commented 1 month ago

Translations work the same way. For example, let's say a mod does this:

{
    "Action": "EditData",
    "Target": "Characters/Dialogue/Abigail",
    "Entries": {
        "Sun_25": "{{i18n: dialogue.abigail.sun25}}"
    }
}

Another mod can then edit Characters/Dialogue/Abigail and replace that translation text with its own translation (since it's now part of the game data). But it can't edit the internal data (including translations) in the original mod directly, it can only overlay edits onto the same game data.

lycc193 commented 1 month ago

Do you mean...

{
    "Action": "EditData",
    "Target": "Characters/Dialogue/Abigail",
    "Entries": {
        "Sun_25": "{{i18n: mymod.dialogue.abigail.sun25}}"
    }
}

Is it supposed to be modified in this way? This approach has poor compatibility and is extremely inconvenient for mods with a large amount of text, requiring the writing of a lot of unnecessary content. The issue is that currently, all other resources can be modified using cp, but only i18n cannot. I'm just asking to restore i18n to the same status as other resources. Although they are all internal, cp provides interfaces for all other resources, but not for i18n.

Pathoschild commented 1 month ago

Translations work the same way as other internal mod data. Game assets in the content pipeline (like Characters/Dialogue/Abigail) are part of the game, they're not internal mod data.

As the new-issue template says, this isn't the right place to propose ideas for SMAPI. I suggest discussing it in #making-mods on the Stardew Valley Discord, where many other mod authors can provide feedback too. If you'd like to continue discussing the idea, please do so there.

I'll lock this conversation since we've already discussed it to the extent possible without involving other mod authors.