Saving the database in runtime

More
7 years 7 months ago #2197 by KimAndersenGF
Hi Frank,

I am working a game where the Localization asset is playing a big role.
And i would like to know if i can save the database during the game?

I know how to change the content in the database. I am using:
I2.Loc.LocalizationManager.Sources [0].AddTerm(myNewTerm,I2.Loc.eTermType.Text, true);
And i know how to save the changes in the editormode:
UnityEditor.EditorUtility.SetDirty (I2.Loc.LocalizationManager.Sources [0]);
UnityEditor.AssetDatabase.SaveAssets ();

But this does not write to the disk in runtime mode.
Is possible at all?
Or should i make an export from unity to an extern file, and then import the file when i start the application?
The platform is a standalone player for mac and pc.
Hope you can help?

Regards Kim Andersen

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

More
7 years 7 months ago #2200 by Frank
Hi,
If you need to save changes you made to the localization at runtime, you will have to manage it with a custom script.
You can change the localization, then export the source into CSV or better I2CSV and save that to PlayerPrefs or write directly to a file.
Then everytime the game starts, you should read it back and import back to the source.

You can do something like this:
        // Make your changes
        I2.Loc.LocalizationManager.Sources [0].AddTerm(myNewTerm,I2.Loc.eTermType.Text, true);

        // save the changes
        string data = I2.Loc.LocalizationManager.Sources[0].Export_I2CSV(null);   // null means, save all categories
        PlayerPrefs.SetString("CustomLocalization", data);

Then you should have a script that reads it back when the game starts:
public void Start()
{
     string data = PlayerPref.GetString("CustomLocalization", string.Empty);
     if (!string.IsNullOrEmpty(data))
     {
           I2.Loc.LocalizationManager.Sources[0].Import_I2CSV(data);
           I2.Loc.LocalizationManager.Sources[0].UpdateDictionary(true);
           I2.Loc.LocalizationManager.LocalizeAll(true);
     }
}

Be aware that doing this, overrides the Google Live Synchronization and so the data downloaded from google will be overwritten.
If you want to still synchronize automatically with Google Spreadsheets, you should create a second LanguageSource (e.g. I2LanguagesCustom.prefab) and add it to the GlobalSources array of the LocalizationManager so that it gets loaded automatically:
public static string[] GlobalSources = {"I2Languages", "I2LanguagesCustom"};

Then, you can do the changes in the second LanguageSource (I2.Loc.LocalizationManager.Sources[1]) while the first one still synchronizes from google.

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