class POResource extends POTResource {

    @Override
    public LanguageBundle parse(InputStream inStream, FilterOptions options)
            throws IOException, ResourceFilterException {

        LanguageBundleBuilder bb = new LanguageBundleBuilder(true);
        BufferedReader reader = new BufferedReader(new InputStreamReader(inStream, CHAR_SET));

        // use these to store the state of an entry
        String singularKey = null;
        String pluralKey = null;
        boolean singularValueSet = false;

        String line;
        while ((line = reader.readLine()) != null) {

            if (line.isEmpty()) {
                // reset state, new entry is starting next
                singularKey = null;
                pluralKey = null;
                singularValueSet = false;
                continue;
            }

            String value = extractMessage(line, reader);
            if (value == null || value.isEmpty()) {
                continue;
            }

            if (line.startsWith(UNTRANSLATED_STRING_PREFIX)) {
                // save the singular key for next loop iteration
                singularKey = value;
            } else if (singularKey != null && pluralKey == null && line.startsWith(UNTRANSLATED_PLURAL_STRING_PREFIX)) {
                // save the plural key for next loop iteration
                pluralKey = value;
            } else if (singularKey != null && pluralKey == null && line.startsWith(TRANSLATED_STRING_PREFIX)
                    && !line.startsWith(TRANSLATED_PLURAL_0_STRING_PREFIX)) {
                // this covers the normal case when:
                // msgid "untranslated-string"
                // msgstr "translated-string"
                
                bb.addResourceString(singularKey, value);
            } else if (singularKey != null && pluralKey != null && line.startsWith(TRANSLATED_PLURAL_0_STRING_PREFIX)) {
                // this covers the singular key/value in a plural entry
                // the key is the value of msgid and the value is that of
                // msgstr[0]
                // msgid "Unable to find user: @users"
                // msgid_plural "Unable to find users: @users"
                // msgstr[0] "Benutzer konnte nicht gefunden werden: @users"
                // msgstr[1] "Benutzer konnten nicht gefunden werden: @users"

                bb.addResourceString(singularKey, value);
                singularValueSet = true;
            } else if (singularKey != null && pluralKey != null && singularValueSet
                    && line.startsWith(TRANSLATED_PLURAL_1_STRING_PREFIX)) {
                // this covers the plural key/value in a plural entry
                // the key is the value of msgid_plural and the value is that of
                // msgstr[1]
                bb.addResourceString(pluralKey, value);
            }
        }

        return bb.build();
    }

}