Example_LocalizedString.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using UnityEngine;
  2. namespace I2.Loc
  3. {
  4. public class Example_LocalizedString : MonoBehaviour
  5. {
  6. public LocalizedString _MyLocalizedString; // This string sets a Term in the inspector, but returns its translation
  7. public string _NormalString; // This is regular string to see that the LocalizedString has a custom inspector, but this shows only a textField
  8. [TermsPopup]
  9. public string _StringWithTermPopup; // Example of making a normal string that show as a popup with all the terms in the inspector
  10. public void Start()
  11. {
  12. // LocalizedString are strings that can be set to a Term, and when getting its value, return the Term's translation
  13. // Basic Example of using LocalizedString in the Inspector
  14. // Just change the Term in the inspector, and use this to access the term translation
  15. Debug.Log(_MyLocalizedString);
  16. Debug.Log(LocalizationManager.GetTranslation(_NormalString)); // regular strings need to manually call GetTranslation()
  17. Debug.Log(LocalizationManager.GetTranslation(_StringWithTermPopup)); // same here, given that this string just have a custom inspector
  18. // Example of setting the term in code to get its translation
  19. LocalizedString locString = "Term2";
  20. string translation = locString; // returns the translation of Term2 to the current language
  21. Debug.Log(translation);
  22. // Assigning a LocalizedString to another LocalizedString, copies the reference to its term
  23. LocalizedString locString1 = _MyLocalizedString;
  24. Debug.Log(locString1);
  25. // LocalizedString have settings to customize the result
  26. LocalizedString customString = "Term3";
  27. Debug.Log(customString);
  28. LocalizedString customNoRTL = "Term3";
  29. customNoRTL.mRTL_IgnoreArabicFix = true;
  30. Debug.Log(customNoRTL);
  31. LocalizedString customString1 = "Term3";
  32. customString1.mRTL_ConvertNumbers = true;
  33. customString1.mRTL_MaxLineLength = 20;
  34. Debug.Log(customString1);
  35. // Copying a LocalizedString also copies its settings
  36. LocalizedString customStringCopy = customString1;
  37. Debug.Log(customStringCopy);
  38. }
  39. }
  40. }