Fields
How to use built-in input and WYSIWYG with i18n support in backend.
As an example, we will create a translation field for the title (input)
and content (WYSIWYG)
fields in the core_terms
table.
Database
You need to create a new table in the database schema.
You can find more information about the database schema in the documentation.
As you can see in the example above, we haven't added the translation fields yet. We will add them in service
later using core_languages_words
table.
Show Translation
DTO Object
For the translation fields to show data, you need to use StringLanguage[]
type in the DTO for the object.
DTO for multipart/form-data
If you are using multipart/form-data
all fields will be string
type. You need to transform them to StringLanguage[]
type in the service.
Service
core_languages_words
table doesn't have relation so you need to use StringLanguageHelper
service with show()
to get translations.
In return service we will filter translation by item_id
and variable
to get the correct translation for the title
and content
fields.
API Reference
Prop | Type | Default |
---|---|---|
item_ids | number[] | - |
database | DatabaseSchema | - |
plugin_code | string | - |
variables | string[] | - |
Create / Edit Translation
DTO Input
For the translation fields to work in the input, you need to use StringLanguage
type in the DTO for the input and class-validator
decorators.
To required translation fields you can use @ArrayMinSize(1)
decorator.
Service
To create or edit translation fields you need to use StringLanguageHelper
service with parse()
method.
As an example, we will create a translation field for the title
and content
fields in the core_terms
table.
This method will create a translation inside core_languages_words
table and processing content to send notifications, attachments, etc.
API Reference
Prop | Type | Default |
---|---|---|
item_id | number | - |
plugin_code | string | - |
database | DatabaseSchema | - |
data | StringLanguageInput[] | - |
variable | string | - |
Delete Service
As we mention before, when you create or edit translation fields then our parser()
method will processing content. To delete translations and other things related to it you need to use delete()
method.
Always delete translation when delete primary record!
This is important to delete translation. Otherwise, translations will be still in the database.
API Reference
Prop | Type | Default |
---|---|---|
database | DatabaseSchema | - |
item_id | number | - |
plugin_code | string | - |