docs.unity3d.com

Localization 1.5.1

Search Results for

    Show / Hide Table of Contents

    Method PullIntoStringTableCollection

    PullIntoStringTableCollection(int, StringTableCollection, IList<SheetColumn>, bool, ITaskReporter, bool)

    Pulls data from the Spreadsheet with id SpreadSheetId and uses columnMapping to populate the collection.

    Declaration
    public void PullIntoStringTableCollection(int sheetId, StringTableCollection collection, IList<SheetColumn> columnMapping, bool removeMissingEntries = false, ITaskReporter reporter = null, bool createUndo = false)
    Parameters
    Type Name Description
    int sheetId

    The sheet(Spreadsheet tab) to pull the data from.

    StringTableCollection collection

    The collection to insert the data into.

    IList<SheetColumn> columnMapping

    The column mappings control what data to extract for each column of the sheet. The list must contain one IPullKeyColumn.

    bool removeMissingEntries

    After a pull has completed, any keys that exist in the collection but did not exist in the sheet are considered missing, this may be because they have been deleted from the sheet. A value of true will remove these missing entries; false will preserve them.

    ITaskReporter reporter

    Optional reporter to display the progress and status of the task.

    bool createUndo

    Should an Undo be recorded so any changes can be reverted?

    Examples

    A StringTableCollection can exist over several Google Sheets, for example one per Locale. This example shows how to pull one of those Locales into a StringTableCollection.

    [MenuItem("Localization/Google Sheets/Pull English")]
    public static void PullEnglish()
    {
        // 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.
    
        // You should provide your String Table Collection name here
        var tableCollection = LocalizationEditorSettings.GetStringTableCollection("My Strings");
    
        // We need configure what each column contains in the sheet
        var columnMappings = new SheetColumn[]
        {
            // Column A contains the Key
            new KeyColumn { Column = "A" },
    
            // Column B contains any shared comments. These are Comment Metadata in the Shared category.
            new KeyCommentColumn { Column = "B" },
    
            // Column C contains 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=`.
        googleSheets.PullIntoStringTableCollection(mySheetId, tableCollection, columnMappings);
    }

    This example shows how to pull all the locales in your project by using the ColumnMapping to generate the column mapping data for you.

    [MenuItem("Localization/Google Sheets/Pull Project Locales")]
    public static void PullProjectLocales()
    {
        // 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.
    
        // 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.
        // This assumes that the table was created and pushed to using the same column mappings.
        var columnMappings = ColumnMapping.CreateDefaultMapping();
        int mySheetId = 123456; // This it the id of the sheet in the Google Spreadsheet. it will be in the url after `gid=`.
    
        // Now pull.
        // removeMissingEntries will remove any Keys that we have in the String Table Collection that do not exist in the Pull update.
        // reporter is an optional reporter that can be used to povide feedback in the editor during the Pull.
        googleSheets.PullIntoStringTableCollection(mySheetId, tableCollection, columnMappings, removeMissingEntries: true, reporter: new ProgressBarReporter());
    }

    This example shows how to use the data that was configured in a Google Sheets extension to perform a pull.

    [MenuItem("Localization/Google Sheets/Pull With Google Extension")]
    public static void PullWithExtension()
    {
        // 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;
        }
    
        PullExtension(googleExtension);
    }
    
    static void PullExtension(GoogleSheetsExtension googleExtension)
    {
        // Setup the connection to Google
        var googleSheets = new GoogleSheets(googleExtension.SheetsServiceProvider);
        googleSheets.SpreadSheetId = googleExtension.SpreadsheetId;
    
        // Now update the collection. We can pass in an optional ProgressBarReporter so that we can updates in the Editor.
        googleSheets.PullIntoStringTableCollection(googleExtension.SheetId, googleExtension.TargetCollection as StringTableCollection, googleExtension.Columns, reporter: new ProgressBarReporter());
    }

    This example shows how to pull every StringTableCollection that contains a GoogleSheetsExtension.

    [MenuItem("Localization/Google Sheets/Pull All Google Sheets Extensions")]
    public static void PullAllExtensions()
    {
        // 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)
                {
                    PullExtension(googleExtension);
                }
            }
        }
    }
    In This Article
    • PullIntoStringTableCollection(int, StringTableCollection, IList<SheetColumn>, bool, ITaskReporter, bool)
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)