Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Localization: Switch out TextMeshPro font Asset

Discussion in 'Localization Tools' started by mistergreen2016, Jun 12, 2020.

  1. mistergreen2016

    mistergreen2016

    Joined:
    Dec 4, 2016
    Posts:
    226
    Hey,
    I'm playing with the simple String table. I'm switching from English to Chinese. It works fine with the built in Unity text but TMP needs to switch out to the Chinese Font Asset I made. How do I do this?
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,149
    Hi,
    At the moment you would need to do this with a script. You could create a localized font in the same way we do localized textures etc.

    This script will give you a localized font component which works the same way as strings but for font assets
    Code (CSharp):
    1. using UnityEngine;
    2. using TMPro;
    3. using UnityEngine.Events;
    4. using UnityEngine.Localization;
    5. using UnityEngine.Localization.Components;
    6.  
    7. [System.Serializable]
    8. public class LocalizedFont : LocalizedAsset<TMP_FontAsset> {}
    9.  
    10. [System.Serializable]
    11. public class UpdateFontEvent : UnityEvent<TMP_FontAsset>{}
    12.  
    13. public class LocalizedFontEvent :  LocalizedAssetEvent<TMP_FontAsset, LocalizedFont, UpdateFontEvent>
    14. {
    15. }
    16.  
    Add it to your text and use the event to update the font

    upload_2020-6-12_22-0-32.png

    We are working on a system to allow for property variants in the next version which will make this much simpler.
     
    Last edited: Jun 12, 2020
    xuwilliam01 likes this.
  3. mistergreen2016

    mistergreen2016

    Joined:
    Dec 4, 2016
    Posts:
    226
    Thanks, it worked.
     
    Last edited: Jun 13, 2020
    karl_jones likes this.
  4. divanchik

    divanchik

    Joined:
    Oct 23, 2021
    Posts:
    1
    Hi, I using 2022.3.9. Isn't there a much simpler solution in this version?
     
  5. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,149
    divanchik likes this.