Skip to content

Translation Patcher

Yukita Mayako edited this page May 15, 2023 · 1 revision

The release build of Cassette Beasts uses compressed PHashTranslation tables for its localization. This is great for speed and a low memory footprint, but bad for modding: While getting any single request handled by PHashTranslation is easy, the rest of the functionality the Translation class is supposed to provide is completely absent! There is no easy way to dump all of the existing translation "keys", nor can you insert new ones into a PHashTranslation at runtime to replace anything.

When Mod Utils loads, it takes over all known vanilla translation tables and inserts itself as a scripted middleman. This allows the library to offer other mods the opportunity to respond to specific translation keys (eg. a certain item's name or description) or even rewrite translation results afterwards (eg. to programmatically change lines of dialogue at runtime) while still falling back to the complete original translation tables even after the game updates in the future.

⚠️ You do not need this feature if you are adding new text strings to the game. Only use this if you are overriding vanilla content!

To use this feature, simply invoke one of the following two commands during your mod's init_content callback:

trans_patch.add_translation

func add_translation(table: Translation) -> void

If you've found specific strings you want to replace, inside of cutscene nodes, item metadata, overworld chunk metadata, and so on, you should use this function. Just write a translation table containing only the vanilla keys you want to replace and the messages you want to replace them with, load it, and pass the Resource here.

Read the Importing Translations page of the Godot Engine 3.5 docs for detailed information about how your translation table should be formatted and imported.

Example:

func init_content():
	DLC.mods_by_id.cat_modutils.trans_patch.add_translation(preload("override.en.translation"))

trans_patch.add_translation_callback

func add_translation_callback(object: Object, function: String, binds: Array = [], locale: String = "en") -> void

Do you want a blanket mechanism to replace a piece of dialog that could appear anywhere, in multiple translation keys, such as a particular phrase or character name? Use this function to add a scripted callback that will pass every localization string through your function and allow you to transform it before it shows up on screen.

Example:

func init_content():
	DLC.mods_by_id.cat_modutils.trans_patch.add_translation_callback(self, "_on_translation")

func _on_translation(key: String, message: String) -> String:
	if "bugs" in message:
		return message.replace("bugs", "features")
	return ""
Clone this wiki locally