Search in sources :

Example 11 with MessageBundle

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

the class LocaleServiceImplTest method get_bundle_no_locale.

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

Example 12 with MessageBundle

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

the class LocaleServiceImplTest method get_bundle_no_application.

@Test
public void get_bundle_no_application() {
    final MessageBundle bundle = localeService.getBundle(null, Locale.ENGLISH);
    assertNull(bundle);
}
Also used : MessageBundle(com.enonic.xp.i18n.MessageBundle) Test(org.junit.jupiter.api.Test)

Example 13 with MessageBundle

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

the class LocaleServiceImplTest method get_bundle_norwegian_no.

@Test
public void get_bundle_norwegian_no() {
    final MessageBundle bundle = localeService.getBundle(ApplicationKey.from("myapplication"), Locale.forLanguageTag("no"), "norwegian");
    assertThat(bundle.asMap()).containsExactlyInAnyOrderEntriesOf(Map.of("a", "default", "b", "nb", "d", "no"));
}
Also used : MessageBundle(com.enonic.xp.i18n.MessageBundle) Test(org.junit.jupiter.api.Test)

Example 14 with MessageBundle

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

the class LocaleServiceImplTest method get_bundle_with_variant.

@Test
public void get_bundle_with_variant() {
    final Locale locale = new Locale("en", "US", "1");
    final MessageBundle bundle = localeService.getBundle(ApplicationKey.from("myapplication"), locale);
    assertNotNull(bundle);
    assertEquals(10, bundle.getKeys().size());
    assertEquals("en_US_1", bundle.localize("msg"));
}
Also used : Locale(java.util.Locale) MessageBundle(com.enonic.xp.i18n.MessageBundle) Test(org.junit.jupiter.api.Test)

Example 15 with MessageBundle

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

the class LocaleServiceImplTest method bundleInvalidateCaching.

@Test
public void bundleInvalidateCaching() {
    final ResourceKeys resourceKeys = ResourceKeys.empty();
    when(resourceService.findFiles(any(), anyString())).thenReturn(resourceKeys);
    final ApplicationKey myApp = ApplicationKey.from("myapplication");
    final ApplicationKey otherApp = ApplicationKey.from("otherapp");
    MessageBundle bundleCached = localeService.getBundle(myApp, Locale.ENGLISH, "/phrases", "/override");
    MessageBundle bundle = localeService.getBundle(myApp, Locale.ENGLISH, "/phrases", "/override");
    MessageBundle otherBundleCached = localeService.getBundle(otherApp, Locale.ENGLISH, "/texts");
    MessageBundle otherBundle = localeService.getBundle(otherApp, Locale.ENGLISH, "/texts");
    assertSame(bundle, bundleCached);
    assertSame(otherBundle, otherBundleCached);
    Application application = Mockito.mock(Application.class);
    when(application.getKey()).thenReturn(myApp);
    localeService.activated(application);
    bundle = localeService.getBundle(myApp, Locale.ENGLISH, "/phrases", "/override");
    otherBundle = localeService.getBundle(otherApp, Locale.ENGLISH, "/texts");
    assertNotSame(bundle, bundleCached);
    assertSame(otherBundle, otherBundleCached);
}
Also used : MessageBundle(com.enonic.xp.i18n.MessageBundle) ApplicationKey(com.enonic.xp.app.ApplicationKey) ResourceKeys(com.enonic.xp.resource.ResourceKeys) Application(com.enonic.xp.app.Application) 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