当前位置: 首页>>代码示例>>Java>>正文


Java Message类代码示例

本文整理汇总了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);
}
 
开发者ID:bonitasoft,项目名称:bonita-ui-designer,代码行数:30,代码来源:LanguagePack.java

示例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());
}
 
开发者ID:zanata,项目名称:jgettext,代码行数:27,代码来源:TestMessageStreamParser.java

示例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();
}
 
开发者ID:bonitasoft,项目名称:bonita-ui-designer,代码行数:8,代码来源:LanguagePack.java

示例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;
}
 
开发者ID:CubeEngine,项目名称:I18n,代码行数:30,代码来源:GettextLoader.java

示例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!");
}
 
开发者ID:zanata,项目名称:jgettext,代码行数:11,代码来源:TestMessageStreamParser.java

示例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!");
}
 
开发者ID:zanata,项目名称:jgettext,代码行数:13,代码来源:TestMessageStreamParser.java

示例7: isHeader

import org.fedorahosted.tennera.jgettext.Message; //导入依赖的package包/类
private boolean isHeader(Message message) {
    return message.getMsgid() == null || message.getMsgid().isEmpty();
}
 
开发者ID:bonitasoft,项目名称:bonita-ui-designer,代码行数:4,代码来源:LanguagePack.java

示例8: isPlural

import org.fedorahosted.tennera.jgettext.Message; //导入依赖的package包/类
private boolean isPlural(Message message) {
    return message.getMsgstr() == null;
}
 
开发者ID:bonitasoft,项目名称:bonita-ui-designer,代码行数:4,代码来源:LanguagePack.java

示例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!");

}
 
开发者ID:zanata,项目名称:jgettext,代码行数:13,代码来源:TestMessageStreamParser.java


注:本文中的org.fedorahosted.tennera.jgettext.Message类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。