Implementing Translatable
Defining translatable entities
Making an entity translatable means that string properties of the entity can have a different values for multiple languages.
To make an entity translatable, you need to implement the Translatable interface and add a translations property to the entity.
The translations property is a OneToMany relation to the translations. Any fields that are to be translated are of type LocaleString, and do not have a @Column() decorator.
This is because the text field here does not in fact exist in the database in the product_request table. Instead, it belongs to the product_request_translations table of the ProductRequestTranslation entity:
Thus there is a one-to-many relation between ProductRequest and ProductRequestTranslation, which allows Vendure to handle multiple translations of the same entity. The ProductRequestTranslation entity also implements the Translation interface, which requires the languageCode field and a reference to the base entity.
Translations in the GraphQL schema
Since the text field is getting hydrated with the translation it should be exposed in the GraphQL Schema. Additionally, the ProductRequestTranslation type should
be defined as well, to access other translations as well:
Creating translatable entities
Creating a translatable entity is usually done by using the TranslatableSaver. This injectable service provides a create and update method which can be used to save or update a translatable entity.
Important for the creation of translatable entities is the input object. The input object should contain a translations array with the translations for the entity. This can be done
by defining the types like CreateRequestInput inside the GraphQL schema:
Updating translatable entities
Updating a translatable entity is done in a similar way as creating one. The TranslatableSaver provides an update method which can be used to update a translatable entity.
Once again it's important to provide the translations array in the input object. This array should contain the translations for the entity.
Loading translatable entities
If your plugin needs to load a translatable entity, you will need to use the TranslatorService to hydrate all the LocaleString fields will the actual translated values from the correct translation.