forked from torchbox/wagtail-footnotes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable translation (rebased) (torchbox#69)
* Make footnote model translatable * Make package strings translatable * Add Romanian translation * Add i18n notes in README --------- Co-authored-by: Jhonatan Lopes <[email protected]>
- Loading branch information
1 parent
9ded66b
commit 62f0176
Showing
17 changed files
with
435 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,6 @@ coverage.xml | |
cover/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import json | ||
|
||
from bs4 import BeautifulSoup as bs4 | ||
from django.test import override_settings | ||
from django.urls import reverse | ||
from django.utils import translation | ||
from wagtail.models import Locale, Page | ||
from wagtail.test.utils import TestCase, WagtailTestUtils | ||
|
||
from wagtail_footnotes.models import Footnote | ||
|
||
from ..models import TestPageStreamField | ||
|
||
|
||
@override_settings( | ||
LANGUAGES=[ | ||
("en", "English"), | ||
("fr", "French"), | ||
("de", "German"), | ||
], | ||
WAGTAIL_CONTENT_LANGUAGES=[ | ||
("en", "English"), | ||
("fr", "French"), | ||
("de", "German"), | ||
], | ||
) | ||
class TestSubmitPageTranslationView(WagtailTestUtils, TestCase): | ||
@classmethod | ||
def setUpTestData(cls): | ||
cls.en_locale = Locale.objects.first() | ||
cls.fr_locale = Locale.objects.create(language_code="fr") | ||
cls.de_locale = Locale.objects.create(language_code="de") | ||
|
||
cls.en_homepage = Page.objects.get(title="Welcome to your new Wagtail site!") | ||
cls.fr_homepage = cls.en_homepage.copy_for_translation(cls.fr_locale) | ||
cls.fr_homepage.save_revision().publish() | ||
cls.de_homepage = cls.en_homepage.copy_for_translation(cls.de_locale) | ||
cls.de_homepage.save_revision().publish() | ||
|
||
cls.uuid = "f291a4b7-5ac5-4030-b341-b1993efb2ad2" | ||
cls.en_test_page = TestPageStreamField( | ||
title="Test Page With Footnote", | ||
slug="test-page-with-footnote", | ||
body=json.dumps( | ||
[ | ||
{ | ||
"type": "paragraph", | ||
"value": f'<p>This is a paragraph with a footnote. <footnote id="{cls.uuid}">1</footnote></p>', | ||
}, | ||
] | ||
), | ||
) | ||
cls.en_homepage.add_child(instance=cls.en_test_page) | ||
cls.en_test_page.save_revision().publish() | ||
cls.en_footnote = Footnote.objects.create( | ||
page=cls.en_test_page, | ||
uuid=cls.uuid, | ||
text="This is a footnote", | ||
) | ||
cls.url = reverse( | ||
"simple_translation:submit_page_translation", args=(cls.en_test_page.id,) | ||
) | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.login() | ||
|
||
def test_translating_page_translates_footnote(self): | ||
de = self.de_locale.id | ||
fr = self.fr_locale.id | ||
data = {"locales": [de, fr], "include_subtree": True} | ||
self.client.post(self.url, data, follow=True) | ||
|
||
de_footnote = self.en_footnote.get_translation(de) | ||
self.assertEqual(de_footnote.text, self.en_footnote.text) | ||
self.assertEqual(de_footnote.uuid, self.en_footnote.uuid) | ||
de_test_page = self.en_test_page.get_translation(de) | ||
self.assertCountEqual(de_test_page.footnotes.all(), [de_footnote]) | ||
|
||
fr_footnote = self.en_footnote.get_translation(fr) | ||
self.assertEqual(fr_footnote.text, self.en_footnote.text) | ||
self.assertEqual(fr_footnote.uuid, self.en_footnote.uuid) | ||
fr_test_page = self.en_test_page.get_translation(fr) | ||
self.assertCountEqual(fr_test_page.footnotes.all(), [fr_footnote]) | ||
|
||
# Can also change the text: | ||
fr_footnote.text = "This is a French translated footnote" | ||
fr_footnote.save(update_fields=["text"]) | ||
fr_footnote.refresh_from_db() | ||
en_footnote = self.en_footnote | ||
en_footnote.refresh_from_db() | ||
self.assertEqual(fr_footnote.text, "This is a French translated footnote") | ||
self.assertNotEqual(fr_footnote.text, en_footnote.text) | ||
|
||
def test_translated_page_shows_translated_footnote(self): | ||
fr = self.fr_locale.id | ||
data = {"locales": [fr], "include_subtree": True} | ||
response = self.client.post(self.url, data, follow=True) | ||
|
||
fr_test_page = self.en_test_page.get_translation(fr) | ||
|
||
self.assertRedirects( | ||
response, reverse("wagtailadmin_pages:edit", args=[fr_test_page.pk]) | ||
) | ||
|
||
self.assertIn( | ||
"The page 'Test Page With Footnote' was successfully created in French", | ||
[msg.message for msg in response.context["messages"]], | ||
) | ||
|
||
fr_footnote = self.en_footnote.get_translation(fr) | ||
self.assertEqual(fr_footnote.text, self.en_footnote.text) | ||
self.assertEqual(fr_footnote.uuid, self.en_footnote.uuid) | ||
self.assertCountEqual(fr_test_page.footnotes.all(), [fr_footnote]) | ||
|
||
fr_test_page.title = ("[FR] Test Page With Footnote",) | ||
fr_test_page.body = json.dumps( | ||
[ | ||
{ | ||
"type": "paragraph", | ||
"value": f'<p>This is a French paragraph with a footnote. <footnote id="{self.uuid}">1</footnote></p>', | ||
}, | ||
] | ||
) | ||
fr_test_page.save_revision().publish() | ||
fr_test_page.refresh_from_db() | ||
|
||
# Can also change the text: | ||
fr_footnote.text = "This is a French translated footnote" | ||
fr_footnote.save() | ||
|
||
translation.activate("fr") | ||
|
||
response = self.client.get(fr_test_page.get_full_url()) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
soup = bs4(response.content, "html.parser") | ||
|
||
# Test that required html tags are present with correct | ||
# attrs that enable the footnotes to respond to clicks | ||
source_anchor = soup.find("a", {"id": "footnote-source-1"}) | ||
self.assertTrue(source_anchor) | ||
|
||
source_anchor_string = str(source_anchor) | ||
self.assertIn("<sup>[1]</sup>", source_anchor_string) | ||
self.assertIn('href="#footnote-1"', source_anchor_string) | ||
self.assertIn('id="footnote-source-1"', source_anchor_string) | ||
|
||
footnotes = soup.find("div", {"class": "footnotes"}) | ||
self.assertTrue(footnotes) | ||
|
||
footnotes_string = str(footnotes) | ||
self.assertIn('id="footnote-1"', footnotes_string) | ||
self.assertIn('href="#footnote-source-1"', footnotes_string) | ||
self.assertIn("[1] This is a French translated footnote", footnotes_string) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# SOME DESCRIPTIVE TITLE. | ||
# Copyright (C) 2024 Torchbox | ||
# This file is distributed under the same license as the PACKAGE package. | ||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. | ||
# | ||
#, fuzzy | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: PACKAGE VERSION\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-05-17 09:04-0500\n" | ||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Language-Team: LANGUAGE <[email protected]>\n" | ||
"Language: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Plural-Forms: nplurals=2; plural=(n != 1);\n" | ||
#: templates/wagtail_footnotes/admin/footnotes_modal.html:14 | ||
msgid "Choose a footnote" | ||
msgstr "" | ||
|
||
#: templates/wagtail_footnotes/admin/footnotes_modal.html:26 | ||
msgid "Footnotes" | ||
msgstr "" | ||
|
||
#: templates/wagtail_footnotes/admin/footnotes_modal.html:28 | ||
msgid "" | ||
"To add a new footnote, close this window and scroll to the \"Footnotes\" " | ||
"section at bottom of the page." | ||
msgstr "" | ||
|
||
#: templates/wagtail_footnotes/admin/footnotes_modal.html:36 | ||
msgid "Text" | ||
msgstr "" | ||
|
||
#: templates/wagtail_footnotes/admin/footnotes_modal.html:37 | ||
msgid "ID" | ||
msgstr "" | ||
|
||
#: templates/wagtail_footnotes/admin/footnotes_modal.html:45 | ||
msgid "" | ||
"Footnotes will appear with arbitrary numbers here in the editor. On the " | ||
"published page, and in previews, their numbering will be numerical and " | ||
"ordered." | ||
msgstr "" | ||
|
||
#: templates/wagtail_footnotes/includes/footnotes.html:6 | ||
msgid "Foonotes" | ||
msgstr "" | ||
|
||
#: templates/wagtail_footnotes/includes/footnotes.html:12 | ||
msgid "Back to content" | ||
msgstr "" |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# 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. | ||
# | ||
#, fuzzy | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: \n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-05-17 09:06-0500\n" | ||
"PO-Revision-Date: 2024-05-17 15:23+0100\n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"Language: ro\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n==0 || (n!=1 && n%100>=1 && " | ||
"n%100<=19) ? 1 : 2);\n" | ||
"X-Generator: Poedit 3.4.4\n" | ||
|
||
#: templates/wagtail_footnotes/admin/footnotes_modal.html:14 | ||
msgid "Choose a footnote" | ||
msgstr "Alegeți o notă de subsol" | ||
|
||
#: templates/wagtail_footnotes/admin/footnotes_modal.html:26 | ||
msgid "Footnotes" | ||
msgstr "Note de subsol" | ||
|
||
#: templates/wagtail_footnotes/admin/footnotes_modal.html:28 | ||
msgid "" | ||
"To add a new footnote, close this window and scroll to the \"Footnotes\" " | ||
"section at bottom of the page." | ||
msgstr "" | ||
"Pentru a adăuga o notă nouă de subsol, închideți această fereastră și " | ||
"derulați la secțiunea „Note de subsol”." | ||
|
||
#: templates/wagtail_footnotes/admin/footnotes_modal.html:36 | ||
msgid "Text" | ||
msgstr "Text" | ||
|
||
#: templates/wagtail_footnotes/admin/footnotes_modal.html:37 | ||
msgid "ID" | ||
msgstr "ID" | ||
|
||
#: templates/wagtail_footnotes/admin/footnotes_modal.html:45 | ||
msgid "" | ||
"Footnotes will appear with arbitrary numbers here in the editor. On the " | ||
"published page, and in previews, their numbering will be numerical and " | ||
"ordered." | ||
msgstr "" | ||
"Notele de subsol vor apărea ca un set de numere și cifre aleatorii în " | ||
"editorul de text. Pe pagina publicată și în previzualizări, numerotarea va " | ||
"fi numerică și ordonată." | ||
|
||
#: templates/wagtail_footnotes/includes/footnotes.html:6 | ||
msgid "Foonotes" | ||
msgstr "Note de subsol" | ||
|
||
#: templates/wagtail_footnotes/includes/footnotes.html:12 | ||
msgid "Back to content" | ||
msgstr "Înapoi la conținut" |
Oops, something went wrong.