Skip to content

Commit

Permalink
temp: review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
xitij2000 committed Aug 2, 2024
1 parent a29e779 commit 2c641cf
Show file tree
Hide file tree
Showing 16 changed files with 443 additions and 422 deletions.
147 changes: 18 additions & 129 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,142 +10,31 @@ This XBlock comes with a Docker test environment ready to build, based on the xb

The XBlock SDK Workbench, including this XBlock, will be available on the list of XBlocks at http://localhost:8000

Translating
*************

Internationalization (i18n) is when a program is made aware of multiple languages.
Localization (l10n) is adapting a program to local language and cultural habits.

Use the locale directory to provide internationalized strings for your XBlock project.
For more information on how to enable translations, visit the
`Open edX XBlock tutorial on Internationalization <https://edx.readthedocs.org/projects/xblock-tutorial/en/latest/edx_platform/edx_lms.html>`_.

This cookiecutter template uses `django-statici18n <https://django-statici18n.readthedocs.io/en/latest/>`_
to provide translations to static javascript using ``gettext``.

The included Makefile contains targets for extracting, compiling and validating translatable strings.
The general steps to provide multilingual messages for a Python program (or an XBlock) are:

1. Mark translatable strings.
2. Run i18n tools to create raw message catalogs.
3. Create language specific translations for each message in the catalogs.
4. Use ``gettext`` to translate strings.

1. Mark translatable strings
=============================

Mark translatable strings in python::


from django.utils.translation import ugettext as _

# Translators: This comment will appear in the `.po` file.
message = _("This will be marked.")

See `edx-developer-guide <https://edx.readthedocs.io/projects/edx-developer-guide/en/latest/internationalization/i18n.html#python-source-code>`__
for more information.

You can also use ``gettext`` to mark strings in javascript::


// Translators: This comment will appear in the `.po` file.
var message = gettext("Custom message.");

See `edx-developer-guide <https://edx.readthedocs.io/projects/edx-developer-guide/en/latest/internationalization/i18n.html#javascript-files>`__
for more information.

2. Run i18n tools to create Raw message catalogs
=================================================

This cookiecutter template offers multiple make targets which are shortcuts to
use `edx-i18n-tools <https://github.com/openedx/i18n-tools>`_.

After marking strings as translatable we have to create the raw message catalogs.
These catalogs are created in ``.po`` files. For more information see
`GNU PO file documentation <https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html>`_.
These catalogs can be created by running::


$ make extract_translations

The previous command will create the necessary ``.po`` files under
``xblock-accordion/accordion/conf/locale/en/LC_MESSAGES/text.po``.
The ``text.po`` file is created from the ``django-partial.po`` file created by
``django-admin makemessages`` (`makemessages documentation <https://docs.djangoproject.com/en/3.2/topics/i18n/translation/#message-files>`_),
this is why you will not see a ``django-partial.po`` file.

3. Create language specific translations
==============================================

3.1 Add translated strings
---------------------------

After creating the raw message catalogs, all translations should be filled out by the translator.
One or more translators must edit the entries created in the message catalog, i.e. the ``.po`` file(s).
The format of each entry is as follows::

# translator-comments
A. extracted-comments
#: reference…
#, flag…
#| msgid previous-untranslated-string
msgid 'untranslated message'
msgstr 'mensaje traducido (translated message)'

For more information see
`GNU PO file documentation <https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html>`_.

To use translations from transifex use the follow Make target to pull translations::

$ make pull_translations

See `config instructions <https://github.com/openedx/i18n-tools#transifex-commands>`_ for information on how to set up your
transifex credentials.

See `transifex documentation <https://docs.transifex.com/integrations/django>`_ for more details about integrating
django with transiflex.

3.2 Compile translations
-------------------------

Once translations are in place, use the following Make target to compile the translation catalogs ``.po`` into
``.mo`` message files::

$ make compile_translations

The previous command will compile ``.po`` files using
``django-admin compilemessages`` (`compilemessages documentation <https://docs.djangoproject.com/en/3.2/topics/i18n/translation/#compiling-message-files>`_).
After compiling the ``.po`` file(s), ``django-statici18n`` is used to create language specific catalogs. See
``django-statici18n`` `documentation <https://django-statici18n.readthedocs.io/en/latest/>`_ for more information.

To upload translations to transiflex use the follow Make target::

$ make push_translations

See `config instructions <https://github.com/openedx/i18n-tools#transifex-commands>`_ for information on how to set up your
transifex credentials.
Testing frontend
****************

See `transifex documentation <https://docs.transifex.com/integrations/django>`_ for more details about integrating
django with transiflex.
The frontend code in the XBlock can be tested without the backend running for quicker iteration on the UI.
To do this, just run ``npm run dev`` in the `frontend` folder. This will start a dev server with just the
frontend component. You can open the URL in the terminal and browse to the student or studio components.

**Note:** The ``dev.run`` make target will automatically compile any translations.
Installation
************

**Note:** To check if the source translation files (``.po``) are up-to-date run::
You can install the XBlock with the following command:

$ make detect_changed_source_translations
.. code-block:: bash
4. Use ``gettext`` to translate strings
========================================
pip install xblock-accordion@git+https://github.com/open-craft/xblock-accordion.git
Django will automatically use ``gettext`` and the compiled translations to translate strings.
If using tutor, you can add `xblock-accordion@git+https://github.com/open-craft/xblock-accordion.git` to
`OPENEDX_EXTRA_PIP_REQUIREMENTS` to have the xblock installed on deployment.

Troubleshooting
****************

If there are any errors compiling ``.po`` files run the following command to validate your ``.po`` files::
Usage
*****

$ make validate
To use the XBlock in a course, you need to ensure that you have "accordion" in the
**Advanced Modules List** in the Advanced settings page of the course.

See `django's i18n troubleshooting documentation
<https://docs.djangoproject.com/en/3.2/topics/i18n/translation/#troubleshooting-gettext-incorrectly-detects-python-format-in-strings-with-percent-signs>`_
for more information.
Once added there you will be able to add an Accordion block from the **Advanced Modules*
section of blocks.
34 changes: 34 additions & 0 deletions accordion/conf/locale/en/LC_MESSAGES/django-partial.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# edX translation file.
# Copyright (C) 2024 EdX
# This file is distributed under the GNU AFFERO GENERAL PUBLIC LICENSE.
# EdX Team <[email protected]>, 2024.
#
msgid ""
msgstr ""
"Project-Id-Version: 0.1a\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2023-06-13 08:00+0000\n"
"PO-Revision-Date: 2023-06-13 09:00+0000\n"
"Last-Translator: \n"
"Language-Team: openedx-translation <[email protected]>\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"

#: accordion.py:18
msgid "Accordion"
msgstr ""

#: static/html/accordion.html:6
msgid "Continue"
msgstr ""

#: static/html/accordion.html:10
msgid "Save"
msgstr ""

#: static/html/accordion.html:14
msgid "Cancel"
msgstr ""
38 changes: 38 additions & 0 deletions accordion/conf/locale/en/LC_MESSAGES/text.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# edX translation file.
# Copyright (C) 2024 EdX
# This file is distributed under the GNU AFFERO GENERAL PUBLIC LICENSE.
# EdX Team <[email protected]>, 2024.
#
msgid ""
msgstr ""
"Project-Id-Version: 0.1a\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2023-06-13 08:00+0000\n"
"PO-Revision-Date: 2023-06-13 09:00+0000\n"
"Last-Translator: \n"
"Language-Team: openedx-translation <[email protected]>\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"

#: accordion.py:18
msgid "Accordion"
msgstr ""

#: static/html/accordion.html:6
msgid "Continue"
msgstr ""

#: static/html/accordion.html:10
msgid "Save"
msgstr ""

#: static/html/accordion.html:14
msgid "Cancel"
msgstr ""

#: public/student-ui.js:10
msgid "mewli"
msgstr ""
2 changes: 1 addition & 1 deletion accordion/public/student-ui.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions accordion/public/student-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -7282,14 +7282,14 @@ function Uh({ panels: e, styling: t }) {
/* @__PURE__ */ le.jsxs(
Su,
{
className: "collapsible-trigger rounded-0",
className: "collapsible-trigger rounded-0 px-3 py-2",
style: {
backgroundColor: t == null ? void 0 : t.backgroundColor,
color: t == null ? void 0 : t.textColor,
fontSize: t == null ? void 0 : t.fontSize
},
children: [
/* @__PURE__ */ le.jsx("span", { className: "flex-grow-1", children: u.title }),
/* @__PURE__ */ le.jsx("span", { className: "flex-grow-1 my-0", children: u.title }),
/* @__PURE__ */ le.jsx(_o, { whenClosed: !0, children: /* @__PURE__ */ le.jsx(wo, { src: Fh }) }),
/* @__PURE__ */ le.jsx(_o, { whenOpen: !0, children: /* @__PURE__ */ le.jsx(wo, { src: bh }) })
]
Expand Down
16 changes: 10 additions & 6 deletions accordion/public/studio-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -18895,7 +18895,7 @@ function Kte({
setColor: i,
help: u
}) {
return /* @__PURE__ */ cs.jsxs("div", { className: "d-flex flex-column mb-3", children: [
return /* @__PURE__ */ cs.jsxs("div", { className: "d-flex flex-column pb-3", children: [
/* @__PURE__ */ cs.jsxs("div", { className: "d-flex align-items-center", "data-testid": o, children: [
/* @__PURE__ */ cs.jsx("span", { className: "mr-2", children: o }),
/* @__PURE__ */ cs.jsx(
Expand All @@ -18916,8 +18916,8 @@ function FEe({
}) {
const i = (u) => r({ ...o, ...u });
return /* @__PURE__ */ cs.jsxs("div", { style: { maxWidth: "800px" }, children: [
/* @__PURE__ */ cs.jsx("h2", { className: "mb-2", children: "Styling of Accordions" }),
/* @__PURE__ */ cs.jsxs(H3, { className: "d-flex align-items-center", children: [
/* @__PURE__ */ cs.jsx("h3", { className: "mb-2", children: "Styling of Accordions" }),
/* @__PURE__ */ cs.jsxs(H3, { className: "d-flex align-items-center py-2", children: [
/* @__PURE__ */ cs.jsx(Pw, { isInline: !0, children: "Font size" }),
/* @__PURE__ */ cs.jsx(Mw, { size: "sm", controlClassName: "px-2 py-0", className: "flex-grow-0 p-0", value: o.fontSize, onChange: (u) => i({ fontSize: u.target.value }) })
] }),
Expand Down Expand Up @@ -72015,13 +72015,14 @@ function XEe({ panels: o, setPanels: r }) {
};
return /* @__PURE__ */ cs.jsxs(cs.Fragment, { children: [
/* @__PURE__ */ cs.jsx("div", { className: "d-flex justify-content-end", children: /* @__PURE__ */ cs.jsx(Nk, { iconBefore: mwe, onClick: h, children: "Add Accordion" }) }),
/* @__PURE__ */ cs.jsxs("div", { className: "d-flex flex-row", children: [
/* @__PURE__ */ cs.jsxs("div", { className: "d-flex flex-row mx-2", children: [
/* @__PURE__ */ cs.jsx("div", { className: "d-flex flex-column mr-2", style: { flexGrow: 1, width: "25%" }, children: o.map((k, _) => /* @__PURE__ */ cs.jsx(
Nk,
{
className: "justify-content-start",
className: "justify-content-start font-weight-bold p-2 rounded-0",
variant: i === _ ? "light" : "outline",
onClick: () => u(_),
size: "lg",
children: k.title || "Untitled accordion item"
},
`${k.title}-${_}`
Expand Down Expand Up @@ -72123,7 +72124,10 @@ function QEe({
] }) })
] }) });
}
const tTe = (o, r, { panels: i, styling: u }) => {
const tTe = (o, r, {
panels: i,
styling: u
}) => {
const h = o.handlerUrl(r, "studio_save");
Vre.render(
/* @__PURE__ */ cs.jsx(et.StrictMode, { children: /* @__PURE__ */ cs.jsx(
Expand Down
2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ coverage:
patch:
default:
enabled: yes
target: 100%
target: 90%

comment: false
Loading

0 comments on commit 2c641cf

Please sign in to comment.