Author Topic: need help about Label with UILocalize  (Read 4567 times)

aofhd15

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
need help about Label with UILocalize
« 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";
    }
}
--------------------

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: need help about Label with UILocalize
« Reply #1 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.

aofhd15

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: need help about Label with UILocalize
« Reply #2 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?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: need help about Label with UILocalize
« Reply #3 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");

aofhd15

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: need help about Label with UILocalize
« Reply #4 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");
            }
   }
}
--------------

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: need help about Label with UILocalize
« Reply #5 on: February 25, 2014, 03:04:05 PM »
You need to update your NGUI.

aofhd15

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: need help about Label with UILocalize
« Reply #6 on: February 26, 2014, 03:05:58 PM »
You need to update your NGUI.

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