Search in sources :

Example 1 with EntityLocalizations

use of com.developmentontheedge.be5.metadata.model.EntityLocalizations in project be5 by DevelopmentOnTheEdge.

the class MetaImpl method getLocalization.

private String getLocalization(Project project, String language, String entity, Predicate<LocalizationElement> accept) {
    for (Module module : project.getModulesAndApplication()) {
        Localizations localizations = module.getLocalizations();
        LanguageLocalizations languageLocalizations = localizations.get(language);
        if (languageLocalizations == null)
            continue;
        EntityLocalizations entityLocalizations = languageLocalizations.get(entity);
        if (entityLocalizations == null)
            continue;
        for (LocalizationElement element : entityLocalizations.elements()) if (accept.test(element))
            return element.getValue();
    }
    return "";
}
Also used : EntityLocalizations(com.developmentontheedge.be5.metadata.model.EntityLocalizations) LanguageLocalizations(com.developmentontheedge.be5.metadata.model.LanguageLocalizations) EntityLocalizations(com.developmentontheedge.be5.metadata.model.EntityLocalizations) LanguageLocalizations(com.developmentontheedge.be5.metadata.model.LanguageLocalizations) Localizations(com.developmentontheedge.be5.metadata.model.Localizations) Module(com.developmentontheedge.be5.metadata.model.Module) LocalizationElement(com.developmentontheedge.be5.metadata.model.LocalizationElement)

Example 2 with EntityLocalizations

use of com.developmentontheedge.be5.metadata.model.EntityLocalizations in project be5 by DevelopmentOnTheEdge.

the class EntityLocalizationsTest method testLocalizations.

@Test
public void testLocalizations() {
    Project proj = new Project("test");
    proj.getApplication().getLocalizations().addLocalization("de", "entity", Arrays.asList("@AllQueries", "topic"), "Hello", "Guten Tag");
    Entity entity = new Entity("entity", proj.getApplication(), EntityType.TABLE);
    DataElementUtils.save(entity);
    DataElementUtils.save(new Query("testQuery", entity));
    DataElementUtils.save(new Query("testQuery2", entity));
    EntityLocalizations el = proj.getApplication().getLocalizations().get("de").get("entity");
    Set<LocalizationRow> expected = StreamEx.of("testQuery", "testQuery2", "topic").map(topic -> new EntityLocalizations.LocalizationRow(topic, "Hello", "Guten Tag")).toSet();
    assertEquals(expected, el.getRawRows());
    assertEquals(expected, el.getRows());
    el.remove("Hello", Collections.singleton("topic"));
    expected = StreamEx.of("testQuery", "testQuery2").map(topic -> new EntityLocalizations.LocalizationRow(topic, "Hello", "Guten Tag")).toSet();
    assertEquals(expected, el.getRawRows());
    assertEquals(expected, el.getRows());
}
Also used : Arrays(java.util.Arrays) LocalizationRow(com.developmentontheedge.be5.metadata.model.EntityLocalizations.LocalizationRow) StreamEx(one.util.streamex.StreamEx) Set(java.util.Set) Test(org.junit.Test) Assert(org.junit.Assert) Collections(java.util.Collections) LocalizationRow(com.developmentontheedge.be5.metadata.model.EntityLocalizations.LocalizationRow) LocalizationRow(com.developmentontheedge.be5.metadata.model.EntityLocalizations.LocalizationRow) Test(org.junit.Test)

Aggregations

EntityLocalizations (com.developmentontheedge.be5.metadata.model.EntityLocalizations)1 LocalizationRow (com.developmentontheedge.be5.metadata.model.EntityLocalizations.LocalizationRow)1 LanguageLocalizations (com.developmentontheedge.be5.metadata.model.LanguageLocalizations)1 LocalizationElement (com.developmentontheedge.be5.metadata.model.LocalizationElement)1 Localizations (com.developmentontheedge.be5.metadata.model.Localizations)1 Module (com.developmentontheedge.be5.metadata.model.Module)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Set (java.util.Set)1 StreamEx (one.util.streamex.StreamEx)1 Assert (org.junit.Assert)1 Test (org.junit.Test)1