Line 623: |
Line 623: |
| The translation API lets you translate your mod into the player's current language, accounting for locale fallback automatically (e.g. if a translation isn't available in <tt>pt-BR.json</tt>, SMAPI will check <tt>pt.json</tt> and <tt>default.json</tt>). Translations can be a simple string, or they can include tokens to inject values into the translation. | | The translation API lets you translate your mod into the player's current language, accounting for locale fallback automatically (e.g. if a translation isn't available in <tt>pt-BR.json</tt>, SMAPI will check <tt>pt.json</tt> and <tt>default.json</tt>). Translations can be a simple string, or they can include tokens to inject values into the translation. |
| | | |
− | ====File structure====
| + | <dl> |
− | SMAPI reads translations from JSON files in a structure like this: | + | <dt>File structure</dt> |
| + | <dd>SMAPI reads translations from JSON files in a structure like this: |
| <pre> | | <pre> |
| YourMod/ | | YourMod/ |
Line 668: |
Line 669: |
| | Spanish | | | Spanish |
| | <tt>es.json</tt> | | | <tt>es.json</tt> |
− | |} | + | |}</dd> |
| | | |
− | ====Reading translations====
| + | <dt>Reading translations</dt> |
− | Once your i18n files are set up, you can read translations for the current locale: | + | <dd>Once your i18n files are set up, you can read translations for the current locale: |
| <source lang="c#"> | | <source lang="c#"> |
| // read a simple translation | | // read a simple translation |
Line 691: |
Line 692: |
| | | |
| i18n.Get("item-type.fruit-tree", new { fruitName = i18n.Get("apple") }); | | i18n.Get("item-type.fruit-tree", new { fruitName = i18n.Get("apple") }); |
− | </source> | + | </source></dd> |
| | | |
− | ====Tips for translators====
| + | <dt>Tips for translators</dt> |
| + | <dd> |
| * Save i18n files with UTF-8 encoding to avoid broken symbols in-game. | | * Save i18n files with UTF-8 encoding to avoid broken symbols in-game. |
| * Type <code>reload_i18n</code> into the SMAPI console and hit enter to reload translations without exiting the game. (If a mod internally cached a translation, it may not be updated.) | | * Type <code>reload_i18n</code> into the SMAPI console and hit enter to reload translations without exiting the game. (If a mod internally cached a translation, it may not be updated.) |
| + | </dd> |
| + | </dl> |
| | | |
| ==Utilities== | | ==Utilities== |