本文整理汇总了Java中org.fedorahosted.tennera.jgettext.Message类的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Message类属于org.fedorahosted.tennera.jgettext包,在下文中一共展示了Message类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toJson
import org.fedorahosted.tennera.jgettext.Message; //导入依赖的package包/类
/**
* Transform po file into json file.
* Using hash map ease the transformation into JSON.
*
* @return a JSON representation of the catalog conform to angular-gettext expectations.
* @throws IOException
*/
public byte[] toJson() throws IOException {
HashMap<String, HashMap<String, Object>> language = new HashMap<>();
final HashMap<String, Object> translations = new HashMap<>();
Catalog catalog = poParser.parseCatalog(poFile);
language.put(extractLanguageFrom(catalog.locateHeader()), translations);
catalog.processMessages(new MessageProcessor() {
@Override
public void processMessage(Message message) {
if (isHeader(message)) { // ignore header
return;
}
translations.put(message.getMsgid(),
isPlural(message) ?
message.getMsgstrPlural() :
message.getMsgstr());
}
});
return objectMapper.toJson(language);
}
示例2: testIteratingThroughABasicFile
import org.fedorahosted.tennera.jgettext.Message; //导入依赖的package包/类
@Test
public void testIteratingThroughABasicFile() throws Throwable {
Message message;
MessageStreamParser parser = new MessageStreamParser(poFile);
assertTrue(parser.hasNext());
message = parser.next();
assertTrue(message.isHeader());
assertTrue(message.isFuzzy());
assertTrue(parser.hasNext());
message = parser.next();
assertFalse(message.isHeader());
assertFalse(message.isFuzzy());
parser.next();
parser.next();
message = parser.next();
assertTrue(message.isObsolete());
parser.next();
parser.next(); // last message
assertFalse(parser.hasNext());
}
示例3: extractLanguageFrom
import org.fedorahosted.tennera.jgettext.Message; //导入依赖的package包/类
private String extractLanguageFrom(Message header) {
Matcher matcher = Pattern.compile("Language:(.*?)$", Pattern.MULTILINE).matcher(header.getMsgstr());
if (!matcher.find()) {
throw new RuntimeException("Couldn't find po file language.");
}
return matcher.group(1).trim();
}
示例4: loadTranslations
import org.fedorahosted.tennera.jgettext.Message; //导入依赖的package包/类
public TranslationContainer loadTranslations(TranslationContainer container, Locale locale) throws TranslationLoadingException
{
Map<String, String> singularMessages = new HashMap<String, String>();
Map<String, String[]> pluralMessages = new HashMap<String, String[]>();
Set<URL> loadFrom = new LinkedHashSet<URL>();
for (URL poFile : poFiles)
{
String fileName = poFile.toString();
if (fileName.endsWith(locale.getLanguage().toLowerCase() + "_" + locale.getCountry().toUpperCase() + ".po")
|| fileName.endsWith(locale.getLanguage().toLowerCase() + ".po"))
{
loadFrom.add(poFile);
}
}
for (URL url : loadFrom)
{
Catalog catalog = this.parseCatalog(url);
if (catalog != null)
{
for (Message message : catalog)
{
singularMessages.put(message.getMsgid(), message.getMsgstr());
pluralMessages.put(message.getMsgidPlural(), message.getMsgstrPlural().toArray(new String[message.getMsgstrPlural().size()]));
}
}
container.merge(singularMessages, pluralMessages);
}
return container;
}
示例5: testParseFromInputStream
import org.fedorahosted.tennera.jgettext.Message; //导入依赖的package包/类
@Test
public void testParseFromInputStream() throws Throwable {
MessageStreamParser parser = new MessageStreamParser(
new ByteArrayInputStream(msgString.getBytes("UTF-8")));
Message message = parser.next();
assertEquals(message.getMsgid(), "hello world!");
assertEquals(message.getMsgstr(), "hei verden!");
}
示例6: testParseFromInputStreamWithUtf16Charset
import org.fedorahosted.tennera.jgettext.Message; //导入依赖的package包/类
@Test
public void testParseFromInputStreamWithUtf16Charset() throws Throwable {
MessageStreamParser parser =
new MessageStreamParser(
new ByteArrayInputStream(msgString.getBytes("UTF-16")),
Charset.forName("UTF-16"));
Message message = parser.next();
assertEquals(message.getMsgid(), "hello world!");
assertEquals(message.getMsgstr(), "hei verden!");
}
示例7: isHeader
import org.fedorahosted.tennera.jgettext.Message; //导入依赖的package包/类
private boolean isHeader(Message message) {
return message.getMsgid() == null || message.getMsgid().isEmpty();
}
示例8: isPlural
import org.fedorahosted.tennera.jgettext.Message; //导入依赖的package包/类
private boolean isPlural(Message message) {
return message.getMsgstr() == null;
}
示例9: testParseFromReader
import org.fedorahosted.tennera.jgettext.Message; //导入依赖的package包/类
@Test
public void testParseFromReader() throws Throwable {
MessageStreamParser parser = new MessageStreamParser(
new StringReader(msgString));
Message message = parser.next();
assertEquals(message.getMsgid(), "hello world!");
assertEquals(message.getMsgstr(), "hei verden!");
}