Adding Custom Localization - brandonandzeus/Trainworks2 GitHub Wiki

Custom Localization

Custom Localization is supported by the framework, by loading a CSV file. There are two parts to implementing it in your mod!

Crafting the CSV

You can craft a CSV in Excel, Google Sheets, or a text editor. The CSV should contain the following headers which you can copy-paste into any of the previous software easily. The Type column must be 'Text' for all entries, and is mandatory.

Key,Type,Desc,Plural,Group,Descriptions,English [en-US],French [fr-FR],German [de-DE],Russian,Portuguese (Brazil),Chinese [zh-CN]

You can get a sample csv (of all the text in game) by calling

CustomLocalizationManager.ExportCSV(path)

at any time.

CSV Template: https://docs.google.com/spreadsheets/d/1RxlbAcUtrf8RFC1eOE_NqWbgztq6ROJf-zwtPylHupw/edit?usp=sharing

Importing the CSV file

To import the CSV, you must call CustomLocalizationManager.ImportCSV(path). This should only be done ONCE in your Plugin's Initialize method. Any attempts to import a CSV file multiple times will result in it being ignored.

Additionally, once the game starts and the main menu is up any additional localizations can't be added via Trainworks. This is to prevent misuse from modders as the internal localization library is very slow and calling these functions many times will slow the game down.

So any calls to the localization library are batched and it's all uploaded to the localization library once to improve start-up time.

This means that while you are building all of your data you won't be able to localize any strings from within your CSV file, that shouldn't be an issue, but if it is (for instance you are generating text) You will need to use I2.Loc's parameters

Note that if your generated text includes replacement text like [attack] [gold] etc you will need to call LocalizationManager.ApplyLocalizationParams(ref text) on your generated text to parse those with their replacement strings.

Issues

Plural data is broken in the library when importing from csv, and I was too lazy to debug, so there's no plural support currently. Notes on how to implement are in the source file.

CSV Dictionary

The following in descriptions will be replaced with the appropriate symbol or value

key:

#: replace # with an a positive number

Text: Replace with Text of your choice

Special Symbols or Text:

[coin]

[gold]

[attack]

[health]

[capacity]

[armor]

[ember]

[x]

[enhance]

[resolve]

[harvest]

[summon]

[freeze]

Data Access:

[effect#] refers to the effect at Index, can be used to access data of effectState

[effect#.power]: get the ParamInt of Effect at Index

[effect#.status#.power]: get the ParamInt of the Status at Index of the Effect at Index

[effect#.upgrade.bonussize]: Get the Size of a CardUpgrade

[trait#] Get the CardTrait at Index

See: The CardTextReplacements class for a full list of what you can use here.

Text Tags:

<b>Text</b>: Bolds Text

<br>: Line Break

⚠️ **GitHub.com Fallback** ⚠️