Translations
Built-in Translation
Translations within Tyranid are designed to be supported without having to do any additional work on the part of the developer -- they are "built-in". This is accomplished by having "language string codes" automatically generated based on metadata and IDs in the majority of cases.
However, for cases where you need a translatable term that is not associated with a particular piece of data or metadata, this is handled by Terms.
Locale and White Labels
White labeling is translation process where application and data terms can be modified to be specific for an organization. For example, an application might by default want to label a field as "Manager" while some specific organization might want to see that field show up as "Leader".
Tyranid enhances the concept of a local to also optionally include an organization. This confers the ability to white label data by providing an organization along with the locale when defining a translation.
This means that white labels can also be internationalized because both an organization and a locale can be provided in a context.
Translations
Translations are stored in the tyrTranslation collection. For example:
Translation | Description |
---|---|
|
Inserts a Korean translation for the name field in the User collection. |
| Inserts a white label in the default language. |
| Inserts a white label in the korean language. |
Translation IDs
The format of the tyrTranslation._id field is:
UID[/path]
For example:Translation ID | Means |
---|---|
u00 | The label for the User collection. |
u00/name | The label for the User collection's name field. |
u00/name/help | The tooltip for the User collection's name field. |
or3/orders.amount | The label for the Order collection's amount field that is embedded in an orders array. |
u005567f2a5387fa974fc6f3a42/name | The value of the name field for the user with ID 5567f2a5387fa974fc6f3a42. |
_tmwidgetName | The value of the widgetName term (_tm is the UID for the Term collection). |
Terms
Terms are stored in the tyrTerm collection.Tyr.$ can be used to automatically translate the default string into another context. For example:
TyrTerm.insert({
_id: 'applicationName',
value: 'My Default Application',
help: 'This contains the name of the default application.'
});
...
const value = Tyr.$`Welcome to $$applicationName!`;
Default values provided in metadata automatically are processed by Tyr.$. The following example shows how terms can be used in regular metadata:
new Tyr.Collection({
name: 'Widget',
label: 'A $$widgetName',
...,
fields: {
...,
name: {
is: 'string',
label: '$$widgetName Label',
help: 'This contains the name of your $$widgetName.'
}
});
Automatic Translations
Accessing white-labelable fields will be automatically translated into the current user context if one is available on Tyr.local.
For example, accessing Tyr.collections.User.fields.name.label will automatically return any translation relevant to the current user for the label for User name field.