def get_mapping_for_pofile_plurals(pofile):
    """Check if POFile plural forms need fixing.

    Return a mapping if a plural form expression in PO file header doesn't
    match expected plural form expression for `pofile.language`, otherwise
    return False.
    """
    expected_plural_formula = pofile.language.pluralexpression
    used_plural_formula = POHeader(pofile.header).plural_form_expression
    if expected_plural_formula == used_plural_formula:
        return None
    else:
        forms_map = plural_form_mapper(expected_plural_formula,
                                       used_plural_formula)
        for key in forms_map:
            if forms_map[key] != key:
                return forms_map

        return None
def get_mapping_for_pofile_plurals(pofile):
    """Check if POFile plural forms need fixing.

    Return a mapping if a plural form expression in PO file header doesn't
    match expected plural form expression for `pofile.language`, otherwise
    return False.
    """
    expected_plural_formula = pofile.language.pluralexpression
    used_plural_formula = POHeader(pofile.header).plural_form_expression
    if expected_plural_formula == used_plural_formula:
        return None
    else:
        forms_map = plural_form_mapper(expected_plural_formula,
                                       used_plural_formula)
        for key in forms_map:
            if forms_map[key] != key:
                return forms_map

        return None
Example #3
0
    def _parseHeader(self, header_text, header_comment):
        try:
            header = POHeader(header_text, header_comment)
            self._translation_file.header = header
            self._translation_file.syntax_warnings += header.syntax_warnings
        except TranslationFormatInvalidInputError as error:
            if error.line_number is None:
                error.line_number = self._message_lineno
            raise
        self._translation_file.header.is_fuzzy = ('fuzzy'
                                                  in self._message.flags)

        if self._translation_file.messages:
            self._emitSyntaxWarning("Header entry is not first entry.")

        plural_formula = self._translation_file.header.plural_form_expression
        if plural_formula is None:
            # We default to a simple plural formula which uses
            # a single form for translations.
            plural_formula = '0'
        self._plural_form_mapping = plural_form_mapper(
            plural_formula, self._expected_plural_formula)
        # convert buffered input to the encoding specified in the PO header
        self._decode()
    def _parseHeader(self, header_text, header_comment):
        try:
            header = POHeader(header_text, header_comment)
            self._translation_file.header = header
            self._translation_file.syntax_warnings += header.syntax_warnings
        except TranslationFormatInvalidInputError as error:
            if error.line_number is None:
                error.line_number = self._message_lineno
            raise
        self._translation_file.header.is_fuzzy = (
            'fuzzy' in self._message.flags)

        if self._translation_file.messages:
            self._emitSyntaxWarning("Header entry is not first entry.")

        plural_formula = self._translation_file.header.plural_form_expression
        if plural_formula is None:
            # We default to a simple plural formula which uses
            # a single form for translations.
            plural_formula = '0'
        self._plural_form_mapping = plural_form_mapper(
            plural_formula, self._expected_plural_formula)
        # convert buffered input to the encoding specified in the PO header
        self._decode()