From b4e404b1f94ffab15c52de5c1382d61235cd8c81 Mon Sep 17 00:00:00 2001 From: Piotr Surowiec Date: Fri, 23 Jul 2021 18:27:17 +0200 Subject: [PATCH] feat: add French translations [BB-4504] (#3) This ports fr_CA translations from raccoongang/xblock-pdf. --- pdf/pdf.py | 65 +++++++---- pdf/{static => templates}/html/pdf_edit.html | 6 +- pdf/{static => templates}/html/pdf_view.html | 0 pdf/translations/en/LC_MESSAGES/text.mo | Bin 0 -> 346 bytes pdf/translations/en/LC_MESSAGES/text.po | 101 +++++++++++++++++ pdf/translations/fr/LC_MESSAGES/text.mo | Bin 0 -> 2148 bytes pdf/translations/fr/LC_MESSAGES/text.po | 109 +++++++++++++++++++ pdf/utils.py | 27 ++++- setup.py | 20 ++-- 9 files changed, 294 insertions(+), 34 deletions(-) rename pdf/{static => templates}/html/pdf_edit.html (93%) rename pdf/{static => templates}/html/pdf_view.html (100%) create mode 100644 pdf/translations/en/LC_MESSAGES/text.mo create mode 100644 pdf/translations/en/LC_MESSAGES/text.po create mode 100644 pdf/translations/fr/LC_MESSAGES/text.mo create mode 100644 pdf/translations/fr/LC_MESSAGES/text.po diff --git a/pdf/pdf.py b/pdf/pdf.py index 9ee0ef6..0652506 100644 --- a/pdf/pdf.py +++ b/pdf/pdf.py @@ -6,13 +6,13 @@ from xblock.core import XBlock from xblock.fields import Scope, String, Boolean from xblock.fragment import Fragment +from xblockutils.resources import ResourceLoader +from .utils import _, bool_from_str, DummyTranslationService, is_all_download_disabled -from pdf.utils import ( - bool_from_str, - is_all_download_disabled, -) +loader = ResourceLoader(__name__) +@XBlock.needs('i18n') class PdfBlock(XBlock): ''' @@ -24,40 +24,44 @@ class PdfBlock(XBlock): Fields ''' display_name = String( - display_name="Display Name", - default="PDF", + display_name=_("Display Name"), + default=_("PDF"), scope=Scope.settings, - help="This name appears in the horizontal navigation at the top of the page." + help=_("This name appears in the horizontal navigation at the top of the page.") ) url = String( - display_name="PDF URL", - default="https://tutorial.math.lamar.edu/pdf/Trig_Cheat_Sheet.pdf", + display_name=_("PDF URL"), + default=_("https://tutorial.math.lamar.edu/pdf/Trig_Cheat_Sheet.pdf"), scope=Scope.content, - help="The URL for your PDF." + help=_("The URL for your PDF.") ) allow_download = Boolean( - display_name="PDF Download Allowed", + display_name=_("PDF Download Allowed"), default=True, scope=Scope.content, - help="Display a download button for this PDF." + help=_("Display a download button for this PDF.") ) source_text = String( - display_name="Source document button text", + display_name=_("Source document button text"), default="", scope=Scope.content, - help="Add a download link for the source file of your PDF. " + help=_( + "Add a download link for the source file of your PDF. " "Use it for example to provide the PowerPoint file used to create this PDF." + ) ) source_url = String( - display_name="Source document URL", + display_name=_("Source document URL"), default="", scope=Scope.content, - help="Add a download link for the source file of your PDF. " + help=_( + "Add a download link for the source file of your PDF. " "Use it for example to provide the PowerPoint file used to create this PDF." + ) ) ''' @@ -85,16 +89,20 @@ def student_view(self, context=None): The primary view of the XBlock, shown to students when viewing courses. """ - context = { 'display_name': self.display_name, 'url': self.url, 'allow_download': self.allow_download, 'disable_all_download': is_all_download_disabled(), 'source_text': self.source_text, - 'source_url': self.source_url + 'source_url': self.source_url, + '_i18n_service': self.i18n_service, } - html = self.render_template('static/html/pdf_view.html', context) + html = loader.render_django_template( + 'templates/html/pdf_view.html', + context=context, + i18n_service=self.i18n_service, + ) event_type = 'edx.pdf.loaded' event_data = { @@ -102,7 +110,6 @@ def student_view(self, context=None): 'source_url': self.source_url, } self.runtime.publish(self, event_type, event_data) - frag = Fragment(html) frag.add_javascript(self.load_resource("static/js/pdf_view.js")) frag.initialize_js('pdfXBlockInitView') @@ -121,8 +128,11 @@ def studio_view(self, context=None): 'source_text': self.source_text, 'source_url': self.source_url } - html = self.render_template('static/html/pdf_edit.html', context) - + html = loader.render_django_template( + 'templates/html/pdf_edit.html', + context=context, + i18n_service=self.i18n_service, + ) frag = Fragment(html) frag.add_javascript(self.load_resource("static/js/pdf_edit.js")) frag.initialize_js('pdfXBlockInitEdit') @@ -147,7 +157,7 @@ def save_pdf(self, data, suffix=''): """ self.display_name = data['display_name'] self.url = data['url'] - + if not is_all_download_disabled(): self.allow_download = bool_from_str(data['allow_download']) self.source_text = data['source_text'] @@ -156,3 +166,12 @@ def save_pdf(self, data, suffix=''): return { 'result': 'success', } + + @property + def i18n_service(self): + """ Obtains translation service """ + i18n_service = self.runtime.service(self, "i18n") + if i18n_service: + return i18n_service + else: + return DummyTranslationService() diff --git a/pdf/static/html/pdf_edit.html b/pdf/templates/html/pdf_edit.html similarity index 93% rename from pdf/static/html/pdf_edit.html rename to pdf/templates/html/pdf_edit.html index cbabedd..908f7eb 100644 --- a/pdf/static/html/pdf_edit.html +++ b/pdf/templates/html/pdf_edit.html @@ -23,8 +23,8 @@
{% trans "Display a download button for this PDF." %} @@ -33,7 +33,7 @@
  • - +
    diff --git a/pdf/static/html/pdf_view.html b/pdf/templates/html/pdf_view.html similarity index 100% rename from pdf/static/html/pdf_view.html rename to pdf/templates/html/pdf_view.html diff --git a/pdf/translations/en/LC_MESSAGES/text.mo b/pdf/translations/en/LC_MESSAGES/text.mo new file mode 100644 index 0000000000000000000000000000000000000000..3a91d7874fcedfd53f5825d050133dbe7823273d GIT binary patch literal 346 zcmYL^&q~BF5XM*Z)T3t)5j-e5Zd(6!TY6DYu>Q(u&Ch?t<#1Q5iGGY)p&uBU~;T6=NEVMjmW CZC{W8 literal 0 HcmV?d00001 diff --git a/pdf/translations/en/LC_MESSAGES/text.po b/pdf/translations/en/LC_MESSAGES/text.po new file mode 100644 index 0000000..0c7b947 --- /dev/null +++ b/pdf/translations/en/LC_MESSAGES/text.po @@ -0,0 +1,101 @@ +# 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 , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-07-19 16:52+0200\n" +"PO-Revision-Date: 2021-07-19 16:54+0200\n" +"Language: en\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" +"Last-Translator: \n" +"Language-Team: \n" +"X-Generator: Poedit 3.0\n" + +#: pdf/pdf.py:27 +msgid "Display Name" +msgstr "" + +#: pdf/pdf.py:28 +msgid "PDF" +msgstr "" + +#: pdf/pdf.py:30 pdf/templates/html/pdf_edit.html:10 +msgid "This name appears in the horizontal navigation at the top of the page." +msgstr "" + +#: pdf/pdf.py:34 pdf/templates/html/pdf_edit.html:15 +msgid "PDF URL" +msgstr "" + +#: pdf/pdf.py:35 +msgid "https://tutorial.math.lamar.edu/pdf/Trig_Cheat_Sheet.pdf" +msgstr "" + +#: pdf/pdf.py:37 pdf/templates/html/pdf_edit.html:18 +msgid "The URL for your PDF." +msgstr "" + +#: pdf/pdf.py:41 pdf/templates/html/pdf_edit.html:24 +msgid "PDF Download Allowed" +msgstr "" + +#: pdf/pdf.py:44 pdf/templates/html/pdf_edit.html:30 +msgid "Display a download button for this PDF." +msgstr "" + +#: pdf/pdf.py:48 pdf/templates/html/pdf_edit.html:35 +msgid "Source document button text" +msgstr "" + +#: pdf/pdf.py:52 pdf/pdf.py:62 pdf/templates/html/pdf_edit.html:42 +msgid "" +"Add a download link for the source file of your PDF. Use it for example to " +"provide the PowerPoint file used to create this PDF." +msgstr "" + +#: pdf/pdf.py:58 pdf/templates/html/pdf_edit.html:39 +msgid "Source document URL" +msgstr "" + +#: pdf/templates/html/pdf_edit.html:7 +msgid "Name" +msgstr "" + +#: pdf/templates/html/pdf_edit.html:26 +msgid "True" +msgstr "" + +#: pdf/templates/html/pdf_edit.html:27 +msgid "False" +msgstr "" + +#: pdf/templates/html/pdf_edit.html:36 +msgid "Default : Download the source document" +msgstr "" + +#: pdf/templates/html/pdf_edit.html:51 +msgid "Save" +msgstr "" + +#: pdf/templates/html/pdf_edit.html:54 +msgid "Cancel" +msgstr "" + +#: pdf/templates/html/pdf_view.html:6 +msgid "It appears you don't have a PDF plugin for this browser." +msgstr "" + +#: pdf/templates/html/pdf_view.html:13 +msgid "Download the PDF" +msgstr "" + +#: pdf/templates/html/pdf_view.html:18 +msgid "Download the source document" +msgstr "" diff --git a/pdf/translations/fr/LC_MESSAGES/text.mo b/pdf/translations/fr/LC_MESSAGES/text.mo new file mode 100644 index 0000000000000000000000000000000000000000..7f6c1b9b1572a5f8728b9ab4640ae83a765d0ba9 GIT binary patch literal 2148 zcmbW1%WoS+9LEPJFPBFtj|&ftI5Y`m{Rkwa4ykbM8bwN4D{)#RK+)LyTYJiSXPKR~ zom}9;4GECofW)EVgfILB+}s=IUJ>mL4jedf1%Y z2Y;H5e+8=;-v?Rlg(oIkzAu&Z%^(Vm@@1%_Ph?=MbX}5(No|{CphJ=-kOvsbMy;Ng zdkIPHvVAmEy%_7x$k>{`_VJ0M4KpCyFgn66KAtAz^PaXP<#>xuGEt(cqBe!1MuAF0 zC(E)nGv$~CzG|>qHr9FDNk{wMm9&$1O@ryib#I6Inm2hhJchDdE-sh6 z;yYgHk}R#3S5__-my5;RmP(x0v?@wM1#`->p~+g3+e(LBHinJa_`ME)_E@V32pLM+Y=y0R@-G(d}QWZFiTW!nbgstOe3TSgxoPX7HOY4%KC`abo#V$O}sipE0wKj47g@ZistlA#nz;HWF{S5 wuBgH~1QpdzSvCIINguCMhH7Rr7mcG*f+~}u4&t)lDK<@t#|^9W|1Tc@0, YEAR. +# +# Translators: +# Etienne Laurin , 2018 +# Pierre Mailhot , 2019 +# +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-09-06 15:43+0300\n" +"PO-Revision-Date: 2021-07-19 16:55+0200\n" +"Last-Translator: Pierre Mailhot , 2019\n" +"Language-Team: French (Canada) (https://www.transifex.com/open-edx/" +"teams/6205/fr_CA/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Language: fr\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" +"X-Generator: Poedit 3.0\n" + +#: pdf/pdf.py:27 +msgid "Display Name" +msgstr "Nom d'affichage" + +#: pdf/pdf.py:28 +msgid "PDF" +msgstr "PDF" + +#: pdf/pdf.py:30 pdf/templates/html/pdf_edit.html:10 +msgid "This name appears in the horizontal navigation at the top of the page." +msgstr "Ce nom apparaît dans la navigation horizontale au haut de la page." + +#: pdf/pdf.py:34 pdf/templates/html/pdf_edit.html:15 +msgid "PDF URL" +msgstr "URL du PDF" + +#: pdf/pdf.py:35 +msgid "https://tutorial.math.lamar.edu/pdf/Trig_Cheat_Sheet.pdf" +msgstr "https://tutorial.math.lamar.edu/pdf/Trig_Cheat_Sheet.pdf" + +#: pdf/pdf.py:37 pdf/templates/html/pdf_edit.html:18 +msgid "The URL for your PDF." +msgstr "Le URL pour votre PDF." + +#: pdf/pdf.py:41 pdf/templates/html/pdf_edit.html:24 +msgid "PDF Download Allowed" +msgstr "Téléchargement PDF autorisé" + +#: pdf/pdf.py:44 pdf/templates/html/pdf_edit.html:30 +msgid "Display a download button for this PDF." +msgstr "Afficher un blouton de téléchargement pour ce PDF." + +#: pdf/pdf.py:48 pdf/templates/html/pdf_edit.html:35 +msgid "Source document button text" +msgstr "Texte du bouton du document source" + +#: pdf/pdf.py:52 pdf/pdf.py:62 pdf/templates/html/pdf_edit.html:42 +msgid "" +"Add a download link for the source file of your PDF. Use it for example to " +"provide the PowerPoint file used to create this PDF." +msgstr "" +"Ajoutez un lien de téléchargement pour le fichier source de votre PDF. " +"Utilisez-le par exemple pour fournir le fichier PowerPoint utilisé pour " +"créer ce PDF." + +#: pdf/pdf.py:58 pdf/templates/html/pdf_edit.html:39 +msgid "Source document URL" +msgstr "URL du document source" + +#: pdf/templates/html/pdf_edit.html:7 +msgid "Name" +msgstr "Nom" + +#: pdf/templates/html/pdf_edit.html:26 +msgid "True" +msgstr "Vrai" + +#: pdf/templates/html/pdf_edit.html:27 +msgid "False" +msgstr "Faux" + +#: pdf/templates/html/pdf_edit.html:36 +msgid "Default : Download the source document" +msgstr "Défaut : Téléchargez le document source" + +#: pdf/templates/html/pdf_edit.html:51 +msgid "Save" +msgstr "Sauvegarder" + +#: pdf/templates/html/pdf_edit.html:54 +msgid "Cancel" +msgstr "Annuler" + +#: pdf/templates/html/pdf_view.html:6 +msgid "It appears you don't have a PDF plugin for this browser." +msgstr "Il semble que vous n’ayez pas de plug-in PDF pour ce navigateur." + +#: pdf/templates/html/pdf_view.html:13 +msgid "Download the PDF" +msgstr "Téléchargez le PDF" + +#: pdf/templates/html/pdf_view.html:18 +msgid "Download the source document" +msgstr "Téléchargez le document source" diff --git a/pdf/utils.py b/pdf/utils.py index 90eda4b..eb8e7f1 100644 --- a/pdf/utils.py +++ b/pdf/utils.py @@ -1,5 +1,5 @@ """ -Utility functions for XBlock +Utility functions for PDF XBlock """ from django.conf import settings @@ -19,3 +19,28 @@ def is_all_download_disabled(): Check if all download is disabled or not """ return getattr(settings, 'PDFXBLOCK_DISABLE_ALL_DOWNLOAD', False) + + +def _(text): + """ + Dummy `gettext` replacement to make string extraction tools scrape strings marked for translation + """ + return text + + +def ngettext_fallback(text_singular, text_plural, number): + """ + Dummy `ngettext` replacement to make string extraction tools scrape strings marked for translation + """ + if number == 1: + return text_singular + else: + return text_plural + + +class DummyTranslationService(object): + """ + Dummy drop-in replacement for i18n XBlock service + """ + gettext = _ + ngettext = ngettext_fallback diff --git a/setup.py b/setup.py index badafeb..d7a97ed 100644 --- a/setup.py +++ b/setup.py @@ -4,30 +4,36 @@ from setuptools import setup -def package_data(pkg, root): - """Generic function to find package_data for `pkg` under `root`.""" +def package_data(pkg, roots): + """ + Generic function to find package_data. + + All of the files under each of the `roots` will be declared as package data for package `pkg`. + """ data = [] - for dirname, _, files in os.walk(os.path.join(pkg, root)): - for fname in files: - data.append(os.path.relpath(os.path.join(dirname, fname), pkg)) + for root in roots: + for dirname, _, files in os.walk(os.path.join(pkg, root)): + for fname in files: + data.append(os.path.relpath(os.path.join(dirname, fname), pkg)) return {pkg: data} setup( name='xblock-pdf', - version='1.0.4', + version='1.1.0', description='Course component (Open edX XBlock) that provides an easy way to embed a PDF', packages=[ 'pdf', ], install_requires=[ 'XBlock', + 'xblock-utils', ], entry_points={ 'xblock.v1': [ 'pdf = pdf.pdf:PdfBlock', ] }, - package_data=package_data('pdf', 'static'), + package_data=package_data('pdf', ['static', 'templates', 'translations']), )