Method ImportInto
ImportInto(TextReader, StringTableCollection, bool, ITaskReporter, bool)
Import the CSV data into collection
using columnMappings
to control what data will be imported.
See KeyIdColumns and LocaleColumns for further details.
Declaration
public static void ImportInto(TextReader reader, StringTableCollection collection, bool createUndo = false, ITaskReporter reporter = null, bool removeMissingEntries = false)
Parameters
Type | Name | Description |
---|---|---|
TextReader | reader | The source of the CSV data. |
StringTableCollection | collection | The target collection to be updated using the CSV data. |
bool | createUndo | Should an Undo operation be created so the changes can be undone? |
ITaskReporter | reporter | An optional reporter that can be used to provide feedback during import. |
bool | removeMissingEntries | After a pull has completed, any keys that exist in the |
Examples
This example show how to import a collection with default settings.
var collection = LocalizationEditorSettings.GetStringTableCollection("My Strings");
using (var stream = new StreamReader("My Strings CSV.csv"))
{
Csv.ImportInto(stream, collection);
}
ImportInto(TextReader, StringTableCollection, IList<CsvColumns>, bool, ITaskReporter, bool)
Import the CSV data into collection
using default column mappings generated using CreateDefaultMapping(bool).
Declaration
public static void ImportInto(TextReader reader, StringTableCollection collection, IList<CsvColumns> columnMappings, bool createUndo = false, ITaskReporter reporter = null, bool removeMissingEntries = false)
Parameters
Type | Name | Description |
---|---|---|
TextReader | reader | |
StringTableCollection | collection | |
IList<CsvColumns> | columnMappings | |
bool | createUndo | |
ITaskReporter | reporter | |
bool | removeMissingEntries | After a pull has completed, any keys that exist in the |
Examples
This example shows how to configure the data you wish to import in CSV through column mappings.
var collection = LocalizationEditorSettings.GetStringTableCollection("My Strings");
// Use custom column mappings to control what data gets imported.
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
});
using (var stream = new StreamReader("My Strings CSV.csv"))
{
Csv.ImportInto(stream, collection, columnMappings);
}
This example shows how to import every StringTableCollection that contains a CsvExtension.
[MenuItem("Localization/CSV/Import All CSV Files")]
public static void ImportAllExtensions()
{
// 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) && File.Exists(csvExtension.File))
{
using (var stream = new StreamReader(csvExtension.File))
{
Csv.ImportInto(stream, collection, csvExtension.Columns);
}
}
}
}
}
}