Is there any scripting api?

More
4 years 3 months ago #466 by InkHawk
I need 2 features:
1. String format, a lot of time the text is not only just text, it also contains data.
for example:
String.Format("This talent called {0}, it deals {1} damage.",talentName,damage);
Any easy way to do this?

2. Any way to load spread sheet dynamicly? For support mods, I would like the moders can create mods without unity. Therefor I need a way to load the mod texts on fly.

Thank you

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

More
4 years 3 months ago #467 by InkHawk
Replied by InkHawk on topic Is there any scripting api?
BTW, I'm using uGUI

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

More
4 years 3 months ago #468 by Frank
Replied by Frank on topic Is there any scripting api?

1. String format, a lot of time the text is not only just text, it also contains data.
for example:
String.Format("This talent called {0}, it deals {1} damage.",talentName,damage);
Any easy way to do this?


If you are accessing the translation from an script, you could do:

string text = I2.Loc.ScriptLocalization.Get("MyKEY"); // e.g. "This talent called {0}, it deals {1} damage."
string newText = String.Format(text,talentName,damage);


However, I2 Localization provides a way to automatize that by allowing to modify the translations by using callbacks.
Check this out:
forum.unity3d.com/threads/i2-localizatio.../page-2#post-1880413
www.inter-illusion.com/forum/i2-localiza...ctly-from-scripts#55

The basic idea is that you can assign a Localize component to the Text object and set it to call a function whenever it gets a translation assigned. You can then, modify the translation as you need, which allows you having parameters.
For example:

public void OnModifyLocalization()
{
if (string.IsNullOrEmpty(Localize.MainTranslation))
return;

Localize.MainTranslation = Localize.MainTranslation.Replace("{PLAYER_NAME}", PlayerName);
}

The most common usage of this is to create a function that replaces ALL your parameters (PLAYER_NAME, SCORE, COINS, etc) Then whenever you need to translate something with parameters, you just assign that function as the callback.

The Example scene "UnityStandard Localization" contains a text that uses callbacks.

2. Any way to load spread sheet dynamicly? For support mods, I would like the moders can create mods without unity. Therefor I need a way to load the mod texts on fly.


LanguageSource source = LocalizationManager.Sources[0];

string CSVstring = LocalizationReader.ReadCSVfile (FileName);

string sError = source.Import_CSV( string.Empty, CSVstring, eSpreadsheetUpdateMode.Replace);


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.212 seconds
Template by JoomlaShine