Skip to content

Localizing Text

Brian Intile edited this page Feb 15, 2019 · 11 revisions

NitorInc. will be entirely localized. The microgame commands and names are automatically handled by the game code, but if you need in-game text or an extra command, or if you're programming something outside of microgames, then follow this guide:

How it works

  • Localized text is gotten using keys corresponding to a text value that varies by language.
  • All keys and their corresponding values are in the Localization Sheet, which includes multiple sub-sheets.
  • Keys for extra microgame text are formatted "microgame.[Microgame ID].[key]", all of which are found in the Microgame Text section of the sheet.
  • Notify me if you use text so I can add a new key to the localization sheet.

Getting localized text from a script

  • To get localized text from a script, call TextHelper.getLocalizedText(string, string) or TextHelper.getLocalizedMicrogameText(). The former will require you to enter the whole key, but the latter works only in microgames and will automatically prefix "microgame.[ID].", saving you from typing it.
  • The first string argument is the key for the text. The second is the default string to return if the key isn't found.

Localizing a text component

  • If you have a TextMesh or Text component, attach a LocalizedText instance to it. For microgames, it's recommended to set the Key Prefix to "Current Microgame" so you won't need to specify "microgame.[ID]." in the key.
  • LocalizedText will edit the text automatically and will do nothing if no string with that key is found.
  • LocalizedText.setKey() can be used to change the text from a new key value.

Localizing a second microgame command

  • If you need to display an extra command mid-game, use MicrogameController.instance.displayLocalizedCommand(key, defaultValue). This function will also automaticaly add the "microgame.[ID]." so don't include that in your key string.

Fonts in TextMesh Pro

  • To localize text with a TMPro component, add a LocalizedText component as usual.
  • For the font of the TextMeshPro component, you should use the DefaultEmpty asset. Font changes are handled entirely by fallback fonts in the code, so the fonts of each localized TMPro component is an empty font with no characters.
  • Then, set the font you actually want the text to be as the "Default TM Pro Fallback Font" field in the LocalizedText component. When the text gets localized, the font will change automatically.
  • The "Tm Pro Fallback Override Fonts* is useful if you want certain custom fonts that are only available in certain languages. For each item, put in the fallback font, and then the name of each language in the "Languages" field (separated by line breaks).

Updating localization files (And TMPro fonts)

  • The game project has a scriptable object called the "Localization Updater", which pulls from our localization Google Sheet. Before you pull, make sure the "signups" and "Steam store" subsheet pages are on the far right of the main sheet (in google sheets), and make sure "Subsheet Count" in the Localization Updater matches the amount of subsheets preceding them. Then hit the "Update Language Content" button to pull.
  • TextMeshPro font assets need to be rebuilt every time the localization updates. Unfortunately there's no real way around it. The "Update Chars Files* button will create files of all chars included in every language, as well as compilation files of non-Asian languages (for fonts that support certain accented characters but not Asian languages). Use these char files in the TMPro font asset creator by changing "Character Set" and selecting the "Characters from File" option.
  • Also force a font size 86 so the padding is consistent.