Description
In PoReader translate(TranslationContext, String, ContextAndMsgId.Type) can handle both of contextual and contextless (more generic) translations, which is a good thing. But as org.apache.isis.core.runtimeservices.i18n.po.Block reads the po file, we can not define generic translation, context is a must (contextlist should be non-empty).
Maybe a new State (GENCONTEXT) is sugested:
private enum State { CONTEXT("^#: (?<value>.+)$"), GENCONTEXT("^#:\s*$"), MSGID("^msgid \"(?<value>.+)\"$"), MSGID_PLURAL("^msgid_plural \"(?<value>.+)\"$"), MSGSTR("^msgstr \"(?<value>.+)\"$"), MSGSTR0("^msgstr\\[0\\] \"(?<value>.+)\"$"), MSGSTR1("^msgstr\\[1\\] \"(?<value>.+)\"$");
and in parseLine:
if (state == State.CONTEXT) { final Matcher contextMatcher = state.pattern.matcher(line); if (contextMatcher.matches()) { final String context = contextMatcher.group("value"); contextList.add(context); return this; } else { state = State.GENCONTEXT; } } if (state == State.GENCONTEXT) { final Matcher contextMatcher = state.pattern.matcher(line); if (contextMatcher.matches()) { contextList.add(""); return this; } else { state = State.MSGID; // fallthrough (there may not have been any more context) } }
Maybe contextList is better to be Set, not a List.
In this case we can use
#: msgid "Anonymous" msgstr "Anonim felhasználó"
As generic context.