translation of a dynamic content of dfgui label

More
10 years 5 months ago #161 by UnikatBike
Hi,
I have a label of dfgui where the content is changing from time to time. the translation string is at start for examble lblText1001. After button clicks it could be lbl2004 or 3006. So, I have 200 different strings which could be visible on this one label.
Any idea what to do?
thanks in advance

Please Log in or Create an account to join the conversation.

More
10 years 5 months ago #163 by Frank
Hi
Sorry for the lack of supports this last week. I was out on vacations and coudn't connect as often as I would like it.

You could do it in two main ways:

1- Don't assign a localize component to the label and instead everytime the user clicks the button, assign the text already translated to the label. So, it becomes something like:
void OnClick()
{
     string Text = "RAL6018";
     MyLabel.text = I2.Loc.ScriptLocalization.Get("lbl" + Text);   // This will find the key "lblRAL6018" and show the translation
}

2- Assign a localize component to the label, and whenever the user clicks the button, change the Localize.Term and allow the Localize component to do the localization.
void OnClick()
{
     string Text = "RAL6018";
     I2.Localize LocalizeCmp = MyLabel.GetComponent<I2.Localize>();
     LocalizeCmp.Term = "lbl" + Text;
     LocalizeCmp.OnLocalize();
}

This second way will allow you to also automatically translate fonts depending on the language.

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.

More
10 years 5 months ago - 10 years 5 months ago #165 by UnikatBike
Hi Frank,
thank you for the answer. Hope your vacation was fine.

I tried this already, but it doesn't give me the expected result.

The button name (which is the key text is stored in a variable KeyText.
If I set 'dfLabel.Text = KeyText' I can se on the label the correct Keytext: lblRAL1007 or whatever.
If I set dfLabel.Text = I2.Loc.ScriptLocalization.Get(KeyText); it doesn't show me the text. only blank label which is coloured by the pressed color button..
The result you can see at the two attached images.
Do you have any idea?

This is the script I use:

FrameColorButtonValue = CreateFrameColorButton.FrameColorNumber;

//Key for Translation
KeyText = "lbl" + FrameColorButtonValue; // has the right value
Label.Text = I2.Loc.ScriptLocalization.Get(KeyText); //doesn't show anything
Label.BackgroundSprite = FrameColorButtonValue; // setting the colour of label, works perfectly



Attachment LabelwithTranslation.png not found

Attachments:
Last edit: 10 years 5 months ago by UnikatBike. Reason: some more information

Please Log in or Create an account to join the conversation.

More
10 years 5 months ago #167 by Frank
Hi,
The code you posted should work as far as the source is accessible and has the keys in.

Could you check this two things:

1- The key that its concatenated exists in the LanguageSource.
You can place a Debug.Log to see in the console the key you got and then verify that against the keys in the source.
Be aware that keys have to be exactly the same: i.e. "lblRAL1000" its not the same than "lblral1000"or "lblRAL1000 ". That seems obvious but you will be surprised how many times I have had to track an space at the end of the Terms.
KeyText = "lbl" + FrameColorButtonValue;
Label.Text = I2.Loc.ScriptLocalization.Get(KeyText);

Debug.Log(KeyText + " " + Label.Text);   // This will print to the console the key and translation in case the Label.Text gets modified later on

Label.BackgroundSprite = FrameColorButtonValue;

2- Check that LanguageSource is available. Your LanguageSource should be added to one of the objects in your scene or prefferably, it should be the I2Languages.prefab
If you are adding all your terms to the I2Languages.prefab. Check that prefab is inside a Resources folder and that there is only one asset named I2Languages.prefab.

Let me know if the issue is one of those things. If not, email me and I will send to you a quick working sample that dynamically gets the translation so that you could see if your project has any setting different or we can chat and further check your project.

Thank,
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.

More
10 years 5 months ago #168 by UnikatBike
Hi Frank,

I checked this all several times, the localization is in, because the inspector show me the terms and the keys are written excactly the same. the debug.log show me only my keyTex Variable and not what is coming from I2.LOC...., so it sems that this wil not find in the project. Is there something that I have to copy from i2 folder to resources?
I just wrote a mail to you with link to dropbox where I stored the project. If you like, please have a look on it.
thank you very much
Holger

Please Log in or Create an account to join the conversation.

More
10 years 5 months ago #169 by Frank
Hi,

I just checked the project and the issue was that the terms are in a category named "Main".
So, when requesting the translation, instead of asking for "lblRAL3018", it should be "Main/lblRAL3018"

In your project, just replace the LabelSelectedFrameColor.cs (line 17) from
		KeyText = "lbl" + FrameColorButtonValue;

into
		KeyText = "Main/lbl" + FrameColorButtonValue;

That will make it work :-)


Also, another thing I noticed is that you have several scenes, and each one of them has the LocalizationSource object with the same terms.

If you want to make terms accessible in ALL scenes, add the terms into the I2/Localization/Resources/I2Languages.prefab
That way you don't need to add the terms into each scene and will save memory well.

Be aware that in your project I2Languages.prefab has been renamed to I2Languages.prefa
So you will have to add the missing "b" for it to work.

BTW, one easy way to move the terms into the I2Languages.prefab is by deleting the LanguageSource component inside that prefab and dragging there the one in your start scene.
Or you can export the one in the scene into an CSV file and then import that file into the prefab.

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 following user(s) said Thank You: UnikatBike

Please Log in or Create an account to join the conversation.

Time to create page: 0.136 seconds
Template by JoomlaShine