Hello Guest

Author Topic: Localization friendly dialog boxes?  (Read 7469 times)

test84

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Localization friendly dialog boxes?
« on: April 17, 2014, 11:10:03 pm »
Hi,

I need to have two versions of texts for dialog boxes (and preferably buttons), one in English and one in Arabic but I don't need to have them all at the same build. I currently have everything in English and for sake of simplicity of Unicode handling, I will draw text boxes in Photoshop as handling Unicode is hell in Unity, at least as I've researched.

So is there any way to have both of these versions of arts of dialog boxes available and swap them with a change language button? If not, it will still be good enough if I can put a compiler directive or something to let me define which language I want to build for and then have some #IF's in compile time to decide which version to load?

Hope I made myself clear enough, if not, please let me know and I'll put it in another word.

Cheers.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Localization friendly dialog boxes?
« Reply #1 on: April 18, 2014, 05:12:39 am »
No there isn't an official way to do this. You could probably hijack the platform collections feature to handle this, by creating a new platform with 1.0 scale, and a name like @arabic.
tk2dSystem.assetPlatforms is where you'd do this.

I have to reiterate this is officially unsupported though.

test84

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Re: Localization friendly dialog boxes?
« Reply #2 on: April 23, 2014, 01:38:44 pm »
Thanks. I found how to add a 1x platform but how can I name it?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Localization friendly dialog boxes?
« Reply #3 on: April 23, 2014, 01:58:08 pm »
tk2dSystem.assetPlatforms - that array keeps a list of things + names, you can rename "2x" to arabic with scale of 1.0f, that will mean that files ending with @arabic will be treated as a swap.

test84

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Re: Localization friendly dialog boxes?
« Reply #4 on: April 23, 2014, 05:50:16 pm »
Thanks.

I can't get my head around the platform specific sprite collection for this. I've read the documentation numerous times but can't get it right.

What I don't understand is that we create sprite collections by adding files form different locations to the sprite collection window in Unity and when we change the sprite collection via script, for each sprite it goes to corresponding folder and looks for the one with the designated suffix, i.e. @2x? If it is, then I can't get it to work and please elaborate.

Also does it ever search for @1x?

Thanks.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Localization friendly dialog boxes?
« Reply #5 on: April 24, 2014, 10:20:20 am »
When you set tk2dSystem.CurrentPlatform, any subsequently loaded sprite collections will load that platform. You should ideally do this at the start of the game, and not switch it mid game as it will not reload collections that have already been loaded.

For each sprite in your collection you should have a corresponding platform collection. So if your sprite name is test.png, and your default platform is 1x - you should have test@2x.png if you add a 2x platform. The default platform file can also be test@1x.png. All of this is documented here: http://2dtoolkit.com/docs/latest/advanced/platform_specific_sprite_collections.html

Basically, when you commit this collection - it creates multiple collections in parallel, one for each defined platform. At runtime, it loads the correct collection - it doesn't actually care about source files then.

test84

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Re: Localization friendly dialog boxes?
« Reply #6 on: April 24, 2014, 03:46:19 pm »
Thanks for the detailed info but I'm afraid to say that I still cannot make it work. Here are steps that I've done:

0- Went inside tk2dSystem.assetPlatforms and renamed 2x to "fa".

1- Created two png files one named "CantEquipMoreThan3PowerUps_Overlay@1x.png" and another called "CantEquipMoreThan3PowerUps_Overlay@fa.png".

1- Created a new sprite collection added support for platforms, and added my "fa" to it.

2- Then I grabbed one of the "CantEquipMoreThan3PowerUps_Overlay@1x.png" to the sprite collection, created a script and in it's start wrote "tk2dSystem.CurrentPlatform = "fa";" and attached it to an empty game object and put it in an empty scene.

3- I run the game and expect it to load the "fa" version automatically, but it shows the default "1x" one.

What am I missing?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Localization friendly dialog boxes?
« Reply #7 on: April 24, 2014, 05:21:22 pm »
How many platforms do you have in total?
Does it work if you switch it in the 2D Toolkit preferences panel?


test84

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Re: Localization friendly dialog boxes?
« Reply #8 on: April 24, 2014, 08:00:37 pm »
I have two, "1x" and "fa".

Yes it does work in preferences panel.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Localization friendly dialog boxes?
« Reply #9 on: April 24, 2014, 08:57:37 pm »
If it doesn't change at runtime, it means you're not setting it before the collection loads. You should debug that to work out when its happening.

test84

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Re: Localization friendly dialog boxes?
« Reply #10 on: April 26, 2014, 12:15:20 pm »
Thanks, changing it in an empty scene that doesn't have any tk2d stuff in it and then transiting to the actual game scene did it.

test84

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Re: Localization friendly dialog boxes?
« Reply #11 on: April 27, 2014, 02:03:35 pm »
There is a hidden bug that is driving me mad. Sometimes it doesn't work and I just have to restart Unity to make it work. The change of current platform via code seems to either get lost or not affect the sprite collections. I try to edit a lot of things to make it work and it doesn't and I restart Unity and it works. I can't reproduce it to help any further.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Localization friendly dialog boxes?
« Reply #12 on: April 27, 2014, 06:46:30 pm »
If Unity thinks an asset has changed it will not unload it, and as a result will not reload it. tk2d doesn't affect it, but it could possibly happen if its committed and not saved - unity defers saving until you quit unity / save another scene, but other things could trigger it too.

The platform switching code in preferences wlil force a reload, but the runtime code behaves exactly like it will at runtime, i,.e. it will not force reload everything thats already loaded. If you want it to force a reload regardless, you have the code, you can switch it around if you like.