use of org.xwiki.localization.message.TranslationMessage in project xwiki-platform by xwiki.
the class MessageToolTranslationMessageParserTest method messageWithEscapedParameter.
@Test
public void messageWithEscapedParameter() throws ComponentLookupException {
TranslationMessage translationMessage = getMockedComponent().parse("'{0}");
Assert.assertEquals("'{0}", translationMessage.getRawSource());
Assert.assertEquals(new CompositeBlock(Arrays.<Block>asList(new SpecialSymbolBlock('{'), new WordBlock("0"), new SpecialSymbolBlock('}'))), translationMessage.render(null, null, "word"));
}
use of org.xwiki.localization.message.TranslationMessage in project xwiki-platform by xwiki.
the class MessageToolTranslationMessageParserTest method messageEmpty.
@Test
public void messageEmpty() throws ComponentLookupException {
TranslationMessage translationMessage = getMockedComponent().parse("");
Assert.assertEquals("", translationMessage.getRawSource());
Assert.assertEquals(new CompositeBlock(), translationMessage.render(null, null));
}
use of org.xwiki.localization.message.TranslationMessage in project xwiki-platform by xwiki.
the class AbstractURLResourceTranslationBundle method loadResourceLocaleBundle.
/**
* @param locale the locale
* @return the {@link LocalizedTranslationBundle} corresponding to the passed {@link Locale}, null if none could be
* found
*/
protected LocalizedTranslationBundle loadResourceLocaleBundle(Locale locale) {
// Find resource
URL localeURL = getLocaleURL(locale);
if (localeURL == null) {
return LocalizedTranslationBundle.EMPTY;
}
// Parse resource
Properties properties = new Properties();
try (InputStream componentListStream = localeURL.openStream()) {
properties.load(componentListStream);
} catch (FileNotFoundException e) {
// No translation files for the passed locale
return LocalizedTranslationBundle.EMPTY;
} catch (IOException e) {
this.logger.error("Failed to parse resource [{}] as translation bundle", localeURL, e);
}
// Convert to LocalBundle
DefaultLocalizedTranslationBundle localeBundle = new DefaultLocalizedTranslationBundle(this, locale);
TranslationMessageParser parser = getTranslationMessageParser();
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
if (entry.getKey() instanceof String && entry.getValue() instanceof String) {
String key = (String) entry.getKey();
String message = (String) entry.getValue();
TranslationMessage translationMessage = parser.parse(message);
localeBundle.addTranslation(new DefaultTranslation(this.bundleContext, localeBundle, key, translationMessage));
}
}
return localeBundle;
}
use of org.xwiki.localization.message.TranslationMessage in project xwiki-platform by xwiki.
the class MessageToolTranslationMessageParserTest method messageSimple.
@Test
public void messageSimple() throws ComponentLookupException {
TranslationMessage translationMessage = getMockedComponent().parse("word");
Assert.assertEquals("word", translationMessage.getRawSource());
Assert.assertEquals(new WordBlock("word"), translationMessage.render(null, null));
}
use of org.xwiki.localization.message.TranslationMessage in project xwiki-platform by xwiki.
the class MessageToolTranslationMessageParserTest method messageWithExpectedParameter.
@Test
public void messageWithExpectedParameter() throws ComponentLookupException {
TranslationMessage translationMessage = getMockedComponent().parse("{0}");
Assert.assertEquals("{0}", translationMessage.getRawSource());
Assert.assertEquals(new CompositeBlock(Arrays.<Block>asList(new SpecialSymbolBlock('{'), new WordBlock("0"), new SpecialSymbolBlock('}'))), translationMessage.render(null, null));
}
Aggregations