Class LocaleMetadataColumn<TMetadata>
Inherited Members
Namespace: UnityEditor.Localization.Plugins.Google.Columns
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
LocaleIdentifier
The Id of the Locale for this column.
Declaration
public LocaleIdentifier LocaleIdentifier { get; set; }
Property Value
Type | Description |
---|---|
LocaleIdentifier |
Methods
PullBegin(StringTableCollection)
Called when starting a pull to allow a column to initialize itself.
Declaration
public override void PullBegin(StringTableCollection collection)
Parameters
Type | Name | Description |
---|---|---|
StringTableCollection | collection | The collection to update from the Google Sheet. |
Overrides
PullCellData(SharedTableData.SharedTableEntry, String, String)
Called to update the StringTableCollection using the provided cell data.
Declaration
public override void PullCellData(SharedTableData.SharedTableEntry keyEntry, string cellValue, string cellNote)
Parameters
Type | Name | Description |
---|---|---|
SharedTableData.SharedTableEntry | keyEntry | The entry being updated for this cell. |
String | cellValue | The cell value or |
String | cellNote | The cell note or |
Overrides
PullEnd()
Called after all calls to PullCellData(SharedTableData.SharedTableEntry, String, String) to provide an opurtunity to deinitialize, cleanup etc.
Declaration
public override void PullEnd()
Overrides
PullMetadata(StringTableEntry, TMetadata, String, String)
Declaration
public abstract void PullMetadata(StringTableEntry entry, TMetadata metadata, string cellValue, string cellNote)
Parameters
Type | Name | Description |
---|---|---|
StringTableEntry | entry | |
TMetadata | metadata | |
String | cellValue | |
String | cellNote |
PushBegin(StringTableCollection)
Called when starting a push to allow a column to initialize itself.
Declaration
public override void PushBegin(StringTableCollection collection)
Parameters
Type | Name | Description |
---|---|---|
StringTableCollection | collection | The collection to push to a Google Sheet. |
Overrides
PushCellData(SharedTableData.SharedTableEntry, IList<StringTableEntry>, out String, out String)
Extracts the data that should populate the columns cell for the row associated with the Key.
Declaration
public override void PushCellData(SharedTableData.SharedTableEntry keyEntry, IList<StringTableEntry> tableEntries, out string value, out string note)
Parameters
Type | Name | Description |
---|---|---|
SharedTableData.SharedTableEntry | keyEntry | The Key that represents the row in the spreadsheet. |
IList<StringTableEntry> | tableEntries | The StringTableEntry for the current SharedTableData.SharedTableEntry. The order of the tables will match the source StringTableCollection, If a table does not contain data for the current key then a null entry will be used. |
String | value | The value to be used for the cell. This can be null if PushFields is Note or the cell should be empty. |
String | note | The value to be used for the cell note. This can be null if PushFields is Value or if there should not be a note for this cell. |
Overrides
PushEnd()
Called after all calls to PushCellData(SharedTableData.SharedTableEntry, IList<StringTableEntry>, out String, out String) to provide an opurtunity to deinitialize, cleanup etc.
Declaration
public override void PushEnd()
Overrides
PushMetadata(TMetadata, out String, out String)
Declaration
public abstract void PushMetadata(TMetadata metadata, out string value, out string note)
Parameters
Type | Name | Description |
---|---|---|
TMetadata | metadata | |
String | value | |
String | note |