How to batch replace font files

Hello community friends?

The game our team is currently developing is almost at the launch stage. I’m working on finishing it now, and I have an additional feature I need.

We are using A font (A.ttf) file now. However, this font does not support Chinese and Japanese. So, I have to use a different font for that country.

The problem is that the font is set in the cocos creator inspector for all label components used in the game.
image

If the system language of the device is Japanese, I need to change it to B font, and if it is Chinese, I need to change it to C font. Is there a way to replace this all at once by script?


you can use search Component Name, search Label and select all Label to change to the font you want.

That’s a very cool idea! However, the number of labels we are using is over 100, and we are currently in a situation where we need to change the font to a script. Is there any way to change it to a font? First of all, I have loaded all the font files with the asset loader.

I think extension API could be helpful

I think he is asking for runtime change.

You can create own script to handle this. Grab all labels at runtime and change ttf based on your needs.

Runtime approach could also be used in extension or simply in the devtools of scene panel (open by menu > Developer > Toggle Scene Devtools). The good thing is all modified data could be serialized into saved data

Thanks for the advice, extensions seem like a very handy feature. But it doesn’t serve my purpose right now.

For example, if you select a language on the language selection screen as follows, I want all fonts to change accordingly. In the end, it should be possible with a script, but is there no way to do this?

Oh, if it’s pure runtime need, you need to search for components and modify with a loop (it would be slow), or have a global i18n manager to do the job.

There are some i18n plugins in our store
http://store.cocos.com/app/en/resources/search?name=i18n

You can take a look

You can refer to this i18n plugin to make a similar effect, which is the popular solution.

This plugin currently supports replacing text and images, but not yet fonts.

If you want to replace the font, then you need to use the uuid of the target font as the basis to find the Label component of this font in the nodes of the scene and prefab resources. Then replace it with a new font. (This process can be done in the extension plugin)

The documentation for the extension plugin can be found at: Editor Extension · Cocos Creator