#86 Merged at 870a91c

fixed #955: footnote i18n translation cause KeyError and 'Only update text nodes in translation' change at b7b808e46851 break translation.

  1. Takayuki Shimizukawa


  • original node.children count and translated patch.children count is not equal.
  • original node.children include registered auto numbered footnote_reference but patch.children is not.
  • named-footnote and numbered footnote are not same as auto-numbered footnote.
  • if patch.children has duplicated auto numbered footnote [#] then don't care because it is wrong msgstr.
  • also fix #1044: External links don't work in localized HTML

Comments (7)

  1. Dmitry Shachnev

    I'm not sure if this is a side-effect of your branch, but I now get lots of warnings when I try to build text containing literal blocks, like this one:

    some text::
       this is
       a literal block
    more text

    Warnings are similar to this one:

    /path/to/file.rst:2: WARNING: Literal block expected; none found.

    Do you know what may cause this? A test case is lp:ubuntu-packaging-guide with Spanish translation.

    P.S. Thanks a lot for your work here (again)!

  2. Jon Waltman

    I think the code still has some issues in how it handles references and footnote_references that are present in one case but not the other.

    What about checking whether the number of references is equal in both the translated form and the untranslated form? If they're not equal, emit a warning and don't bother trying to transfer the references.

  3. Jon Waltman

    I think this looks alright.

    One thing I'd suggest though is slightly re-wording the warning message.
    (the "skip translation" part is no longer correct right?)

    diff --git a/sphinx/environment.py b/sphinx/environment.py
    --- a/sphinx/environment.py
    +++ b/sphinx/environment.py
    @@ -234,9 +234,8 @@ class Locale(Transform):
                 old_foot_refs = node.traverse(is_autonumber_footnote_ref)
                 new_foot_refs = patch.traverse(is_autonumber_footnote_ref)
                 if len(old_foot_refs) != len(new_foot_refs):
    -                env.warn_node('The number of reference are inconsistent '
    -                              'in both the translated form and the '
    -                              'untranslated form. skip translation.', node)
    +                env.warn_node('inconsistent footnote references in '
    +                              'translated message', node)
                 for old, new in zip(old_foot_refs, new_foot_refs):
                     new['ids'] = old['ids']
    @@ -253,9 +252,8 @@ class Locale(Transform):
                 new_refs = patch.traverse(is_refnamed_ref)
                 applied_refname_map = {}
                 if len(old_refs) != len(new_refs):
    -                env.warn_node('The number of reference are inconsistent '
    -                              'in both the translated form and the '
    -                              'untranslated form. skip translation.', node)
    +                env.warn_node('inconsistent references in '
    +                              'translated message', node)
                 for new in new_refs:
                     if new['refname'] in applied_refname_map:
                         # 2nd appearance of the reference
    @@ -1813,4 +1811,3 @@ class BuildEnvironment:
                     if 'orphan' in self.metadata[docname]:
                     self.warn(docname, 'document isn\'t included in any toctree')
    diff --git a/tests/test_intl.py b/tests/test_intl.py
    --- a/tests/test_intl.py
    +++ b/tests/test_intl.py
    @@ -120,8 +120,13 @@ def test_i18n_warn_for_number_of_referen
         assert result == expect
         warnings = warnfile.getvalue().replace(os.sep, '/')
    -    expected_warning_expr = "i18n/refs_inconsistency.txt:\d+: WARNING: The number of reference are inconsistent in both the translated form and the untranslated form. skip translation."
    -    assert len(re.findall(expected_warning_expr, warnings)) == 3
    +    warning_fmt = u'.*/i18n/refs_inconsistency.txt:\\d+: ' \
    +          u'WARNING: inconsistent %s in translated message\n'
    +    expected_warning_expr = (
    +        warning_fmt % 'footnote references' +
    +        warning_fmt % 'references' +
    +        warning_fmt % 'references')
    +    assert re.search(expected_warning_expr, warnings)
     @with_app(buildername='html', cleanenv=True,