Skip to content

This add-on provides a custom datatype, a related field and a dataGrid column renderer, for storing, editing and displaying multilingual string values.

Notifications You must be signed in to change notification settings

pbaris/jmix-multilingual-field

Repository files navigation

license

MultilingualField for Jmix

This add-on provides a custom datatype, a related field and a dataGrid column renderer, for storing, editing and displaying multilingual string values.

preview1
preview2

Installation

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>'

How to use the add-on

Datatype

Add-on provides a new datatype MultilingualString.

You can define an entity attribute with the MultilingualString datatype using Studio.

studio1

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":"Ηλεκτρονικός υπολογιστής"}

Field

In a detail view you can add the field from studio Component Palette window

studio2

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>

DataGrid Column Renderer

In a list view you can add the renderer from studio Jmix UI context menu

studio3

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.

Configuration

Locale Modes

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 property jmix.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

UI Field

Field Type

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.

field1
MULTI

A multiline-line text input component will be used.

field2
RTF

The Jmix’s RichTextEditor component will be used.

field3

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;
}
field4

Properties

  • 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.

Validation

If the field is bound to a required entity attribute, then the edit fields also become required:

field1 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

UI Flags

The supported locales for the field are listed below. If an unsupported locale is used, the unknown flag will be displayed.

sq Albanian (sq)

hy Armenian (hy)

bg Bulgarian (bg)

zh Chinese (zh)

hr Croatian (hr)

cs Czech (cs)

da Danish (da)

nl Dutch (nl)

en English (en)

et Estonian (et)

fi Finnish (fi)

fr French (fr)

de German (de)

el Greek (el)

he Hebrew (he)

hi Hindi (hi)

hu Hungarian (hu)

it Italian (it)

ja Japanese (ja)

ko Korean (ko)

lt Lithuanian (lt)

mt Maltese (mt)

no Norwegian (no)

pl Polish (pl)

pt Portuguese (pt)

ro Romanian (ro)

ru Russian (ru)

sr Serbian (sr)

es Spanish (es)

sv Swedish (sv)

th Thai (th)

tr Turkish (tr)

vi Vietnamese (vi)

xx Unknown

Limitations

Since the actual value stored in the database is a JSON string (CLOB), there are the following limitations:

  • GenericFilter and PropertyFilter components are not supported.

  • Sorting is applied using the default locale.

About

This add-on provides a custom datatype, a related field and a dataGrid column renderer, for storing, editing and displaying multilingual string values.

Resources

Stars

Watchers

Forks

Sponsor this project

 

Packages