Allow searching of plural strings (source & translation). Closes #186.

This commit is contained in:
Jon Baldivieso 2018-01-10 12:03:01 -08:00
parent 20c7ff4a07
commit a701097073
3 changed files with 70 additions and 1 deletions

View file

@ -0,0 +1,38 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: Rosetta\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2009-10-21 12:21+0200\n"
"PO-Revision-Date: 2008-09-22 11:02\n"
"Last-Translator: Admin Admin <admin@admin.com>\n"
"Language-Team: French <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Translated-Using: django-rosetta 0.4.RC2\n"
msgid "String 1"
msgstr ""
msgid "String 2"
msgstr ""
#. Translators: This is a text of the base template
#: templates/base.html:43
msgid "String 3 with comment"
msgstr ""
msgctxt "Context hint"
msgid "String 4"
msgstr ""
msgid "%d Child"
msgid_plural "%d Childrenen"
msgstr[0] "%d Tchilt"
msgstr[1] "%d Tchildren"

View file

@ -938,6 +938,35 @@ class RosettaTestCase(TestCase):
r = self.client.get(url % 'adipisicing')
self.assertContains(r, 'Lorem')
def test_45_issue186_plural_msg_search(self):
"""Confirm that search of the .po file works for plurals.
"""
self.copy_po_file_from_template('./django.po.issue186.template')
url = self.xx_form_url + '?query=%s'
# Here's the message entry we're considering:
# msgstr "%d Child"
# msgid_plural "%d Childrenen"
# msgstr[0] "%d Tchilt"
# msgstr[1] "%d Tchildren"
# First, confirm that we don't ALWAYS see this particular message on the
# page.
r = self.client.get(url % 'kids')
self.assertNotContains(r, 'Child')
# Search msgid_plural
r = self.client.get(url % 'childrenen')
self.assertContains(r, 'Child')
# Search msgstr[0]
r = self.client.get(url % 'tchilt')
self.assertContains(r, 'Child')
# Search msgstr[1]
r = self.client.get(url % 'tchildren')
self.assertContains(r, 'Child')
# Stubbed access control function
def no_access(user):

View file

@ -620,7 +620,9 @@ class TranslationFormView(RosettaFileLevelMixin, TemplateView):
return (six.text_type(e.msgstr) +
six.text_type(e.msgid) +
six.text_type(e.comment) +
u''.join([o[0] for o in e.occurrences])
u''.join([o[0] for o in e.occurrences]) +
six.text_type(e.msgid_plural) +
u''.join(e.msgstr_plural.values())
)
entries = [e_ for e_ in self.po_file