Entity instances translation

Hi every one, we are creating our first application using cuba platform and every day we find out new feature that we are really like…congratulation!!!

We are now struggling with a need we have: give to users not only the entity translation in their language, but of the instances too… is that possible in cuba? Please see the example…

I see the issue was mentioned in a previous forum post Translation of entity values and the issue was reported in a github activity…but i cannot understand if we have that feature or not…

EXAMPLE
Entity: userWorkgroup
Field_1: name_ES
Field_2: name_EN
Instance 1: “Jardinería”,“greenkeeper”
Instance 2: “Fontanero”,“plumber”
Instance 3: “Albañil”,“bricklayer”
and so on…

Thank you very much…
Angelo

Hi Angelo,

We are planning to implement this feature but the time is not defined yet.
For now, you can create any workaround yourself, for example, storing an Embeddable object with fields for each language instead of one String attribute.

1 Like

Thank you very much Olga for the answer, i will check out the solution you suggest.

Thanks
Angelo

Olga, i googled a bit but no examples for the embedded field type… so, do you have any example or documentation that describes the correct use of the field?

Thank you very much
Angelo

Yes, sure: @Embedded.

For example:

@NamePattern("%s|name")
@Table(name = "DEMO_PERSON")
@Entity(name = "demo$Person")
public class Person extends StandardEntity {
    private static final long serialVersionUID = 1234662462822335242L;

    @Embedded
    @EmbeddedParameters(nullAllowed = false)
    @AttributeOverrides({
            @AttributeOverride(name = "en", column = @Column(name = "NAME_EN")),
            @AttributeOverride(name = "ru", column = @Column(name = "NAME_RU")),
            @AttributeOverride(name = "fr", column = @Column(name = "NAME_FR"))
    })
    protected NameLoc name;

. . .

}
@MetaClass(name = "demo$NameLoc")
@Embeddable
public class NameLoc extends EmbeddableEntity {
    private static final long serialVersionUID = -7506958463389513646L;

    @Column(name = "EN")
    protected String en;

    @Column(name = "RU")
    protected String ru;

    @Column(name = "FR")
    protected String fr;

    public void setEn(String en) {
        this.en = en;
    }

    public String getEn() {
        return en;
    }

. . .

}

And you’ll need to implement some logic to display the needed locale in browsers, for example:

person-browse.xml

<groupTable id="personsTable">
    <columns>
        <column id="name"
                generator="generateNameCell"/>
    </columns>
    <rows datasource="personsDs"/>
</groupTable>

PersonBrowse.java

public class PersonBrowse extends AbstractLookup {

    @Inject
    private UserSession userSession;

    public Component generateNameCell(Person person) {
        Locale locale = userSession.getLocale();
        if (locale == Locale.ENGLISH) {
            return new Table.PlainTextCell(person.getName().getEn());
        } else if (locale == Locale.FRENCH) {
            return new Table.PlainTextCell(person.getName().getFr());
        } else if (locale == Locale.forLanguageTag("ru")) {
            return new Table.PlainTextCell(person.getName().getRu());
        } else {
            return new Table.PlainTextCell(person.getName().getEn());
        }
    }
}

Here’s the small demo project for you to try: demo.zip (90.4 KB)

1 Like

Olga, first of all, it’s so great to see how you are working guys, i mean, not only the CUBA Platform is a great software but you guys behind are REALLY great professionals!! CONGRATULATIONS!!!

Thank you very much for the example i will check it out!

Angelo

2 Likes

3 posts were split to a new topic: IllegalStateException for field with custom converter