This add-on provides a custom datatype, a related field and a dataGrid column renderer, for storing, editing and displaying multilingual string values.
The following table shows which version of the add-on is compatible with which version of the platform:
Jmix Version | Add-on Version | Implementation |
---|---|---|
2.4.1 |
1.0.0 |
gr.netmechanics.jmix:jmix-multilingual-field-starter:1.0.0 |
2.4.2 |
1.1.0 |
gr.netmechanics.jmix:jmix-multilingual-field-starter:1.1.0 |
2.5.x |
1.2.0 |
gr.netmechanics.jmix:jmix-multilingual-field-starter:1.2.0 |
For manual installation, add the following dependencies to your build.gradle
:
implementation 'gr.netmechanics.jmix:jmix-multilingual-field-starter:<addon-version>'
Add-on provides a new datatype MultilingualString
.
You can define an entity attribute with the MultilingualString
datatype using Studio.
As a result, Studio generates the following attribute definition:
@Column(name = "TITLE")
private MultilingualString title;
Note
|
The actual value stored in the database is a JSON string. {"en":"Computer","el":"Ηλεκτρονικός υπολογιστής"} |
In a detail view you can add the field from studio Component Palette
window
or through code
<view xmlns="http://jmix.io/schema/flowui/view"
xmlns:nm="http://schemas.netmechanics.gr/jmix/ui"
focusComponent="form">
...
<layout>
<formLayout id="form">
<nm:multilingualField id="titleField" property="title"/>
</formLayout>
...
</layout>
</view>
In a list view you can add the renderer from studio Jmix UI context menu
or through code
<view xmlns="http://jmix.io/schema/flowui/view"
xmlns:nm="http://schemas.netmechanics.gr/jmix/ui"
focusComponent="postsDataGrid">
...
<layout>
...
<dataGrid id="postsDataGrid" width="100%"
minHeight="20em" dataContainer="postsDc">
<columns resizable="true">
<column property="title">
<nm:multilingualStringRenderer/>
</column>
</columns>
</dataGrid>
...
</layout>
</view>
Tip
|
The default locale will be used to render the column. |
The add-on provides two modes for defining supported locales.
- SYSTEM
-
This mode utilizes the locales specified in the
jmix.core.available-locales
property. - USER
-
The
jmix.mlf.user-locales
application property allows you to define locales as a list of language codes following the ISO 639-1 standard.jmix.mlf.user-locales=en,el,ru,es,fr,my
Alternatively to dynamically specify locales at runtime, you can implement the
gr.netmechanics.jmix.mlf.locales.UserLocales
interface and provide its implementation through the application propertyjmix.mlf.user-locales-app-setting-class
. For instance, this can be achieved using an AppSetting.package com.example.entity; import io.jmix.appsettings.entity.AppSettingsEntity; import gr.netmechanics.jmix.mlf.locales.UserLocales; @JmixEntity @Table(name = "EXMP_SYSTEM_SETTINGS") @Entity(name = "EXMP_SystemSettings") public class SystemSettings extends AppSettingsEntity implements UserLocales { @AppSettingsDefault("en") @Column(name = "LOCALES") private String locales; @Override public String getLocales() { return locales; } public void setLocales(final String locales) { this.locales = locales; } }
jmix.mlf.user-locales-app-setting-class=com.example.entity.SystemSettings
Tip
|
In both modes, the selection options in the UI field are arranged in the same order as the locales, with the first specified locale serving as the default. |
The default mode is SYSTEM
. You can select the desired mode by configuring the jmix.mlf.locale-mode
application property.
jmix.mlf.locale-mode=USER
There are three types for the UI field
- SINGLE
-
A single-line text input component will be used. This is the default type unless another type is specified.
- MULTI
-
A multiline-line text input component will be used.
- RTF
-
The Jmix’s RichTextEditor component will be used.
Additionally, you can use a field provider which will return a component.
For example using the TinyMCE Editor add-on:
@Install(to = "titleField", subject = "fieldProvider")
private AbstractField<?, String> titleFieldFieldProvider() {
TinyMceEditor tinyMceEditor = uiComponents.create(TinyMceEditor.class);
TinyMceConfigUtil.applyConfig(tinyMceEditor, TinyMceConfigMode.BASIC);
tinyMceEditor.setHeight("400px");
return tinyMceEditor;
}
-
fieldType
- sets the field type, SINGLE, MULTI or RTF values can be used. -
multilineHeight
- sets the height of the multi-line text input component if used. -
multilineMinHeight
- sets the min-height of the multi-line text input component if used. -
multilineMaxHeight
- sets the max-height of the multi-line text input component if used.
If the field is bound to a required entity attribute, then the edit fields also become required:
For the field to be valid, values must be provided for all locales. To validate only the default locale set the jmix.mlf.validate-default-locale-only
application property to true.
jmix.mlf.validate-default-locale-only=true
The supported locales for the field are listed below. If an unsupported locale is used, the unknown flag will be displayed.