Search in sources :

Example 6 with MessageBundle

use of com.enonic.xp.i18n.MessageBundle in project xp by enonic.

the class MessageBundleImplTest method testEmptyValue.

@Test
public void testEmptyValue() {
    MessageBundle resourceBundle = createDefault();
    assertNull(resourceBundle.localize("key6"));
}
Also used : MessageBundle(com.enonic.xp.i18n.MessageBundle) Test(org.junit.jupiter.api.Test)

Example 7 with MessageBundle

use of com.enonic.xp.i18n.MessageBundle in project xp by enonic.

the class MessageBundleImplTest method testParameterizedPhraseMissingParameter.

@Test
public void testParameterizedPhraseMissingParameter() {
    MessageBundle resourceBundle = createDefault();
    Object[] testArgs = { "myValue1" };
    String resolvedPhrase = resourceBundle.localize("key5", testArgs);
    assertEquals("value is here myValue1 and there {1}", resolvedPhrase);
}
Also used : MessageBundle(com.enonic.xp.i18n.MessageBundle) Test(org.junit.jupiter.api.Test)

Example 8 with MessageBundle

use of com.enonic.xp.i18n.MessageBundle in project xp by enonic.

the class MessageBundleImplTest method testParameterizedPhrase.

@Test
public void testParameterizedPhrase() {
    MessageBundle resourceBundle = createDefault();
    Object[] testArgs = { "myValue1" };
    String resolvedPhrase = resourceBundle.localize("key4", testArgs);
    assertEquals("value is here myValue1", resolvedPhrase);
}
Also used : MessageBundle(com.enonic.xp.i18n.MessageBundle) Test(org.junit.jupiter.api.Test)

Example 9 with MessageBundle

use of com.enonic.xp.i18n.MessageBundle in project xp by enonic.

the class LocalizeFunction method execute.

@Override
public Object execute(final ViewFunctionParams params) {
    final LocalizeParams localizeParams = new LocalizeParams(PortalRequestAccessor.get()).setAsMap(params.getArgs());
    final MessageBundle bundle = this.localeService.getBundle(localizeParams.getApplicationKey(), localizeParams.getLocale());
    if (bundle == null) {
        return MessageFormat.format(NO_MATCHING_BUNDLE, localizeParams.getApplicationKey());
    }
    final String localizedMessage = bundle.localize(localizeParams.getKey(), localizeParams.getParams());
    return localizedMessage != null ? localizedMessage : NOT_TRANSLATED_MESSAGE;
}
Also used : MessageBundle(com.enonic.xp.i18n.MessageBundle)

Example 10 with MessageBundle

use of com.enonic.xp.i18n.MessageBundle in project xp by enonic.

the class LocaleServiceImplTest method get_bundle_with_country.

@Test
public void get_bundle_with_country() {
    final MessageBundle bundle = localeService.getBundle(ApplicationKey.from("myapplication"), Locale.US);
    assertNotNull(bundle);
    assertEquals(9, bundle.getKeys().size());
    assertEquals("en_US", bundle.localize("msg"));
}
Also used : MessageBundle(com.enonic.xp.i18n.MessageBundle) Test(org.junit.jupiter.api.Test)

Aggregations

MessageBundle (com.enonic.xp.i18n.MessageBundle)26 Test (org.junit.jupiter.api.Test)22 Properties (java.util.Properties)6 Locale (java.util.Locale)3 ApplicationKey (com.enonic.xp.app.ApplicationKey)2 LocaleService (com.enonic.xp.i18n.LocaleService)2 LinkedHashSet (java.util.LinkedHashSet)2 Application (com.enonic.xp.app.Application)1 ResourceKeys (com.enonic.xp.resource.ResourceKeys)1 LocalDate (java.time.LocalDate)1 LocalTime (java.time.LocalTime)1