Finding all text labels in a scene


In an effort to localise a game which is being published for iOS and Android, I’d like to get all of the strings from the CMS.

The best possible way I can see this working, is naming my labels with something like “COPY_TITLE”, “COPY_DESCRIPTION”, “COPY_INTRO”, and so on.
These labels could then have whatever values at build time, but then at runtime, when we get new values from the CMS, I’d my initial setup to just iterate through every single label in the scene, active or non-active, and see if its name contains “COPY_”. If so, find the matching value to that key, in the data received from the CMS.

Is there a way of doing this, or perhaps a different/better way of going about it?

I’m using Unity 5 PRO, if it helps.


By labels you mean the GUI.Label or UI Text or …? If UI Text, then what you want is this:

    Text[] yourLabels = FindObjectsOfType<Text>();
    foreach (Text someLabel in yourLabels)
        //do here whatever you need

If you’re using GUI.Label then you could simply use your source of strings directly? E.g. if it would be a list/array:

    GUI.Label(new Rect(10, 10, 100, 20), yourSourceOfStrings[4]);//or whichever one this label should be using

As for the different/better way I’d suggest you firstly to go through FREE Localizations out THERE and check their code, maybe you wouldn’t even want to do your own localization after that in first place.