Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void PullSheet(SheetsServiceProvider sheetsServiceProvider, string spreadSheetId, int sheetId, StringTableCollection targetCollection, IList<SheetColumn> columns) {
- // Setup the connection to Google
- var googleSheets = new GoogleSheets(sheetsServiceProvider) {
- SpreadSheetId = spreadSheetId
- };
- // Update the collection
- googleSheets.PullIntoStringTableCollection(sheetId, targetCollection, columns);
- }
- [MenuItem("Build/Pull Localization")]
- static void PullLocalizationAndCreateTables() {
- var serviceProvider = ScriptableObject.CreateInstance<SheetsServiceProvider>();
- serviceProvider.ApplicationName = "gamescreen";
- serviceProvider.SetApiKey("<removed>");
- var sheetIds = new int[] { 123, 321 };
- var locales = LocalizationEditorSettings.GetLocales();
- for (int i = 0; i < sheetIds.Length; i++) {
- var tableCollection = LocalizationEditorSettings.CreateStringTableCollection($"{sheetIds[i]}", "Assets/Localization");
- var googleSheetsExtension = new GoogleSheetsExtension {
- SheetId = sheetIds[i],
- SheetsServiceProvider = serviceProvider,
- SpreadsheetId = "removed"
- };
- var columns = new List<SheetColumn>();
- var keyColumn = new KeyColumn { ColumnIndex = 0 };
- columns.Add(keyColumn);
- for (int j = 0; j < locales.Count; j++) {
- var table = ScriptableObject.CreateInstance<StringTable>();
- table.SharedData = tableCollection.SharedData;
- table.LocaleIdentifier = locales[j].Identifier;
- table.name = $"{sheetIds[i]}-{locales[j].Identifier}";
- var localeColumn = new LocaleColumn {
- ColumnIndex = j + 1,
- LocaleIdentifier = locales[j].Identifier
- };
- columns.Add(localeColumn);
- }
- // Can't do this
- googleSheetsExtension.Columns = columns;
- tableCollection.AddExtension(googleSheetsExtension);
- PullSheet(serviceProvider, "<remove>", sheetIds[i], tableCollection, columns);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement