Skip to content
This repository was archived by the owner on May 6, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
All notable changes to this project will be documented in this file.
Add any new changes to the top (right below this line).

- 2022-04-06
- Role: simple_theme
- Added a new `SIMPLETHEME_I18N_DJANGO` setting to allow operators to provide
additional translations, or override existing django translations.

- 2022-03-25
- Role: edxapp
- Added a new `CUSTOM_RESOURCE_TEMPLATES_DIRECTORY` setting to allow operators to
Expand Down
34 changes: 34 additions & 0 deletions playbooks/roles/simple_theme/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,37 @@ SIMPLETHEME_STATIC_FILES_URLS: []
# border-top: 3px solid $main-color;
# }
SIMPLETHEME_EXTRA_SASS: ""


# Use this variable to configure django translations.
# Note that edx-platform does not pick up translations from themes by default.
# You will have to manually configure either `COMPREHENSIVE_THEME_LOCALE_PATHS` or
# `PREPEND_LOCALE_PATHS` to include the path to the theme's i18n/locale folder for
# these translations to get picked up.
#
# The SIMPLETHEME_I18n_DJANGO variable should contain a list of dictionaries with these keys:
# - `lang`: the language code
# - `domain`: the i18n domain (typically one of "django" or "djangojs")
# - `headers`: (optional) Additional PO file headers.
# - `messages`: Translation messages. It should be a raw string of PO formatted messages.
#
# Samle:
# SIMPLETHEME_I18N_DJANGO:
# - lang: en
# domain: django
# headers: |
# "Plural-Forms: nplurals=2; plural=(n > 1);\n"
# messages: |
# msgid "my id"
# msgstr "my translation"
#
# msgid "one"
# msgid_plural "many"
# msgstr[0] "just one"
# msgstr[1] "a lot"
# - lang: en
# domain: djangojs
# messages: |
# msgid "my id"
# msgstr "my JS translation"
SIMPLETHEME_I18N_DJANGO: []
42 changes: 42 additions & 0 deletions playbooks/roles/simple_theme/tasks/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,45 @@
owner: "{{ edxapp_user }}"
group: "{{ common_web_group }}"
with_items: "{{ SIMPLETHEME_STATIC_FILES_URLS }}"

# Handle translations.
- block:
- name: Install needed packages
apt:
name: gettext
state: present
update_cache: true
cache_valid_time: 3600
- name: Create directories for django translations
file:
path: "{{ simpletheme_folder }}/i18n/conf/locale/{{ item.lang }}/LC_MESSAGES"
state: directory
owner: "{{ edxapp_user }}"
group: "{{ common_web_group }}"
with_items: "{{ SIMPLETHEME_I18N_DJANGO }}"
- name: Make sure .po files exist
file:
path: "{{ simpletheme_folder }}/i18n/conf/locale/{{ item.lang }}/LC_MESSAGES/{{ item.domain }}.po"
state: touch
owner: "{{ edxapp_user }}"
group: "{{ common_web_group }}"
with_items: "{{ SIMPLETHEME_I18N_DJANGO }}"
- name: Create temporary .po files with custom translations
template:
src: "i18n/domain.po.j2"
dest: "{{ simpletheme_folder }}/i18n/conf/locale/{{ item.lang }}/LC_MESSAGES/{{ item.domain }}.po_"
owner: "{{ edxapp_user }}"
group: "{{ common_web_group }}"
with_items: "{{ SIMPLETHEME_I18N_DJANGO }}"
- name: Merge temporary .po files into default translations
shell: >
msgcat --use-first {{ simpletheme_folder }}/i18n/conf/locale/{{ item.lang }}/LC_MESSAGES/{{ item.domain }}.po_
{{ simpletheme_folder }}/i18n/conf/locale/{{ item.lang }}/LC_MESSAGES/{{ item.domain }}.po >
{{ simpletheme_folder }}/i18n/conf/locale/{{ item.lang }}/LC_MESSAGES/{{ item.domain }}.po
with_items: "{{ SIMPLETHEME_I18N_DJANGO }}"
- name: Compile .po files into .mo
shell: >
msgfmt {{ simpletheme_folder }}/i18n/conf/locale/{{ item.lang }}/LC_MESSAGES/{{ item.domain }}.po
-o {{ simpletheme_folder }}/i18n/conf/locale/{{ item.lang }}/LC_MESSAGES/{{ item.domain }}.mo
with_items: "{{ SIMPLETHEME_I18N_DJANGO }}"
when: SIMPLETHEME_I18N_DJANGO | length > 0
12 changes: 12 additions & 0 deletions playbooks/roles/simple_theme/templates/i18n/domain.po.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: {{ item.lang }}\n"
{% if 'headers' in item -%}
{{ item.headers }}
{%- endif %}

{% if 'messages' in item -%}
{{ item.messages }}
{%- endif %}