Class: DefaultTranslation<K>
Defined in: src/diagram/locale.tsx:24
Default built-in implementation for i18n strings interpolation and other methods from Translation interface.
Type Parameters
| Type Parameter | Default type |
|---|---|
|
|
Implements
Translation<K>
Constructors
Constructor
new DefaultTranslation<
K>(options):DefaultTranslation<K>
Defined in: src/diagram/locale.tsx:29
Parameters
| Parameter | Type | Description |
|---|---|---|
| { | ‐ |
| readonly | Translation bundles for UI text strings in the workspace in order from higher to lower priority. See |
| Overrides how a single label gets selected from multiple of them based on target language. |
Returns
DefaultTranslation<K>
Methods
formatLabel()
formatLabel(
labels,fallbackIri,language):string
Defined in: src/diagram/locale.tsx:105
Same as selectLabel() but uses local part of
the fallbackIri as a fallback to display an entity referred by IRI
even if there is no suitable label to use.
Example:
// Returns: 'Apple'
const name = t.formatLabel(
[
model.factory.literal('Apfel', 'de'),
model.factory.literal('Яблоко', 'ru'),
],
'http://example.com/entity/Apple',
'en'
);
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
|
|
Returns
string
Implementation of
selectLabel()
selectLabel(
labels,language):undefined|Literal
Defined in: src/diagram/locale.tsx:86
Selects a single preferred literal for the target language out of several candidates.
Language code is specified as lowercase BCP47
string (examples: en, en-gb, etc).
Example:
// Returns: Rdf.Literal { value = 'Apfel', language = 'de' }
const name = t.selectLabel(
[
model.factory.literal('Apple', 'en'),
model.factory.literal('Apfel', 'de'),
model.factory.literal('Яблоко', 'ru'),
],
'de'
);
Parameters
| Parameter | Type | Description |
|---|---|---|
| readonly | candidate literal with same or different language codes |
|
| target language code |
Returns
undefined | Literal
selected literal or undefined if no suitable literal was found
Implementation of
selectValues()
selectValues(
values,language): (Literal|NamedNode<string>)[]
Defined in: src/diagram/locale.tsx:94
Selects a subset of RDF values for the target language.
The value is included if matches at least one criteria:
- is a named node,
- is a literal without language,
- is a literal with language equal to the target language.
Language code is specified as lowercase BCP47
string (examples: en, en-gb, etc).
Parameters
| Parameter | Type |
|---|---|
| readonly ( |
|
|
Returns
(Literal | NamedNode<string>)[]
Implementation of
template()
template(
key,parts):ReactNode
Defined in: src/diagram/locale.tsx:81
Templates a translation string into React Fragment by replacing placeholders with provided React nodes (elements, etc).
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
Returns
ReactNode
Implementation of
text()
text(
key,placeholders?):string
Defined in: src/diagram/locale.tsx:66
Formats a translation string by replacing placeholders with provided values.
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
Returns
string
Implementation of
textOptional()
textOptional(
key,placeholders?):undefined|string
Defined in: src/diagram/locale.tsx:70
Formats a translation string by replacing placeholders with provided values if the string exists.
Returns undefined if a translation string is null or does exists
for the specified key.
Parameters
| Parameter | Type |
|---|---|
|
|
|
|
Returns
undefined | string