use of com.enonic.xp.resource.ResourceKeys in project xp by enonic.
the class LocaleServiceImpl method getAppLocales.
private Set<Locale> getAppLocales(final ApplicationKey applicationKey, final String... bundleNames) {
LOG.debug("Create app locales for {}", applicationKey);
final Set<Locale> locales = new LinkedHashSet<>();
for (final String bundleName : bundleNames) {
final String bundlePattern = "^" + Pattern.quote(bundleName.startsWith("/") ? bundleName : "/" + bundleName) + ".*\\.properties$";
final ResourceKeys resourceKeys = resourceService.findFiles(applicationKey, bundlePattern);
for (ResourceKey resourceKey : resourceKeys) {
final Locale locale = localeFromResource(resourceKey.getName());
locales.add(locale);
if (locale.equals(LOCALE_NO)) {
locales.add(LOCALE_NB);
locales.add(LOCALE_NN);
}
if (locale.getLanguage().equals(LOCALE_NB.getLanguage()) || locale.getLanguage().equals(LOCALE_NN.getLanguage())) {
locales.add(LOCALE_NO);
}
}
}
return locales;
}
use of com.enonic.xp.resource.ResourceKeys in project xp by enonic.
the class LocaleServiceImplTest method getSupportedLocale_moreThanOneFound.
@Test
public void getSupportedLocale_moreThanOneFound() {
final ResourceKeys resourceKeys = ResourceKeys.from("myapplication:/site/i18n/myphrases.properties", "myapplication:/site/i18n/myphrases_en.properties", "myapplication:/site/i18n/myphrases_en_US.properties", "myapplication:/site/i18n/myphrases_en_US_1.properties", "myapplication:/site/i18n/myphrases_fr.properties", "myapplication:/site/i18n/myphrases_ca.properties");
when(resourceService.findFiles(any(), anyString())).thenReturn(resourceKeys);
List<Locale> preferredLocales = localeList("no", "ca-ES", "en");
Locale supportedLocale = localeService.getSupportedLocale(preferredLocales, ApplicationKey.from("myapplication"), "/myphrases");
assertNotNull(supportedLocale);
assertEquals("ca", supportedLocale.toLanguageTag());
}
use of com.enonic.xp.resource.ResourceKeys in project xp by enonic.
the class LocaleServiceImplTest method getSupportedLocale_nb_file_supports_no_locale.
@Test
public void getSupportedLocale_nb_file_supports_no_locale() {
final ResourceKeys resourceKeys = ResourceKeys.from("myapplication:/site/i18n/myphrases.properties", "myapplication:/site/i18n/myphrases_nb.properties");
when(resourceService.findFiles(any(), anyString())).thenReturn(resourceKeys);
List<Locale> preferredLocales = localeList("no");
Locale supportedLocale = localeService.getSupportedLocale(preferredLocales, ApplicationKey.from("myapplication"), "/myphrases");
assertNotNull(supportedLocale);
assertEquals("no", supportedLocale.toLanguageTag());
}
use of com.enonic.xp.resource.ResourceKeys in project xp by enonic.
the class LocaleServiceImplTest method getSupportedLocale_no_file_supports_nb_locale.
@Test
public void getSupportedLocale_no_file_supports_nb_locale() {
final ResourceKeys resourceKeys = ResourceKeys.from("myapplication:/site/i18n/myphrases.properties", "myapplication:/site/i18n/myphrases_no.properties");
when(resourceService.findFiles(any(), anyString())).thenReturn(resourceKeys);
List<Locale> preferredLocales = localeList("nb");
Locale supportedLocale = localeService.getSupportedLocale(preferredLocales, ApplicationKey.from("myapplication"), "/myphrases");
assertNotNull(supportedLocale);
assertEquals("nb", supportedLocale.toLanguageTag());
}
use of com.enonic.xp.resource.ResourceKeys in project xp by enonic.
the class LocaleServiceImplTest method getSupportedLocale_no_file_supports_nn_locale.
@Test
public void getSupportedLocale_no_file_supports_nn_locale() {
final ResourceKeys resourceKeys = ResourceKeys.from("myapplication:/site/i18n/myphrases.properties", "myapplication:/site/i18n/myphrases_no.properties");
when(resourceService.findFiles(any(), anyString())).thenReturn(resourceKeys);
List<Locale> preferredLocales = localeList("nn");
Locale supportedLocale = localeService.getSupportedLocale(preferredLocales, ApplicationKey.from("myapplication"), "/myphrases");
assertNotNull(supportedLocale);
assertEquals("nn", supportedLocale.toLanguageTag());
}
Aggregations