Method PushStringTableCollection
PushStringTableCollection(int, StringTableCollection, IList<SheetColumn>, ITaskReporter)
Extracts data from collection
using columnMapping
and sends it to the sheet
inside of the Spreadsheet with id Spread
Declaration
public void PushStringTableCollection(int sheetId, StringTableCollection collection, IList<SheetColumn> columnMapping, ITaskReporter reporter = null)
Parameters
Type | Name | Description |
---|---|---|
int | sheetId | The sheet(Spreadsheet tab) to insert the data into. |
String |
collection | The collection to extract the data from. |
IList<Sheet |
columnMapping | The column mappings control what data will be extracted for each column of the sheet. The list must contain 1 Key |
ITask |
reporter | Optional reporter to display the progress and status of the task. |
Examples
A String
[MenuItem("Localization/Google Sheets/Push English")]
public static void PushEnglish()
{
// Setup the connection to Google. You will need a preconfigured SheetsServiceProvider asset.
var sheetServiceProvider = AssetDatabase.LoadAssetAtPath<SheetsServiceProvider>("Assets/Sheets Service Provider.asset");
var googleSheets = new GoogleSheets(sheetServiceProvider);
googleSheets.SpreadSheetId = "My spread sheet id"; // We need to provide the Spreadsheet id. This can be found in the url. See docs for further info.
// Prepare the data we want to push.
// You should provide your String Table Collection name here
var tableCollection = LocalizationEditorSettings.GetStringTableCollection("My Strings");
// We need configure what each column will contain in the sheet
var columnMappings = new SheetColumn[]
{
// Column A will contain the Key
new KeyColumn { Column = "A" },
// Column B will contain any shared comments. These are Comment Metadata in the Shared category.
new KeyCommentColumn { Column = "B" },
// Column C will contain the English Locale and any comments that are just for this Locale.
new LocaleColumn { Column = "C", LocaleIdentifier = "en", IncludeComments = true },
};
int mySheetId = 123456; // This it the id of the sheet in the Google Spreadsheet. it will be in the url after `gid=`.
// Now send the update.
googleSheets.PushStringTableCollection(mySheetId, tableCollection, columnMappings);
}
This example shows how to push all the locales in your project by using Column
[MenuItem("Localization/Google Sheets/Push Project Locales")]
public static void PushProjectLocales()
{
// Setup the connection to Google. You will need a preconfigured SheetsServiceProvider asset.
var sheetServiceProvider = AssetDatabase.LoadAssetAtPath<SheetsServiceProvider>("Assets/Sheets Service Provider.asset");
var googleSheets = new GoogleSheets(sheetServiceProvider);
googleSheets.SpreadSheetId = "My spread sheet id"; // We need to provide the Spreadsheet id. This can be found in the url. See docs for further info.
// Prepare the data we want to push.
// You should provide your String Table Collection name here
var tableCollection = LocalizationEditorSettings.GetStringTableCollection("My Strings");
// CreateDefaultMapping will create a KeyColumn and a LocaleColumn for each Locale in the project.
var columnMappings = ColumnMapping.CreateDefaultMapping();
int mySheetId = 123456; // This is the id of the sheet in the Google Spreadsheet. it will be in the url after `gid=`.
// Now send the update. We can pass in an optional ProgressBarReporter so that we can see updates in the Editor.
googleSheets.PushStringTableCollection(mySheetId, tableCollection, columnMappings, new ProgressBarReporter());
}
This example shows how to use the data that was configured in the Google
[MenuItem("Localization/Google Sheets/Push With Google Extension")]
public static void PushWithExtension()
{
// You should provide your String Table Collection name here
var tableCollection = LocalizationEditorSettings.GetStringTableCollection("My Strings");
var googleExtension = tableCollection.Extensions.FirstOrDefault(e => e is GoogleSheetsExtension) as GoogleSheetsExtension;
if (googleExtension == null)
{
Debug.LogError($"String Table Collection {tableCollection.TableCollectionName} Does not contain a Google Sheets Extension.");
return;
}
PushExtension(googleExtension);
}
static void PushExtension(GoogleSheetsExtension googleExtension)
{
// Setup the connection to Google
var googleSheets = new GoogleSheets(googleExtension.SheetsServiceProvider);
googleSheets.SpreadSheetId = googleExtension.SpreadsheetId;
// Now send the update. We can pass in an optional ProgressBarReporter so that we can updates in the Editor.
googleSheets.PushStringTableCollection(googleExtension.SheetId, googleExtension.TargetCollection as StringTableCollection, googleExtension.Columns, new ProgressBarReporter());
}
This example shows how to push every String
[MenuItem("Localization/Google Sheets/Push All Google Sheets Extensions")]
public static void PushAllExtensions()
{
// Get every String Table Collection
var stringTableCollections = LocalizationEditorSettings.GetStringTableCollections();
foreach (var collection in stringTableCollections)
{
// Its possible a String Table Collection may have more than one GoogleSheetsExtension.
// For example if each Locale we pushed/pulled from a different sheet.
foreach (var extension in collection.Extensions)
{
if (extension is GoogleSheetsExtension googleExtension)
{
PushExtension(googleExtension);
}
}
}
}