#That s the part I m lost with
1 messages · Page 1 of 1 (latest)
I would use a ChooseFormatter for this. You can then add a translation for each language as a single field instead of having to put it all together at the end.
Then pass the date in as an integer using a persistent variable https://docs.unity3d.com/Packages/com.unity.localization@1.4/manual/Smart/Persistent-Variables-Source.html
¿Could you develop that further? I've never used chooseFormatter, and, don't really know how to get it working either :/
But, thanks fort those links! I'm gonna read 'em out!
You would create a single entry in the string table. Mark it smart with the toggle. Then do something like "The day is {myDateVariable:choose(1|2|3|4|5):Mon|Tue|Wed|Thur|Fri}"
That would be your English entry
Then for the others you just copy it and and replace the English translations
Then add a LocalizedString to your script as a public variable
In the inspector, Set it to point to the table entry and add a local variable of type integer to it, name it myDateVariable
Now you can change its value and the date will update. You can press the Preview button in the inspector for the localized string to test it
Ok! Let me try it out.
There's some more scripting examples on using a localized string here https://docs.unity3d.com/Packages/com.unity.localization@1.3/api/UnityEngine.Localization.LocalizedString.html
One question: Could I add this to a Struct?
The localized string? Yeah
It seems I can't :/
public LocalizedString localizedString = null; Just so it doesnt' bother me with having to set it a value after going back.
Don't do the null part
If I don't, it gives me this error: "Field 'DateTime.localizedString' must be fully assigned before control is returned to the caller", That's why I set it to null
For a littler more of insight, this is the script I'm trying to add it to.
And, because of that error, I can't set it in the inspector.
Initialize it in the struct constructor
Ok, I've added it to the inspector, added to my date's tmpro a localized string event, pointed it to the same table, and now I'm getting this error: FormattingException: Error parsing format string: You cannot specify more than 2 choices at 38 {myDateVariable:choose(1,2,3,4,5,6,7):Mon|Tue|Wed|Thu|Fri|Sat|Sun}
Oh yes I had a typo in my example. It should be separated with| not ,
I edited the message to fix it
Oh, ok, sorry
Sorry for bothering again, but, is this the correct way to update the variable? if (Days == 0) TimeManager.localizedString.myDateVariable = 0;
Can't really wrap my head around all of this, thank you for trying to help me anyways, I'll keep trying to get this working :p
Something like
var date = localizedString["myDateVariable"] as IntegerVariable;
date.Value = 1;
If days is an enum then you should be able to cast it as an int.
E.g
date.Value = (int)Days;
Yeah, but, both my DateToString() void and my Days enum are inside of the DateTime struct.
I just wrote a rough short version. I'm on my phone, it's hard to write code 😉
Don't worry, thanks!