Skip to content

Commit

Permalink
Fix translation o' plurals
Browse files Browse the repository at this point in the history
It was settin' th' plurals in index '0' ratherr than 0. Bleh.

Fixes #79
  • Loading branch information
willkg committed Nov 5, 2015
1 parent aca57f6 commit a59a9bb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
4 changes: 2 additions & 2 deletions dennis/translator.py
Expand Up @@ -735,9 +735,9 @@ def translate_file(self, fname):
count = 0
for entry in po:
if entry.msgid_plural:
entry.msgstr_plural['0'] = self.translate_string(
entry.msgstr_plural[0] = self.translate_string(
entry.msgid)
entry.msgstr_plural['1'] = self.translate_string(
entry.msgstr_plural[1] = self.translate_string(
entry.msgid_plural)
else:
entry.msgstr = self.translate_string(entry.msgid)
Expand Down
5 changes: 5 additions & 0 deletions tests/__init__.py
Expand Up @@ -17,3 +17,8 @@

def build_po_string(data):
return POFILE_HEADER + '\n' + data


def nix_header(pot_file):
"""Nix the POT file header since it changes and we don't care"""
return pot_file[pot_file.find('\n\n')+2:]
32 changes: 31 additions & 1 deletion tests/test_cmdline.py
@@ -1,8 +1,10 @@
from textwrap import dedent

from click.testing import CliRunner
import pytest

from dennis.cmdline import cli
from tests import build_po_string
from tests import build_po_string, nix_header


@pytest.fixture
Expand Down Expand Up @@ -125,6 +127,34 @@ def test_nonexistent_file(self, runner, tmpdir):
last_line = result.output.splitlines()[-1]
assert last_line == 'Error: file %s does not exist.' % str(fn)

def test_plurals(self, runner, tmpdir):
po_file = build_po_string(
'#: test_project/base/views.py:12 test_project/base/views.py:22\n'
'#, python-format\n'
'msgid "%(num)s apple"\n'
'msgid_plural "%(num)s apples"\n'
'msgstr[0] ""\n'
'msgstr[1] ""\n'
)
fn = tmpdir.join('django.po')
fn.write(po_file)

result = runner.invoke(cli, ('translate', '-p', 'shouty', str(fn)))
assert result.exit_code == 0
pot_file = nix_header(fn.read())
# FIXME: This has the wrong variables, too. We need to fix that, too.
assert (
pot_file ==
dedent("""\
#: test_project/base/views.py:12 test_project/base/views.py:22
#, python-format
msgid "%(num)s apple"
msgid_plural "%(num)s apples"
msgstr[0] "%(NUM)S APPLE"
msgstr[1] "%(NUM)S APPLES"
""")
)


class TestLint:
def test_help(self, runner):
Expand Down

0 comments on commit a59a9bb

Please sign in to comment.