Welcome, Guest
Username: Password: Remember me

TOPIC: Automating a google sheets import

Automating a google sheets import 2 weeks 4 days ago #2587

Hello!

I'm using i2 localization with the google sheets sync and want to make it part of our nightly build process. The idea is to run the import from sheets->unity from a command line (and then check in the resulting changes) so it's always up to date. Yes, I know about the auto sync option but for various reasons that's not ideal.

However I can't see a way to do this from just a script. Is there an API call I can make to do a sheets->unity sync (with 'replace' preferably, but 'merge' would also be ok).

Thanks.
The administrator has disabled public write access.

Automating a google sheets import 2 weeks 4 days ago #2588

  • Frank
  • Frank's Avatar
  • Offline
  • Administrator
  • Posts: 915
  • Thank you received: 196
  • Karma: 58
Hi,

The code that runs when you click the Import button is in:
assets\i2\localization\scripts\editor\localization\localizationeditor_spreadsheet_google.cs
function Import_Google at line 423

You could select the source and call that function, or alternatively, run the internal query by using:
        IEnumerator SyncSource()
        {
            LocalizationManager.UpdateSources(); // ensures the source is loaded
            var source = LocalizationManager.Sources[0];
            var www = source.Import_Google_CreateWWWcall(true);
            yield return www;

            if (string.IsNullOrEmpty(www.error))
            {
                source.Import_Google_Result(www.text, eSpreadsheetUpdateMode.Replace);
            }
        }

// call from your code using this:
            I2.Loc.CoroutineManager.Start(SyncSource());

Please, notice, that if you are executing that call from the Editor (not play mode), a normal coroutine will not work. But I2.Loc.CoroutineManager has code to simulate a coroutine by using the EditorApplication.update event.

That way, that code will work in both the editor and in-game.

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
Last Edit: 2 weeks 4 days ago by Frank.
The administrator has disabled public write access.
Time to create page: 0.465 seconds
Colors