Welcome, Guest
Username: Password: Remember me

TOPIC: Localization parameters don't get translated?

Localization parameters don't get translated? 6 months 8 hours ago #2962

  • rtm223
  • rtm223's Avatar
  • Offline
  • New Member
  • Posts: 5
  • Karma: 0
Hi, I'm trying to fit together a system where my UI displays a level and a class, i.e. "Elite Archers".

I have a format string term that looks like
"{[LEVEL]} {[CLASS]}"

And am trying to inject the terms for "Elite" and "Archers" into the parameter manager.

setting the parameters to localization terms is not working, for example?
LEVEL = "UPGRADES/ELITE/NAME"
CLASS = "UPGRADES/ARCHER/CLASS"

It seems that parameters can only be used for non-localized strings, which makes them very limited. How can I localize parameters in a robust way?
The administrator has disabled public write access.

Localization parameters don't get translated? 6 months 7 hours ago #2963

  • rtm223
  • rtm223's Avatar
  • Offline
  • New Member
  • Posts: 5
  • Karma: 0
It also seems that at least half the time, setting parameters using script simply fails to update the localized text at all, and I'm left with just the raw term "{[LEVEL]} {[CLASS]}".

What are the rules for when parameters get applied? I'm trying to set up very, very basic UI widgets, so I'm not sure what's going wrong.

I've followed all the instructions that exist in the docs, and have "Force Localize" checked.
Last Edit: 6 months 7 hours ago by rtm223.
The administrator has disabled public write access.

Localization parameters don't get translated? 5 months 4 weeks ago #2966

  • studenman
  • studenman's Avatar
  • Offline
  • Senior Member
  • Posts: 62
  • Thank you received: 1
  • Karma: 1
This should be pretty easy to debug, just put a breakpoint in LocalizationManager.TryGetTranslation() and see why it's not calling ApplyLocalizationParams()

Hope that helps!
Follow Tiny Bubbles Development:
Twitter | Facebook | Web
The administrator has disabled public write access.
The following user(s) said Thank You: Frank

Localization parameters don't get translated? 5 months 4 weeks ago #2968

  • Frank
  • Frank's Avatar
  • Offline
  • Administrator
  • Posts: 1129
  • Thank you received: 241
  • Karma: 70
It seems that parameters can only be used for non-localized strings

Up to now, parameters don't are just replaced into the final string. Because there is no context about them, I2L can't figure out if they need to be translated or not (they can be Names, Locations and other texts that shouldn't be translated)

So far the way to handle translations of parameters has been to query it in the script:
     public virtual string GetParameterValue( string ParamName )
     {
           if (ParamName == "LEVEL")
               return LocalizationManager.GetTermTranslation("UPGRADES/ELITE/NAME");

           return null; // not found is defined null, not ""
     }

Said that, I like the idea of allowing parameters to be auto translated.

What do you think if we modify the code so that before parameters are injected into the translation, they check if there is a term with that text, if there isn't the parameter is injected, but if there is, then the translation is injected instead.

For example:
You have a term: MY_ITEM0 {English:"Arrow"}
and a term "MY_TEXT" {English: "Player {[NAME]} got an {[ITEM}]"

If you setup your params function to be:
     public virtual string GetParameterValue( string ParamName )
     {
           if (ParamName == "NAME")
               return "Frank";
           if (ParamName == "ITEM")
               return "MY_ITEM_0";
           return null; // not found is defined null, not ""
     }

Then the final translation of MY_TEXT will be "Frank got an Arrow".

I will think a bit about the other implications of this approach, but I think it will solve both cases without introducing too much overhead given that looking up for the parameter's term is a dictionary lookout which is fast.
What are the rules for when parameters get applied?

Parameters are applied in the LocalizationManager.ApplyLocalizationParams which is called from the OnLocalize function of Localize.cs.

Basically the only rules that will prevent that code to be executed are:
- There isn't a primary or secondary term assigned to the localize component (and there is no callback setup)
- The component or gameobject is disabled in the hierarchy.
- You are trying to relocalize to the same language without forcing it.

If you are changing the parameters at runtime after the UI is visible (i.e. its OnEnable has been called already), then you will need to force localize it.

You can do that by either:
1- Disable and Reenable the UI
or
2- Call LocalizationManager.DoLocalizeAll(true) or label.GetComponent<Localize>().OnLocalize(true);

hope that helps,
Frank
Are you :-) Give I2L 5 stars!
Are you :-( Please lets us know how to improve it!
To get the betas as soon as they are ready, check this out
The administrator has disabled public write access.

Localization parameters don't get translated? 5 months 4 weeks ago #2970

  • rtm223
  • rtm223's Avatar
  • Offline
  • New Member
  • Posts: 5
  • Karma: 0
"The component or gameobject is disabled in the hierarchy."

Sorry, but why is this the case? I want to set the text in my UI before enabling it, so it's displaying the correct things when it becomes visible. I can set the localization terms at this point, so it seems that I should be able to set the parameters?

Similarly, you're saying that parameters can't get applied while the gameobject is disabled, but also that if I apply them after enabling, then I have to do an additional force localize? Seems very strange, especially as I've got the force localize box checked.

So again, sorry if I seem dumb, but I kind of need to know the correct order of calls to make, assuming that I want to:

- send a values to the Localize.Term
- send a value to the LocalizationParameterManager.SetParam()
- make the ui visible.

(I will look further into the translation of paramter things tomorrow)


UPDATE: As for putting a breakpoint, it seems that parameters DONT get applied when the LocalizationParamsManager() calls loc.OnLocalize()?? Which is the opposite of what I would expect.

This calls through to LocalizationManager.GetTraslation(finalTerm, false); which defaults apply parameters to false and so of course the parameters are not applied. Is this a bug?
Last Edit: 5 months 4 weeks ago by rtm223.
The administrator has disabled public write access.

Localization parameters don't get translated? 5 months 4 weeks ago #2973

  • Frank
  • Frank's Avatar
  • Offline
  • Administrator
  • Posts: 1129
  • Thank you received: 241
  • Karma: 70
Hi,
The change to only filter out ParamManagers when the component is disabled (independently of the GameObject been enabled/disabled) is available in v2.8.6a3 in the beta folder.
assuming that I want to:

- send a values to the Localize.Term
- send a value to the LocalizationParameterManager.SetParam()
- make the ui visible.

That sequence of steps will work.
Because you are not actually localizing when the object is disabled. What you are doing is setting the term and the parameters.
then, only when the UI becomes visible, the OnLocalize method will be called which takes the term and the parameters and sets the final translation in the label's text.

What will require you manually calling the OnLocalize(true) is if you do this:

- Enable UI
- Set Term, Set Param
- here you have to call label.OnLocalize(true);

Also, notice that if you change the Term, it will call the OnLocalize directly, so, if you set the param before calling SetTerm, it will work fine as well:

- Enable UI
- SetParam
- label.SetTerm(..) -> this calls OnLocalize(true) internally

But as you pointed, the best is to setup everything and then enable the UI
- SetParam
- label.SetTerm(..)
- label1.SetTerm(...)
- label2.SetTerm(..)
- Enable UI

That way, none of the SetTerm call will do OnLocalize, and only when you enable the UI, all of them gets localized at the same time.

Hope that helps,
Frank
Are you :-) Give I2L 5 stars!
Are you :-( Please lets us know how to improve it!
To get the betas as soon as they are ready, check this out
The administrator has disabled public write access.
Time to create page: 0.167 seconds
Colors