Line 4: |
Line 4: |
| | | |
| ==Overview== | | ==Overview== |
− | SMAPI reads translations from files in your mod folder. When you request a translation, it will automatically handle locale fallback (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. | + | SMAPI reads translations from files in your mod folder. When you request a translation, it will automatically handle locale fallback (''e.g.,'' if a translation isn't available in <samp>pt-BR.json</samp>, SMAPI will check <samp>pt.json</samp> and <samp>default.json</samp>). Translations can be a simple string, or they can include tokens to inject values into the translation. |
| | | |
| ==i18n folder== | | ==i18n folder== |
| ===File structure=== | | ===File structure=== |
− | SMAPI reads translations from JSON files in an <tt>i18n</tt> subfolder in your mod folder: | + | SMAPI reads translations from JSON files in an <samp>i18n</samp> subfolder in your mod folder: |
| <pre> | | <pre> |
| YourMod/ | | YourMod/ |
Line 19: |
Line 19: |
| </pre> | | </pre> |
| | | |
− | The <tt>default.json</tt> file includes the default text that will be shown if a more specific translation isn't available, and you create a separate file for each language. Each translation file should have one of these file names: | + | The <samp>default.json</samp> file includes the default text that will be shown if a more specific translation isn't available, and you create a separate file for each language. Each translation file should have one of these file names: |
| | | |
| {| class="wikitable" | | {| class="wikitable" |
Line 27: |
Line 27: |
| |- | | |- |
| | Chinese | | | Chinese |
− | | <tt>zh.json</tt> | + | | <samp>zh.json</samp> |
| |- | | |- |
| | French | | | French |
− | | <tt>fr.json</tt> | + | | <samp>fr.json</samp> |
| |- | | |- |
| | German | | | German |
− | | <tt>de.json</tt> | + | | <samp>de.json</samp> |
| |- | | |- |
| | Hungarian | | | Hungarian |
− | | <tt>hu.json</tt> | + | | <samp>hu.json</samp> |
| |- | | |- |
| | Italian | | | Italian |
− | | <tt>it.json</tt> | + | | <samp>it.json</samp> |
| |- | | |- |
| | Japanese | | | Japanese |
− | | <tt>ja.json</tt> | + | | <samp>ja.json</samp> |
| |- | | |- |
| | Korean | | | Korean |
− | | <tt>ko.json</tt> | + | | <samp>ko.json</samp> |
| |- | | |- |
| | Portuguese | | | Portuguese |
− | | <tt>pt.json</tt> | + | | <samp>pt.json</samp> |
| |- | | |- |
| | Russian | | | Russian |
− | | <tt>ru.json</tt> | + | | <samp>ru.json</samp> |
| |- | | |- |
| | Spanish | | | Spanish |
− | | <tt>es.json</tt> | + | | <samp>es.json</samp> |
| |- | | |- |
| | Turkish | | | Turkish |
− | | <tt>tr.json</tt> | + | | <samp>tr.json</samp> |
| |} | | |} |
| + | |
| + | For a [[Modding:Custom languages|custom language]], use its <samp>LanguageCode</samp> value in the filename. |
| | | |
| ===File format=== | | ===File format=== |
− | Each <tt>.json</tt> file should contain a flat key→value lookup with your default text. Each key is case-insensitive, and can contain alphanumeric, underscore, hyphen, and dot characters. Feel free to add JavaScript comments to organise or document your translations. For example: | + | Each <samp>.json</samp> file should contain a flat key→value lookup with your default text. Each key is case-insensitive, and can contain alphanumeric, underscore, hyphen, and dot characters. Feel free to add JavaScript comments to organise or document your translations. For example: |
| <syntaxhighlight lang="javascript"> | | <syntaxhighlight lang="javascript"> |
| { | | { |
Line 87: |
Line 89: |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
− | The <tt>helper.Translate(…)</tt> method returns a fluent interface — you can keep calling methods on its return value to customise the translation. (See IntelliSense for a description of the available methods.) To get the text, just assign it to a string: | + | The <samp>helper.Translate(…)</samp> method returns a fluent interface — you can keep calling methods on its return value to customise the translation. (See IntelliSense for a description of the available methods.) To get the text, just assign it to a string: |
| <syntaxhighlight lang="c#"> | | <syntaxhighlight lang="c#"> |
| // use fluent chain | | // use fluent chain |
Line 103: |
Line 105: |
| | | |
| If a translation breaks, you'll know immediately since it won't compile. | | If a translation breaks, you'll know immediately since it won't compile. |
| + | |
| + | ==See also== |
| + | [https://gist.github.com/Pathoschild/4e0af42158583983a4206d4d734bfc0b LINQ script] to format an event for translations |
| + | |
| + | [[zh:模组:制作指南/APIs/Translation]] |