Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

For everyone having problem with google sheets not saving

Discussion in 'Localization Tools' started by IroxGames, Jun 16, 2020.

  1. IroxGames

    IroxGames

    Joined:
    Feb 8, 2020
    Posts:
    16
    For everyone having problems with the google sheets not saving:
    This script will fetch all google sheets and insert them in the right string table and SAVE everything afterwards.
    Just put this script into an editor folder and thats it. Then you have the option in the toolbar under Tools/Fetch All Locas to trigger a full fetch and saving process.


    Code (CSharp):
    1. using System.Linq;
    2. using UnityEditor;
    3. using UnityEditor.Localization;
    4. using UnityEditor.Localization.Plugins.Google;
    5. using UnityEditor.Localization.Reporting;
    6.  
    7. namespace IroxGames.Tools
    8. {
    9.     public static class PullAllLocalizationSheets
    10.     {
    11.         [MenuItem("Tools/Fetch All Locas")]
    12.         public static void Fetch()
    13.         {
    14.             foreach (string guid in AssetDatabase.FindAssets($"t: {nameof(StringTableCollection)}"))
    15.             {
    16.                 StringTableCollection tableCollection = AssetDatabase.LoadAssetAtPath<StringTableCollection>(AssetDatabase.GUIDToAssetPath(guid));
    17.  
    18.                 GoogleSheetsExtension sheet = tableCollection.Extensions.FirstOrDefault(extension => extension is GoogleSheetsExtension) as GoogleSheetsExtension;
    19.  
    20.                 if (sheet == null)
    21.                 {
    22.                     continue;
    23.                 }
    24.  
    25.                 GoogleSheets google = new GoogleSheets(sheet.SheetsServiceProvider)
    26.                 {
    27.                     SpreadSheetId = sheet.SpreadsheetId
    28.                 };
    29.                
    30.                 google.PullIntoStringTableCollection(sheet.SheetId, sheet.TargetCollection as StringTableCollection, sheet.Columns, sheet.RemoveMissingPulledKeys, new ProgressBarReporter());
    31.                
    32.                 EditorUtility.SetDirty(tableCollection);
    33.             }
    34.             AssetDatabase.SaveAssets();
    35.         }
    36.     }
    37. }
     
    karl_jones likes this.
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,876
    Hmm I'm not sure this will solve the problem. You only set the collection dirty, you need to also set the tables and shared data dirty.
    However, this issue only actually happens when using Undo, when calling from a script Undo is off by default(its an optional value you can pass in).
    So you only need to set the assets dirty when using Undo, otherwise, we set them dirty for you.
    Its a bug in Unity that causes assets to not become dirty when using Undo.
     
  3. IroxGames

    IroxGames

    Joined:
    Feb 8, 2020
    Posts:
    16
    that's interesting, thanks for that insight!
    This was also meant to be a workaround until it's fixed on your side!
    for our case this works fine :D
     
    karl_jones likes this.
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,876
    We have a fix ready now so it will be in the next release.
    Do you want us to add an option to push/pull all string table collections like you do above?
     
  5. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,876
    Oh by the way you can use LocalizationEditorSettings to get all the string table collection assets instead of using the aseetdatabase.
     
  6. IroxGames

    IroxGames

    Joined:
    Feb 8, 2020
    Posts:
    16
    yes, i think an option to fetch all tables at once would be helpful. For us it happens too often that we change something in multiple sheets and integrating that in ourpipeline before we build is quite useful

    good to know! will change that then!

    looking forward to the next release, really good, lightweight package you've created there!
     
    karl_jones likes this.
  7. Nefahl

    Nefahl

    Joined:
    Feb 20, 2017
    Posts:
    71
    Hello there,
    after working with the package for a while now, my team wanted a "better" way to pull and immediately push tables thereafter if no error arises. So I found your script and though cool somebody already solved this use-case partly.
    now I have the Problem, that we've split our sheets by languages and use different sheets-extensions for the sheets.
    pulling one after the other in inspector works just fine, if I use the snipped above and integrate an foreach(extension in tableCollection.Extensions -> cast them to GoogleSheetsExtension and use the PullIntoStringTableCollection, quite reliably an Assert (Expected sorted entries to match unsorted.) is triggered on an extension in the list, it's not always the same and never was the first so far.
    I first thought okay, seems to be some async-race problem, but as far as I can tell the PullIntoStringTable Collection is a synchronous call, which should wait itself until the request is fully handled, or am I mistaken there?

    In the GoogleSheets.cs there are two nearly similar "errors" regarding the column similarity, one throws an Exception right in the PullIntoStringTableCollection-Function, that one isn't triggered though. The other one is an Assert which part of the following MergePull-Subfunction and that one is triggered. So I guess there is a problem with the merge algorithm when triggering multiple pulls in a short timeframe causing a mismatch when being triggered "too fast". Is there something to wait for that I'm missing?
     
  8. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,876
    Can you please file a bug report?
     
    Nefahl likes this.
  9. Nefahl

    Nefahl

    Joined:
    Feb 20, 2017
    Posts:
    71
    Just reported it: Case 1381229
     
    karl_jones likes this.