Localization parameters don't get translated?
6 years 8 months ago #2962
by rtm223
Localization parameters don't get translated? was created by rtm223
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?
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?
Please Log in or Create an account to join the conversation.
6 years 8 months ago - 6 years 8 months ago #2963
by rtm223
Replied by rtm223 on topic Localization parameters don't get translated?
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.
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 years 8 months ago by rtm223.
Please Log in or Create an account to join the conversation.
6 years 8 months ago #2966
by studenman
Replied by studenman on topic Localization parameters don't get translated?
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!
Hope that helps!
The following user(s) said Thank You: Frank
Please Log in or Create an account to join the conversation.
6 years 8 months ago #2968
by Frank
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:
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:
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.
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!
Replied by Frank on topic Localization parameters don't get translated?
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
Please Log in or Create an account to join the conversation.
6 years 8 months ago - 6 years 8 months ago #2970
by rtm223
Replied by rtm223 on topic Localization parameters don't get translated?
"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?
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: 6 years 8 months ago by rtm223.
Please Log in or Create an account to join the conversation.
6 years 8 months ago #2973
by Frank
Are you Give I2L 5 stars!
Are you Please lets us know how to improve it!
Replied by Frank on topic Localization parameters don't get translated?
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.
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
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
Please Log in or Create an account to join the conversation.
Time to create page: 0.193 seconds