@Test public void getAvailableLocales() throws Exception { when(environment.getResourceAsStream(eq("/WEB-INF/xwiki-locales.txt"))) .thenReturn(getClass().getResourceAsStream("/xwiki-locales.txt")); Set<Locale> locales = localizationScriptService.getAvailableLocales(); assertNotNull(locales); assertFalse(locales.isEmpty()); assertTrue(locales.contains(new Locale("fr"))); assertTrue(locales.contains(new Locale("it"))); assertTrue(locales.contains(new Locale("mr_IN"))); assertFalse(locales.contains(new Locale("whatever"))); }
public Set<Locale> getAvailableLocales() { Set<Locale> locales = new HashSet<>(); locales.addAll(Arrays.asList(Locale.getAvailableLocales())); try (InputStream resource = environment.getResourceAsStream("/WEB-INF/xwiki-locales.txt")) { LineIterator iterator = IOUtils.lineIterator(resource, StandardCharsets.US_ASCII); while (iterator.hasNext()) { String line = iterator.nextLine(); if (StringUtils.isNotBlank(line)) { locales.add(new Locale(line)); } } iterator.close(); } catch (Exception e) { logger.warn("Exception while looking for XWiki Locales.", e); } return locales; }
LocalizationScriptService implements ScriptService { public Set<Locale> getAvailableLocales() { Set<Locale> locales = new HashSet<>(); locales.addAll(Arrays.asList(Locale.getAvailableLocales())); try (InputStream resource = environment.getResourceAsStream("/WEB-INF/xwiki-locales.txt")) { LineIterator iterator = IOUtils.lineIterator(resource, StandardCharsets.US_ASCII); while (iterator.hasNext()) { String line = iterator.nextLine(); if (StringUtils.isNotBlank(line)) { locales.add(new Locale(line)); } } iterator.close(); } catch (Exception e) { logger.warn("Exception while looking for XWiki Locales.", e); } return locales; } }
LocalizationScriptService implements ScriptService { public Set<Locale> getAvailableLocales() { Set<Locale> locales = new HashSet<>(); locales.addAll(Arrays.asList(Locale.getAvailableLocales())); try (InputStream resource = environment.getResourceAsStream("/WEB-INF/xwiki-locales.txt")) { LineIterator iterator = IOUtils.lineIterator(resource, StandardCharsets.US_ASCII); while (iterator.hasNext()) { String line = iterator.nextLine(); if (StringUtils.isNotBlank(line)) { locales.add(new Locale(line)); } } iterator.close(); } catch (Exception e) { logger.warn("Exception while looking for XWiki Locales.", e); } return locales; }  }
LocalizationScriptService implements ScriptService { public Set<Locale> getAvailableLocales() { Set<Locale> locales = new HashSet<>(); locales.addAll(Arrays.asList(Locale.getAvailableLocales())); try (InputStream resource = environment.getResourceAsStream("/WEB-INF/xwiki-locales.txt")) { LineIterator iterator = IOUtils.lineIterator(resource, StandardCharsets.US_ASCII); while (iterator.hasNext()) { String line = iterator.nextLine(); if (StringUtils.isNotBlank(line)) { locales.add(new Locale(line)); } } iterator.close(); } catch (Exception e) { logger.warn("Exception while looking for XWiki Locales.", e); } return locales; }  Translation get(String key); Translation get(String key, Locale locale); boolean use(String bundleType, String bundleId); Locale getCurrentLocale(); Locale toLocale(String str); String render(String key); String render(Collection<String> keys); String render(String key, Locale locale); String render(Collection<String> keys, Locale locale); String render(String key, Collection<?> parameters); String render(Collection<String> keys, Collection<?> parameters); String render(String key, Collection<?> parameters, Locale locale); String render(Collection<String> keys, Collection<?> parameters, Locale locale); String render(String key, Syntax syntax); String render(Collection<String> keys, Syntax syntax); String render(String key, Syntax syntax, Locale locale); String render(Collection<String> keys, Syntax syntax, Locale locale); String render(String key, Syntax syntax, Collection<?> parameters); String render(Collection<String> keys, Syntax syntax, Collection<?> parameters); String render(String key, Syntax syntax, Collection<?> parameters, Locale locale); String render(Collection<String> keys, Syntax syntax, Collection<?> parameters, Locale locale); Set<Locale> getAvailableLocales(); }
LocalizationScriptService implements ScriptService { public Set<Locale> getAvailableLocales() { Set<Locale> locales = new HashSet<>(); locales.addAll(Arrays.asList(Locale.getAvailableLocales())); try (InputStream resource = environment.getResourceAsStream("/WEB-INF/xwiki-locales.txt")) { LineIterator iterator = IOUtils.lineIterator(resource, StandardCharsets.US_ASCII); while (iterator.hasNext()) { String line = iterator.nextLine(); if (StringUtils.isNotBlank(line)) { locales.add(new Locale(line)); } } iterator.close(); } catch (Exception e) { logger.warn("Exception while looking for XWiki Locales.", e); } return locales; }  Translation get(String key); Translation get(String key, Locale locale); boolean use(String bundleType, String bundleId); Locale getCurrentLocale(); Locale toLocale(String str); String render(String key); String render(Collection<String> keys); String render(String key, Locale locale); String render(Collection<String> keys, Locale locale); String render(String key, Collection<?> parameters); String render(Collection<String> keys, Collection<?> parameters); String render(String key, Collection<?> parameters, Locale locale); String render(Collection<String> keys, Collection<?> parameters, Locale locale); String render(String key, Syntax syntax); String render(Collection<String> keys, Syntax syntax); String render(String key, Syntax syntax, Locale locale); String render(Collection<String> keys, Syntax syntax, Locale locale); String render(String key, Syntax syntax, Collection<?> parameters); String render(Collection<String> keys, Syntax syntax, Collection<?> parameters); String render(String key, Syntax syntax, Collection<?> parameters, Locale locale); String render(Collection<String> keys, Syntax syntax, Collection<?> parameters, Locale locale); Set<Locale> getAvailableLocales();  }