BaseFramework Class
Classes
Section titled “Classes”abstract BaseFramework
Section titled “abstract BaseFramework”Defined in: framework/base/base.framework.ts:20
Abstract base class for framework-specific translation file management.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Description |
|---|---|
Resource | The framework-specific data structure representing translation file contents. Returned by deserialize method for translation file content. |
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new BaseFramework<Resource>(config): BaseFramework<Resource>;Defined in: framework/base/base.framework.ts:27
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
config | Static |
Returns
Section titled “Returns”BaseFramework<Resource>
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
directory | string | Name of all source files directory (e.g. locales) | framework/base/base.framework.ts:25 |
locale | string | Name of source locale directory (e.g. en) | framework/base/base.framework.ts:22 |
Methods
Section titled “Methods”deserialize()
Section titled “deserialize()”abstract deserialize(raw): Resource;Defined in: framework/base/base.framework.ts:172
Parses raw translation file content into a framework-specific Resource object.
Implementations should parse the string and validate it against the framework’s resource schema, throwing an error if the format is invalid.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
raw | string | Translation file content as a string |
Returns
Section titled “Returns”Resource
Parsed and validated Resource object
Throws
Section titled “Throws”Error if the content cannot be parsed or fails schema validation
diff()
Section titled “diff()”abstract diff(oldResource): ResourceDelta[];Defined in: framework/base/base.framework.ts:194
Computes translation differences between two Resource objects.
When oldResource is undefined, all keys in newResource should be marked as “added”.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
oldResource | { newResource: Resource; oldResource?: Resource; } | The previous Resource state (undefined for newly created resources) |
oldResource.newResource | Resource | - |
oldResource.oldResource? | Resource | - |
Returns
Section titled “Returns”ResourceDelta[]
Array of ResourceDelta objects, each describing an added, changed, or removed translation key with its path and value(s)
diffSnapshots()
Section titled “diffSnapshots()”diffSnapshots(__namedParameters): SnapshotDelta[];Defined in: framework/base/base.framework.ts:82
Compares two snapshots to identify translation key-level changes across all files.
For each file present in the new snapshot, compares it against the old snapshot (if present) to detect added, changed, or removed translation keys
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
__namedParameters | { newSnapshot: Snapshot<Resource>; oldSnapshot: Snapshot<Resource>; } |
__namedParameters.newSnapshot | Snapshot<Resource> |
__namedParameters.oldSnapshot | Snapshot<Resource> |
Returns
Section titled “Returns”SnapshotDelta[]
Array of SnapshotDelta objects, each containing a file path and a ResourceDelta describing a specific translation change
patch()
Section titled “patch()”abstract patch(resource): Resource;Defined in: framework/base/base.framework.ts:214
Applies translation updates to a Resource object.
Implementations should iterate through the updates array and apply each value at its specified resourcePath
When resource is undefined, creates a new Resource and applies all updates to it.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
resource | { resource?: Resource; updates: Static<any>[]; } | The existing Resource to modify (undefined to create a new one) |
resource.resource? | Resource | - |
resource.updates | Static<any>[] | - |
Returns
Section titled “Returns”Resource
The modified or newly created Resource object
resolve()
Section titled “resolve()”abstract resolve(resource): string;Defined in: framework/base/base.framework.ts:233
Retrieves the translation string value at a specific path within a Resource.
Implementations should traverse the Resource using the provided path array and return the string value found at that location.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
resource | { resource: Resource; resourcePath: Static; } | The Resource object to query |
resource.resource | Resource | - |
resource.resourcePath | Static | - |
Returns
Section titled “Returns”string
The translation string value at the specified path
Throws
Section titled “Throws”Error if the resourcePath does not exist in the resource
resolveFilePath()
Section titled “resolveFilePath()”resolveFilePath(filePath): string;Defined in: framework/base/base.framework.ts:158
Resolves a file path relative to source locale directory to its absolute filesystem location for a given locale.
Combines the configured locales directory, target locale, and relative file path into an absolute path.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
filePath | { filePath: string; locale: string; } | Relative path within the source locale directory (e.g., “common/buttons.json”) |
filePath.filePath | string | - |
filePath.locale | string | - |
Returns
Section titled “Returns”string
Absolute filesystem path to the file (e.g., “/locales/fr/common/buttons.json”)
serialize()
Section titled “serialize()”abstract serialize(resource): string;Defined in: framework/base/base.framework.ts:182
Serializes a Resource object into formatted string content ready for file output.
Implementations should convert the Resource into a properly formatted string.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
resource | Resource | The Resource object to serialize |
Returns
Section titled “Returns”string
Formatted string content that can be written to a file
snapshot()
Section titled “snapshot()”snapshot(locale?): Snapshot<Resource>;Defined in: framework/base/base.framework.ts:43
Captures the current state of all translation files in the source locale directory.
Recursively traverses the directory at {directory}/{locale}, reads and deserializes
each file, and returns a snapshot mapping relative file paths to their parsed contents.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
locale? | string |
Returns
Section titled “Returns”Snapshot<Resource>
Snapshot mapping file paths (relative to the source locale directory) to their deserialized Resource objects.
For example, if a file exists at {directory}/{locale}/common/buttons.json, the key will be common/buttons.json.
Throws
Section titled “Throws”Error if the source locale directory does not exist or files cannot be read