Search in sources :

Example 21 with MessageBundle

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

the class MessageBundleImplTest method testEmptyResourceBundle.

@Test
public void testEmptyResourceBundle() {
    MessageBundle resourceBundle = new MessageBundleImpl(new Properties(), Locale.ENGLISH);
    assertNull(resourceBundle.localize("dummyKey"));
}
Also used : MessageBundle(com.enonic.xp.i18n.MessageBundle) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Example 22 with MessageBundle

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

the class MessageBundleImplTest method alwaysUTC.

@Test
public void alwaysUTC() {
    final Properties properties = new Properties();
    properties.put("key1", "{0,date,z}");
    MessageBundle resourceBundle = new MessageBundleImpl(properties, Locale.ROOT);
    assertEquals("UTC", resourceBundle.localize("key1", System.currentTimeMillis()));
}
Also used : MessageBundle(com.enonic.xp.i18n.MessageBundle) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Example 23 with MessageBundle

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

the class MessageBundleImplTest method testParameterizedPhrase_two_values.

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

Example 24 with MessageBundle

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

the class MessageBundleImplTest method testAsMap.

@Test
public void testAsMap() {
    final MessageBundle resourceBundle = createDefault();
    final Map<String, String> map = resourceBundle.asMap();
    assertEquals(6, map.size());
}
Also used : MessageBundle(com.enonic.xp.i18n.MessageBundle) Test(org.junit.jupiter.api.Test)

Example 25 with MessageBundle

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

the class MessageBundleImplTest method dateTime.

@Test
public void dateTime() {
    final Properties properties = new Properties();
    properties.put("key1", "{0,time,short} {0,date,short}");
    MessageBundle resourceBundle = new MessageBundleImpl(properties, Locale.TRADITIONAL_CHINESE);
    assertEquals("上午9:46 1973/3/3", resourceBundle.localize("key1", Instant.ofEpochMilli(100000000000L).toEpochMilli()));
}
Also used : MessageBundle(com.enonic.xp.i18n.MessageBundle) Properties(java.util.Properties) 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