Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: aofhd15 on February 23, 2014, 07:49:12 AM

Title: need help about Label with UILocalize
Post by: aofhd15 on February 23, 2014, 07:49:12 AM
Sorry for bad English. I don't live in English-speaking countries.. So can't write English very well.  :'(


I created Label,and included UILocalize Component.
Then I created GameObject that includes c# script.
When I started game, I saw the key in label has changed to "Tm_default2".

but in gamescreen, sentence in Label was showed "nothing".
(default sentence is "nothing".)

However, when I changed Language, then finally changed sentence in Label..to Tm_default2's sentence.
Sentence must be change another sentence when I change the language? It is improper..

I need help about this problem...Please help me.


(c# script that I wrote)
--------------------
using UnityEngine;
using System.Collections;

public class TodayMessage : MonoBehaviour {
    public UILocalize Label;
    void Update ()
    {
        int a = 15;
        if(a == 10)
            Label.key ="Tm_default";
        else
            Label.key ="Tm_default2";
    }
}
--------------------
Title: Re: need help about Label with UILocalize
Post by: ArenMook on February 23, 2014, 12:40:51 PM
Changing the key doesn't do anything. You need to tell the script to localize its value after changing the key.

You shouldn't be changing the key at all. The key should remain constant.
Title: Re: need help about Label with UILocalize
Post by: aofhd15 on February 25, 2014, 01:06:17 PM
Changing the key doesn't do anything. You need to tell the script to localize its value after changing the key.

You shouldn't be changing the key at all. The key should remain constant.

{
    Label.key = "Tm_default2";
    Localization.Localize ("Tm_default2");
}

It doesn't work..
Did I write a wrong sentence?
Title: Re: need help about Label with UILocalize
Post by: ArenMook on February 25, 2014, 01:38:14 PM
Localization.Localize is an obsolete function in the current version. Furthermore, it returns a 'string' value of the localized key. In your code you just call it and do nothing with the returned value, which is wrong. To localize text via code, do this:
  1. label.value = Localization.Get("Tm_default2");
Title: Re: need help about Label with UILocalize
Post by: aofhd15 on February 25, 2014, 02:04:24 PM
Localization.Localize is an obsolete function in the current version. Furthermore, it returns a 'string' value of the localized key. In your code you just call it and do nothing with the returned value, which is wrong. To localize text via code, do this:
  1. label.value = Localization.Get("Tm_default2");

Scripts got two errors....
I'll add my script below. I've changed some little things.

--------------
An object reference is required to access non-static member 'Localization.Get(String)'
The name 'label' does not exist in the current context
--------------

--------------
using UnityEngine;
using System.Collections;

public class TodayMessage : MonoBehaviour {
   public UILocalize Label;
   void changekey ()
   {
      int a = 15;
      if (a == 10)
      {
         Label.key = "Tm_default2";
         label.value = Localization.Get("Tm_default2");
            }
      else
      {
         Label.key = "Tm_default";
         label.value = Localization.Get("Tm_default");
            }
   }
}
--------------
Title: Re: need help about Label with UILocalize
Post by: ArenMook on February 25, 2014, 03:04:05 PM
You need to update your NGUI.
Title: Re: need help about Label with UILocalize
Post by: aofhd15 on February 26, 2014, 03:05:58 PM
You need to update your NGUI.

Thanks Aren!!! ㅠㅠ It solved!!!