interface in Unity.Localization.Providers.FileTables
Reads a table snapshot from a file at runtime, so a file-backed provider can rebuild a table without shipping the authored table asset.
A reader turns a stream into a ResourceTableData snapshot, which the provider
rebuilds into a table. Writing the snapshot lives on the editor side, so no serialization code ships in a player.
Implement this and pair it with a FileTableProvider subclass to add a runtime table format;
JsonResourceProvider pairs the default JsonTableReader for JSON.
Additional resources: FileTableProvider, JsonTableReader, ResourceTableData
<para>Add a runtime table format by pairing a reader with a provider.</para>
using System; using System.IO; using System.Text; using Unity.Localization.Providers.FileTables;
namespace Unity.Localization.Samples { // Deliberately simple: one "key=value" line per entry, so a key cannot hold '=' and a value cannot span lines. public class TextTableReader : ITableFileReader { public const string Extension = "txt"; public static readonly TextTableReader Instance = new();
public string FileExtension => Extension;
public ResourceTableData Read(Stream stream) { var data = new ResourceTableData(); using var reader = new StreamReader(stream, Encoding.UTF8, true, 1024, leaveOpen: true); while (reader.ReadLine() is { } line) { if (line.StartsWith("#", StringComparison.Ordinal)) continue; var split = line.IndexOf('='); if (split <= 0) continue; var key = line[..split].Trim(); var value = line[(split + 1)..].Trim(); switch (key) { case "@collection": data.CollectionName = value; break; case "@guid": data.CollectionGuid = value; break; case "@locale": data.LocaleCode = value; break; default: // No id in the file, so the shared data assigns one and matches the row by key. data.Entries.Add(new EntryData { Key = key, Value = value }); break; } } return data; } }
[Serializable] public class TextResourceProvider : FileTableProvider { protected override ITableFileReader Reader => TextTableReader.Instance;
// A language is discovered from the file name, so adding one means writing a file beside the others. public static string LanguageFilePath(string dataFolder, string collectionName, string localeCode) => Path.Combine(dataFolder, FileName(collectionName, localeCode, TextTableReader.Extension)); } }
| Property | Description |
|---|---|
| FileExtension | The file extension the format uses, without the leading dot. |
| Method | Description |
|---|---|
| Read | Reads a table snapshot from a stream. |