docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class LocaleMetadataColumn<TMetadata>

    Provides a column that can be used to synchronize IMetadata for a particular Locale.

    Inheritance
    object
    SheetColumn
    LocaleMetadataColumn<TMetadata>
    LocaleCommentColumn
    Inherited Members
    SheetColumn.Column
    SheetColumn.PushFields
    SheetColumn.ColumnIndex
    SheetColumn.PushHeader(StringTableCollection, out string, out string)
    SheetColumn.IndexToColumnName(int)
    SheetColumn.ColumnNameToIndex(string)
    Namespace: UnityEditor.Localization.Plugins.Google.Columns
    Assembly: Unity.Localization.Editor.dll
    Syntax
    [Serializable]
    public abstract class LocaleMetadataColumn<TMetadata> : SheetColumn where TMetadata : IMetadata
    Type Parameters
    Name Description
    TMetadata
    Examples

    The following example demonstrates how to populate custom metadata into a column.

    [Serializable]
    [DisplayName("Custom Data")]
    [Metadata(AllowedTypes = MetadataType.StringTableEntry)]
    public class MyCustomDataMetadata : IMetadata
    {
        public string someValue;
        public string someNoteValue;
    }
    
    /// <summary>
    /// LocaleMetadataColumn is a version of SheetColumn only used for handling Metadata.
    /// This can now be added to the Column Mappings for any Push or Pull request.
    /// </summary>
    public class MyCustomColumn : LocaleMetadataColumn<MyCustomDataMetadata>
    {
        public override PushFields PushFields => PushFields.ValueAndNote; // For our example we use both value and note.
    
        public override void PullMetadata(StringTableEntry entry, MyCustomDataMetadata metadata, string cellValue, string cellNote)
        {
            // Metadata will be null if the entry does not already contain any.
            if (metadata == null)
            {
                metadata = new MyCustomDataMetadata();
                entry.AddMetadata(metadata);
            }
    
            metadata.someValue = cellValue;
            metadata.someNoteValue = cellNote;
        }
    
        public override void PushHeader(StringTableCollection collection, out string header, out string headerNote)
        {
            // The title of the Google Sheet column
            header = "My Custom Data";
            headerNote = null;
        }
    
        public override void PushMetadata(MyCustomDataMetadata metadata, out string value, out string note)
        {
            // Metadata will never be null as this is only called if the entry contains a metadata entry.
            value = metadata.someValue;
            note = metadata.someNoteValue;
        }
    }

    This is an example of how to synchronize the IsSmart property. Any value in the column causes the value to be marked as smart; leaving the field empty indicates it should not be smart.

    public class SmartStringColumn : LocaleMetadataColumn<SmartFormatTag>
    {
        public override PushFields PushFields => PushFields.Value;
    
        public override void PullMetadata(StringTableEntry entry, SmartFormatTag metadata, string cellValue, string cellNote)
        {
            entry.IsSmart = !string.IsNullOrEmpty(cellValue);
        }
    
        public override void PushHeader(StringTableCollection collection, out string header, out string headerNote)
        {
            header = $"{LocaleIdentifier.ToString()} - Is Smart String";
            headerNote = null;
        }
    
        public override void PushMetadata(SmartFormatTag metadata, out string value, out string note)
        {
            value = "x"; // We mark here with an x but it could be anything.
            note = null;
        }
    }

    Properties

    Name Description
    LocaleIdentifier

    The Id of the Locale for this column.

    Methods

    Name Description
    PullBegin(StringTableCollection)

    Called when starting a pull to allow a column to initialize itself.

    PullCellData(SharedTableEntry, string, string)

    Called to update the StringTableCollection using the provided cell data.

    PullEnd()

    Called after all calls to PullCellData(SharedTableEntry, string, string) to provide an opurtunity to deinitialize, cleanup etc.

    PullMetadata(StringTableEntry, TMetadata, string, string)
    PushBegin(StringTableCollection)

    Called when starting a push to allow a column to initialize itself.

    PushCellData(SharedTableEntry, IList<StringTableEntry>, out string, out string)

    Extracts the data that should populate the columns cell for the row associated with the Key.

    PushEnd()

    Called after all calls to PushCellData(SharedTableEntry, IList<StringTableEntry>, out string, out string) to provide an opurtunity to deinitialize, cleanup etc.

    PushMetadata(TMetadata, out string, out string)
    In This Article
    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)