Skip to content

Commit

Permalink
feat: add French translations [BB-4504] (#3)
Browse files Browse the repository at this point in the history
This ports fr_CA translations from raccoongang/xblock-pdf.
  • Loading branch information
Agrendalath authored Jul 23, 2021
1 parent ad83cf0 commit b4e404b
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 34 deletions.
65 changes: 42 additions & 23 deletions pdf/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

'''
Expand All @@ -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."
)
)

'''
Expand Down Expand Up @@ -85,24 +89,27 @@ 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 = {
'url': self.url,
'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')
Expand All @@ -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')
Expand All @@ -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']
Expand All @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<div class="wrapper-comp-setting">
<label class="label setting-label" for="pdf_edit_allow_download">{% trans "PDF Download Allowed" %}</label>
<select class="input setting-input" id="pdf_edit_allow_download">
<option value="True" {% if allow_download %}selected{% endif %}>True</option>
<option value="False" {% if not allow_download %}selected{% endif %}>False</option>
<option value="True" {% if allow_download %}selected{% endif %}>{% trans "True" %}</option>
<option value="False" {% if not allow_download %}selected{% endif %}>{% trans "False" %}</option>
</select>
</div>
<span class="tip setting-help">{% trans "Display a download button for this PDF." %}</span>
Expand All @@ -33,7 +33,7 @@
<li class="field comp-setting-entry is-set">
<div class="wrapper-comp-setting">
<label class="label setting-label" for="pdf_edit_source_text">{% trans "Source document button text" %}</label>
<input class="input setting-input" id="pdf_edit_source_text" value="{{ source_text }}" type="text" placeholder="Default : Download the source document">
<input class="input setting-input" id="pdf_edit_source_text" value="{{ source_text }}" type="text" placeholder="{% trans 'Default : Download the source document' %}">
</div>
<div class="wrapper-comp-setting">
<label class="label setting-label" for="pdf_edit_source_url">{% trans "Source document URL" %}</label>
Expand Down
File renamed without changes.
Binary file added pdf/translations/en/LC_MESSAGES/text.mo
Binary file not shown.
101 changes: 101 additions & 0 deletions pdf/translations/en/LC_MESSAGES/text.po
Original file line number Diff line number Diff line change
@@ -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 <EMAIL@ADDRESS>, 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 ""
Binary file added pdf/translations/fr/LC_MESSAGES/text.mo
Binary file not shown.
109 changes: 109 additions & 0 deletions pdf/translations/fr/LC_MESSAGES/text.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# 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.
#
# Translators:
# Etienne Laurin <etienne.laurin@gmail.com>, 2018
# Pierre Mailhot <pierre.mailhot@gmail.com>, 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 <pierre.mailhot@gmail.com>, 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"
Loading

0 comments on commit b4e404b

Please sign in to comment.