本文整理匯總了Java中org.fedorahosted.tennera.jgettext.Catalog類的典型用法代碼示例。如果您正苦於以下問題:Java Catalog類的具體用法?Java Catalog怎麽用?Java Catalog使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Catalog類屬於org.fedorahosted.tennera.jgettext包,在下文中一共展示了Catalog類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toJson
import org.fedorahosted.tennera.jgettext.Catalog; //導入依賴的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: loadTranslations
import org.fedorahosted.tennera.jgettext.Catalog; //導入依賴的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;
}
示例3: parseCatalog
import org.fedorahosted.tennera.jgettext.Catalog; //導入依賴的package包/類
private Catalog parseCatalog(URL url) throws TranslationLoadingException
{
try
{
return this.parser.parseCatalog(url.openStream(), charset, true);
}
catch (IOException e)
{
throw new TranslationLoadingException(e);
}
}
示例4: testBadToken
import org.fedorahosted.tennera.jgettext.Catalog; //導入依賴的package包/類
@Test
public void testBadToken() throws Throwable {
File poFile =
new File(getClass()
.getResource("/invalid/badtoken.po").toURI());
ExtendedCatalogParser parser =
new ExtendedCatalogParser(new Catalog(), poFile);
try {
parser.catalog();
fail("was expecting exception");
} catch (UnexpectedTokenException expected) {
// ignore
}
}
示例5: testPartialObsoleteEntries
import org.fedorahosted.tennera.jgettext.Catalog; //導入依賴的package包/類
@Test
public void testPartialObsoleteEntries() throws Throwable {
File poFile =
new File(getClass()
.getResource("/invalid/mixed_up_obsolete.po").toURI());
ExtendedCatalogParser parser =
new ExtendedCatalogParser(new Catalog(), poFile);
try {
parser.catalog();
fail("was expecting exception");
} catch (ParseException expected) {
}
}
示例6: ExtendedCatalogParser
import org.fedorahosted.tennera.jgettext.Catalog; //導入依賴的package包/類
public ExtendedCatalogParser(Catalog catalog, Reader reader, boolean isPot) {
super(new CatalogLexer(reader));
catalog.setTemplate(isPot);
this.catalog = catalog;
}
示例7: getCatalog
import org.fedorahosted.tennera.jgettext.Catalog; //導入依賴的package包/類
public Catalog getCatalog() {
return catalog;
}