Method Export
Export(TextWriter, StringTableCollection, ITaskReporter)
Exports all Stringcollection
using default column mappings generated through
Create
Declaration
public static void Export(TextWriter writer, StringTableCollection collection, ITaskReporter reporter = null)
Parameters
Type | Name | Description |
---|---|---|
Text |
writer | The target that will be populated with CSV data. |
String |
collection | The collection to export to CSV. |
ITask |
reporter | An optional reporter that can be used to provide feedback during export. |
Examples
This example shows how to export a String
var collection = LocalizationEditorSettings.GetStringTableCollection("My Strings");
using (var stream = new StreamWriter("My Strings CSV.csv", false, new UTF8Encoding(false)))
{
Csv.Export(stream, collection);
}
Export(TextWriter, StringTableCollection, IList<CsvColumns>, ITaskReporter)
Exports a StringcolumnMappings
to control the contents of each exported column.
Create
Declaration
public static void Export(TextWriter writer, StringTableCollection collection, IList<CsvColumns> columnMappings, ITaskReporter reporter = null)
Parameters
Type | Name | Description |
---|---|---|
Text |
writer | The target that will be populated with CSV data. |
String |
collection | The collection to export to CSV. |
IList<Csv |
columnMappings | Controls what will be exported.
The Key |
ITask |
reporter | An optional reporter that can be used to provide feedback during export. |
Examples
This example shows how to configure the data you wish to export in CSV through column mappings.
var collection = LocalizationEditorSettings.GetStringTableCollection("My Strings");
// Use custom column mappings to control what data gets exported
var columnMappings = new List<CsvColumns>();
// We must have 1 KeyIdColumns so that we can map the table entries correctly
columnMappings.Add(new KeyIdColumns
{
IncludeId = true, // Include the Id column field.
IncludeSharedComments = true, // Include Shared comments.
});
// Export English with no comments
columnMappings.Add(new LocaleColumns
{
LocaleIdentifier = "en",
IncludeComments = false
});
// Export Japanese with comments
columnMappings.Add(new LocaleColumns
{
LocaleIdentifier = SystemLanguage.Japanese,
IncludeComments = true
});
// Now export
using (var stream = new StreamWriter("My Strings CSV.csv", false, new UTF8Encoding(false)))
{
Csv.Export(stream, collection, columnMappings);
}
This example shows how to export every String
[MenuItem("Localization/CSV/Export All CSV Files(With Extensions)")]
public static void ExportAllCsvExtensions()
{
// 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 extension.
foreach (var extension in collection.Extensions)
{
if (extension is CsvExtension csvExtension)
{
if (!string.IsNullOrEmpty(csvExtension.File))
{
using (var stream = new StreamWriter(csvExtension.File, false, new UTF8Encoding(false)))
{
Csv.Export(stream, collection, csvExtension.Columns);
}
}
}
}
}
}
This example shows how to export all String
[MenuItem("Localization/CSV/Export All CSV Files")]
public static void ExportAllCsv()
{
// Get every String Table Collection
var stringTableCollections = LocalizationEditorSettings.GetStringTableCollections();
var path = EditorUtility.SaveFolderPanel("Export All String Table Collections - CSV", "", "");
if (string.IsNullOrEmpty(path))
return;
foreach (var collection in stringTableCollections)
{
var file = Path.Combine(path, collection.TableCollectionName + ".csv");
using (var stream = new StreamWriter(file, false, new UTF8Encoding(false)))
{
Csv.Export(stream, collection);
}
}
}