use of org.molgenis.data.i18n.model.L10nString in project molgenis by molgenis.
the class LocalizationPopulator method createL10nString.
private L10nString createL10nString(String namespace, String msgId) {
L10nString result = l10nStringFactory.create(msgId);
result.setMessageID(msgId);
result.setNamespace(namespace);
return result;
}
use of org.molgenis.data.i18n.model.L10nString in project molgenis by molgenis.
the class PlatformIT method testLanguageService.
@WithMockUser(username = USERNAME)
@Test(singleThreaded = true)
public void testLanguageService() {
populateUserPermissions();
assertEquals(dataService.getMeta().getEntityType(ENTITY_TYPE_META_DATA).getAttribute("labelEn").getName(), "labelEn");
assertEquals(dataService.getMeta().getEntityType(ENTITY_TYPE_META_DATA).getLabelAttribute("en").getName(), "label");
assertEquals(dataService.getMeta().getEntityType(ENTITY_TYPE_META_DATA).getLabelAttribute("pt").getName(), "label");
assertEquals(dataService.getMeta().getEntityType(ENTITY_TYPE_META_DATA).getLabelAttribute("nl").getName(), "label");
assertEquals(dataService.getMeta().getEntityType(ENTITY_TYPE_META_DATA).getLabelAttribute().getName(), "label");
assertEquals(LanguageService.getCurrentUserLanguageCode(), "en");
assertEqualsNoOrder(LanguageService.getLanguageCodes().toArray(), new String[] { "en", "nl", "de", "es", "it", "pt", "fr", "xx" });
// NL
assertNotNull(dataService.getEntityType(L10N_STRING).getAttribute("nl"));
assertNotNull(dataService.getEntityType(ENTITY_TYPE_META_DATA).getAttribute("labelNl"));
assertNotNull(dataService.getEntityType(ENTITY_TYPE_META_DATA).getAttribute("descriptionNl"));
assertNotNull(dataService.getEntityType(ATTRIBUTE_META_DATA).getAttribute("labelNl"));
assertNotNull(dataService.getEntityType(ATTRIBUTE_META_DATA).getAttribute("descriptionNl"));
// EN
assertNotNull(dataService.getEntityType(L10N_STRING).getAttribute("en"));
assertNotNull(dataService.getEntityType(ENTITY_TYPE_META_DATA).getAttribute("labelEn"));
assertNotNull(dataService.getEntityType(ENTITY_TYPE_META_DATA).getAttribute("descriptionEn"));
assertNotNull(dataService.getEntityType(ATTRIBUTE_META_DATA).getAttribute("labelEn"));
assertNotNull(dataService.getEntityType(ATTRIBUTE_META_DATA).getAttribute("descriptionEn"));
L10nString car = l10nStringFactory.create();
car.setMessageID("car");
car.set("en", "car");
car.set("nl", "auto");
car.setNamespace("platform-it");
dataService.add(L10nStringMetaData.L10N_STRING, car);
// Test default value
assertEquals(LanguageService.getBundle().getString("car"), "car");
}
use of org.molgenis.data.i18n.model.L10nString in project molgenis by molgenis.
the class EmxMetaDataParser method toL10nString.
private L10nString toL10nString(Entity emxI18nStringEntity) {
L10nString l10nString = l10nStringFactory.create();
l10nString.setMessageID(emxI18nStringEntity.getString(EMX_I18N_STRING_MSGID));
l10nString.setDescription(emxI18nStringEntity.getString(EMX_I18N_STRING_DESCRIPTION));
String namespace = emxI18nStringEntity.getString(EMX_I18N_STRING_NAMESPACE);
if (namespace == null) {
namespace = DEFAULT_NAMESPACE;
}
l10nString.setNamespace(namespace);
LanguageService.getLanguageCodes().forEach(lang -> l10nString.set(lang, emxI18nStringEntity.getString(lang)));
return l10nString;
}
use of org.molgenis.data.i18n.model.L10nString in project molgenis by molgenis.
the class EmxMetaDataParser method parseI18nStrings.
private void parseI18nStrings(Repository<Entity> emxI18nStringRepo, IntermediateParseResults intermediateParseResults) {
emxI18nStringRepo.forEach(emxI18nStringEntity -> {
L10nString l10nString = toL10nString(emxI18nStringEntity);
intermediateParseResults.addL10nString(l10nString);
});
}
use of org.molgenis.data.i18n.model.L10nString in project molgenis by molgenis.
the class LocalizationPopulator method updateFromSource.
private void updateFromSource(AllPropertiesMessageSource source, String namespace, String messageID, L10nString l10nString) {
for (String languageCode : LanguageService.getLanguageCodes().collect(toList())) {
Locale locale = new Locale(languageCode);
String message = source.resolveCodeWithoutArguments(messageID, locale);
if (message != null && isNullOrEmpty(l10nString.getString(locale))) {
LOG.debug("Setting {}.{}.{} to {}", namespace, messageID, languageCode, message);
l10nString.set(languageCode, message);
}
}
}
Aggregations