Advertisement
Guest User

Untitled

a guest
Nov 10th, 2022
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 KB | None | 0 0
  1. static void PullSheet(SheetsServiceProvider sheetsServiceProvider, string spreadSheetId, int sheetId, StringTableCollection targetCollection, IList<SheetColumn> columns) {
  2.         // Setup the connection to Google
  3.         var googleSheets = new GoogleSheets(sheetsServiceProvider) {
  4.             SpreadSheetId = spreadSheetId
  5.         };
  6.  
  7.         // Update the collection
  8.         googleSheets.PullIntoStringTableCollection(sheetId, targetCollection, columns);
  9.     }
  10.  
  11.     [MenuItem("Build/Pull Localization")]
  12.     static void PullLocalizationAndCreateTables() {
  13.         var serviceProvider = ScriptableObject.CreateInstance<SheetsServiceProvider>();
  14.         serviceProvider.ApplicationName = "gamescreen";
  15.         serviceProvider.SetApiKey("<removed>");
  16.  
  17.         var sheetIds = new int[] { 123, 321 };
  18.         var locales = LocalizationEditorSettings.GetLocales();
  19.         for (int i = 0; i < sheetIds.Length; i++) {
  20.             var tableCollection = LocalizationEditorSettings.CreateStringTableCollection($"{sheetIds[i]}", "Assets/Localization");
  21.             var googleSheetsExtension = new GoogleSheetsExtension {
  22.                 SheetId = sheetIds[i],
  23.                 SheetsServiceProvider = serviceProvider,
  24.                 SpreadsheetId = "removed"
  25.             };
  26.  
  27.             var columns = new List<SheetColumn>();
  28.             var keyColumn = new KeyColumn { ColumnIndex = 0 };
  29.             columns.Add(keyColumn);
  30.  
  31.             for (int j = 0; j < locales.Count; j++) {
  32.                 var table = ScriptableObject.CreateInstance<StringTable>();
  33.                 table.SharedData = tableCollection.SharedData;
  34.                 table.LocaleIdentifier = locales[j].Identifier;
  35.                 table.name = $"{sheetIds[i]}-{locales[j].Identifier}";
  36.                 var localeColumn = new LocaleColumn {
  37.                     ColumnIndex = j + 1,
  38.                     LocaleIdentifier = locales[j].Identifier
  39.                 };
  40.                 columns.Add(localeColumn);
  41.             }
  42.  
  43.             // Can't do this
  44.             googleSheetsExtension.Columns = columns;
  45.  
  46.             tableCollection.AddExtension(googleSheetsExtension);
  47.  
  48.             PullSheet(serviceProvider, "<remove>", sheetIds[i], tableCollection, columns);
  49.         }
  50.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement