Skip to content

How to get translation in custom scripts

Rodion Lodza edited this page Oct 25, 2020 · 5 revisions

You can get a localized string by key in your scripts. Localizator has several methods for getting localized string.

  • Localizator.Translate(string key, CaseType caseType = CaseType.Default) - return translated text by key for current language.
  • Localizator.Translate(string key, SystemLanguage language, CaseType caseType = CaseType.Default) - return translated text by key for specific language.

You can choose case type of localized string.

  • Default (as in localization file)
  • Uppercase
  • Capitalize
  • Lowercase

Example

using SimpleLocalization;
using UnityEngine.UI;
using UnityEngine;

public class DynamicText : MonoBehaviour
{
    [SerializeField] private Text someText = null;

    private void Start()
    {
        SetDefaultText();
    }

    private void SetDefaultText()
    {
        someText.text = Localizator.Translate("diamonds");
    }

    public void SetAnotherText()
    {
        someText.text = Localizator.Translate("coins");
    }
}
Clone this wiki locally