0
\$\begingroup\$

I am trying to build a localization system for games. And I have stumbled upon a problem where in Unity you basically have to change all the text in Text components / any other references like audio - when loading a game every time.

To better explain it - if the default language is English and user decided to change language to any other. Even if you localize all the files used in the game via code, later on you will have to do it again, when user loads the game after quiting it. Because components don't persist data changed via code in run-time.

How do I make it so that user would be able to change the language once, and all of those references and text... would persist and didn't require re-set up every time the game is loaded? Is that even possible in Unity?

Or should I just localize after the game has been made. And just allow people to download different language versions. But then again, it makes it difficult for people who want to change their language.

\$\endgroup\$
  • \$\begingroup\$ Consider the case where your game is installed on the family computer in a bilingual household. The brother prefers to play the game on his save file in English, the sister prefers to play the game on her save file in French. How do you propose to serve these players without assigning localized text at startup/load time each time the game is run? \$\endgroup\$ – DMGregory Aug 24 '18 at 13:14
  • \$\begingroup\$ @DMGregory still it's not like the menu would be different for any of them. And making saves for every language, maybe, it's a cool feature, but might be an overkill. I don't know if any game proposes such features, so it might not even be demanded from players because it's not standardized. The text would be changed on every scene load if "push" approach used, so even if this feature exists - it can easily be implemented there while the game is loading a level. \$\endgroup\$ – Candid Moon _Max_ Aug 24 '18 at 14:21
  • \$\begingroup\$ @DMGregory but I get the point. If the component is persistent then there is no way to do it unless you change it when the scene is loaded. Or changing the language in settings. \$\endgroup\$ – Candid Moon _Max_ Aug 24 '18 at 14:22
3
\$\begingroup\$

Localization systems I've seen generally work in a "pull" approach, rather than a "push".

ie. instead of pushing out a change to all text in the game when the player changes the language, instead each text field pulls-in its text when it's time to be displayed.

How it might look in Unity is you could have a LocalizedText component on the GameObjects that need text. Each LocalizedText component knows the language-independent ID of the text it's looking for, eg. "Menu-Label-LoadGame".

Inside its OnEnable method (called when the object is spawned or toggled to active state), it asks the localization system for the correct localized string for "Menu-Label-LoadGame" in the user's currently selected language, the the localization system looks it up and returns the display text, eg. "Load Game". The LocalizedText component then populates that into its display field.

When the language changes at runtime, you can fire an OnLanguageChange event that all LocalizedText components subscribe to, telling them to refresh their text again.

This way, the only thing you need to store is the player's last selected language. Everything else will be looked up on demand.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ I am making it this way, though, what is the advantage of "pull" approach? Seems like "push" approach would increase loading time a bit, but wouldn't affect run-time. I thought I could reload all required components when the scene is loaded. Though, I am wondering how people go about audio for example. Maybe, create separate entity, like struct for audio to have both the AudioClip slot + key for localization? \$\endgroup\$ – Candid Moon _Max_ Aug 24 '18 at 12:23
  • 1
    \$\begingroup\$ The push approach does not scale well to situations where some game content isn't loaded when the game first starts / when the language is changed. eg. if the game has multiple levels in separate scenes, you wouldn't want level 5 to miss getting localized because it wasn't loaded at the time the language was changed. The same applies to content spawned at runtime, content streaming, DLC, online interaction messages sent from a server, etc. Relying on all text to be accessible at the one moment the language is changed makes the solution limited and difficult to scale. \$\endgroup\$ – DMGregory Aug 24 '18 at 12:51
  • \$\begingroup\$ Yeah, got it. I would still put the component on objects, so any level would be initialized as soon as it's loaded. Probably will do some kind of a mix. Like 2 different components, but then the game designer would be able to choose either one at any time. \$\endgroup\$ – Candid Moon _Max_ Aug 24 '18 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.