Localization: Switch out TextMeshPro font Asset

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?

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

using UnityEngine;
using TMPro;
using UnityEngine.Events;
using UnityEngine.Localization;
using UnityEngine.Localization.Components;

[System.Serializable]
public class LocalizedFont : LocalizedAsset<TMP_FontAsset> {}

[System.Serializable]
public class UpdateFontEvent : UnityEvent<TMP_FontAsset>{}

public class LocalizedFontEvent :  LocalizedAssetEvent<TMP_FontAsset, LocalizedFont, UpdateFontEvent>
{
}

Add it to your text and use the event to update the font

5974097--641306--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.

1 Like

Thanks, it worked.

1 Like

Hi, I using 2022.3.9. Isn’t there a much simpler solution in this version?

You can use this https://docs.unity3d.com/Packages/com.unity.localization@1.4/manual/LocalizedPropertyVariants.html

1 Like