From 5f46301ec8737bf965fbca8084943bcb0d9ebff2 Mon Sep 17 00:00:00 2001 From: Shadi Naif Date: Sun, 14 May 2023 12:52:17 +0300 Subject: [PATCH 1/2] feat: standardize make extract_translations Refs: FC-0012 OEP-58 --- Makefile | 25 ++++++++++++------ .../{translations => conf/locale}/config.yaml | 0 .../locale/en/LC_MESSAGES/django.po} | 0 .../conf/locale/en/LC_MESSAGES/text.po | 1 + .../locale}/eo/LC_MESSAGES/text.mo | Bin .../locale}/eo/LC_MESSAGES/text.po | 0 .../locale}/es_419/LC_MESSAGES/text.mo | Bin .../locale}/es_419/LC_MESSAGES/text.po | 0 .../locale}/fr_CA/LC_MESSAGES/text.mo | Bin .../locale}/fr_CA/LC_MESSAGES/text.po | 0 .../locale}/ja_JP/LC_MESSAGES/text.mo | Bin .../locale}/ja_JP/LC_MESSAGES/text.po | 0 google_drive/translations | 1 + .../translations/en/LC_MESSAGES/text.mo | Bin 341 -> 0 bytes locale | 2 +- setup.py | 2 +- 16 files changed, 21 insertions(+), 10 deletions(-) rename google_drive/{translations => conf/locale}/config.yaml (100%) rename google_drive/{translations/en/LC_MESSAGES/text.po => conf/locale/en/LC_MESSAGES/django.po} (100%) create mode 120000 google_drive/conf/locale/en/LC_MESSAGES/text.po rename google_drive/{translations => conf/locale}/eo/LC_MESSAGES/text.mo (100%) rename google_drive/{translations => conf/locale}/eo/LC_MESSAGES/text.po (100%) rename google_drive/{translations => conf/locale}/es_419/LC_MESSAGES/text.mo (100%) rename google_drive/{translations => conf/locale}/es_419/LC_MESSAGES/text.po (100%) rename google_drive/{translations => conf/locale}/fr_CA/LC_MESSAGES/text.mo (100%) rename google_drive/{translations => conf/locale}/fr_CA/LC_MESSAGES/text.po (100%) rename google_drive/{translations => conf/locale}/ja_JP/LC_MESSAGES/text.mo (100%) rename google_drive/{translations => conf/locale}/ja_JP/LC_MESSAGES/text.po (100%) create mode 120000 google_drive/translations delete mode 100644 google_drive/translations/en/LC_MESSAGES/text.mo diff --git a/Makefile b/Makefile index 5e3afc4..0f229d2 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,13 @@ endef export BROWSER_PYSCRIPT BROWSER := python -c "$$BROWSER_PYSCRIPT" +WORKING_DIR := google_drive +JS_TARGET := $(WORKING_DIR)/public/js/translations +EXTRACT_DIR := $(WORKING_DIR)/conf/locale/en/LC_MESSAGES +EXTRACTED_DJANGO_PARTIAL := $(EXTRACT_DIR)/django-partial.po +EXTRACTED_DJANGOJS_PARTIAL := $(EXTRACT_DIR)/djangojs-partial.po +EXTRACTED_DJANGO := $(EXTRACT_DIR)/django.po + help: ## display this help message @echo "Please use \`make ' where is one of" @perl -nle'print $& if m{^[a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m %-25s\033[0m %s\n", $$1, $$2}' @@ -78,16 +85,18 @@ validate: quality test validate_translations ## run tests and quality checks ## Localization targets extract_translations: ## extract strings to be translated, outputting .po files - rm -rf docs/_build - - # Extract Python and Django template strings - mkdir -p locale/en/LC_MESSAGES/ - rm -f locale/en/LC_MESSAGES/{django,text}.po - django-admin makemessages -l en -v1 -d django - mv locale/en/LC_MESSAGES/django.po locale/en/LC_MESSAGES/text.po + cd $(WORKING_DIR) && i18n_tool extract + mv $(EXTRACTED_DJANGO_PARTIAL) $(EXTRACTED_DJANGO) + # Safely concatenate djangojs if it exists + ( test -f $(EXTRACTED_DJANGOJS_PARTIAL) && \ + msgcat $(EXTRACTED_DJANGO) $(EXTRACTED_DJANGOJS_PARTIAL) -o $(EXTRACTED_DJANGO) \ + ) || ! test -f $(EXTRACTED_DJANGOJS_PARTIAL) + rm -rf $(EXTRACTED_DJANGOJS_PARTIAL) + sed -i'' -e 's/nplurals=INTEGER/nplurals=2/' $(EXTRACTED_DJANGO) + sed -i'' -e 's/plural=EXPRESSION/plural=\(n != 1\)/' $(EXTRACTED_DJANGO) compile_translations: ## compile translation files, outputting .mo files for each supported language - i18n_tool generate + cd $(WORKING_DIR) && i18n_tool generate make clean detect_changed_source_translations: ## Determines if the source translation files are up-to-date, otherwise exit with a non-zero code. diff --git a/google_drive/translations/config.yaml b/google_drive/conf/locale/config.yaml similarity index 100% rename from google_drive/translations/config.yaml rename to google_drive/conf/locale/config.yaml diff --git a/google_drive/translations/en/LC_MESSAGES/text.po b/google_drive/conf/locale/en/LC_MESSAGES/django.po similarity index 100% rename from google_drive/translations/en/LC_MESSAGES/text.po rename to google_drive/conf/locale/en/LC_MESSAGES/django.po diff --git a/google_drive/conf/locale/en/LC_MESSAGES/text.po b/google_drive/conf/locale/en/LC_MESSAGES/text.po new file mode 120000 index 0000000..0082074 --- /dev/null +++ b/google_drive/conf/locale/en/LC_MESSAGES/text.po @@ -0,0 +1 @@ +django.po \ No newline at end of file diff --git a/google_drive/translations/eo/LC_MESSAGES/text.mo b/google_drive/conf/locale/eo/LC_MESSAGES/text.mo similarity index 100% rename from google_drive/translations/eo/LC_MESSAGES/text.mo rename to google_drive/conf/locale/eo/LC_MESSAGES/text.mo diff --git a/google_drive/translations/eo/LC_MESSAGES/text.po b/google_drive/conf/locale/eo/LC_MESSAGES/text.po similarity index 100% rename from google_drive/translations/eo/LC_MESSAGES/text.po rename to google_drive/conf/locale/eo/LC_MESSAGES/text.po diff --git a/google_drive/translations/es_419/LC_MESSAGES/text.mo b/google_drive/conf/locale/es_419/LC_MESSAGES/text.mo similarity index 100% rename from google_drive/translations/es_419/LC_MESSAGES/text.mo rename to google_drive/conf/locale/es_419/LC_MESSAGES/text.mo diff --git a/google_drive/translations/es_419/LC_MESSAGES/text.po b/google_drive/conf/locale/es_419/LC_MESSAGES/text.po similarity index 100% rename from google_drive/translations/es_419/LC_MESSAGES/text.po rename to google_drive/conf/locale/es_419/LC_MESSAGES/text.po diff --git a/google_drive/translations/fr_CA/LC_MESSAGES/text.mo b/google_drive/conf/locale/fr_CA/LC_MESSAGES/text.mo similarity index 100% rename from google_drive/translations/fr_CA/LC_MESSAGES/text.mo rename to google_drive/conf/locale/fr_CA/LC_MESSAGES/text.mo diff --git a/google_drive/translations/fr_CA/LC_MESSAGES/text.po b/google_drive/conf/locale/fr_CA/LC_MESSAGES/text.po similarity index 100% rename from google_drive/translations/fr_CA/LC_MESSAGES/text.po rename to google_drive/conf/locale/fr_CA/LC_MESSAGES/text.po diff --git a/google_drive/translations/ja_JP/LC_MESSAGES/text.mo b/google_drive/conf/locale/ja_JP/LC_MESSAGES/text.mo similarity index 100% rename from google_drive/translations/ja_JP/LC_MESSAGES/text.mo rename to google_drive/conf/locale/ja_JP/LC_MESSAGES/text.mo diff --git a/google_drive/translations/ja_JP/LC_MESSAGES/text.po b/google_drive/conf/locale/ja_JP/LC_MESSAGES/text.po similarity index 100% rename from google_drive/translations/ja_JP/LC_MESSAGES/text.po rename to google_drive/conf/locale/ja_JP/LC_MESSAGES/text.po diff --git a/google_drive/translations b/google_drive/translations new file mode 120000 index 0000000..618b7e2 --- /dev/null +++ b/google_drive/translations @@ -0,0 +1 @@ +conf/locale \ No newline at end of file diff --git a/google_drive/translations/en/LC_MESSAGES/text.mo b/google_drive/translations/en/LC_MESSAGES/text.mo deleted file mode 100644 index 51ac00c7d5bf5867355131efe3ff1fc295567672..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 341 zcmYL@u};G<5Qd9j%E-dP;DHUUz*bB_HI3Uw*h!S6m0&Zi2}Z@P92ddERehws0+)sS z(x)5lKizlO?@mt+`&|!ngq$N6$T4z-v>700xV*#JcK(xl_ocWo%8! J;LU`n_XjYzUm5@a diff --git a/locale b/locale index 4068dc0..92175d3 120000 --- a/locale +++ b/locale @@ -1 +1 @@ -google_drive/translations \ No newline at end of file +google_drive/conf/locale \ No newline at end of file diff --git a/setup.py b/setup.py index 0460eab..b7e71bd 100644 --- a/setup.py +++ b/setup.py @@ -44,5 +44,5 @@ def package_data(pkg, roots): 'google-calendar = google_drive:GoogleCalendarBlock' ] }, - package_data=package_data("google_drive", ["static", "templates", "public", "translations"]), + package_data=package_data("google_drive", ["static", "templates", "public", "translations", "conf"]), ) From 2dd8e9b7a30c5c5488c45e29a70f1a846c1e83b4 Mon Sep 17 00:00:00 2001 From: Shadi Naif Date: Sun, 14 May 2023 15:09:39 +0300 Subject: [PATCH 2/2] feat: render all in django templates to ensure translation Refs: FC-0012 OEP-58 --- google_drive/google_calendar.py | 15 ++++++++++----- google_drive/google_docs.py | 9 +++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/google_drive/google_calendar.py b/google_drive/google_calendar.py index 38610e4..a4962c5 100644 --- a/google_drive/google_calendar.py +++ b/google_drive/google_calendar.py @@ -92,11 +92,16 @@ def studio_view(self, context): # pylint: disable=unused-argument fragment = Fragment() # Need to access protected members of fields to get their default value default_name = self.fields['display_name']._default # pylint: disable=protected-access,unsubscriptable-object - fragment.add_content(RESOURCE_LOADER.render_template(CALENDAR_EDIT_TEMPLATE, { - 'self': self, - 'defaultName': default_name, - 'defaultID': self.fields['calendar_id']._default # pylint: disable=protected-access,unsubscriptable-object - })) + default_id = self.fields['calendar_id']._default # pylint: disable=protected-access,unsubscriptable-object + fragment.add_content(RESOURCE_LOADER.render_django_template( + CALENDAR_EDIT_TEMPLATE, + context={ + 'self': self, + 'defaultName': default_name, + 'defaultID': default_id + }, + i18n_service=self.runtime.service(self, "i18n"), + )) fragment.add_javascript(RESOURCE_LOADER.load_unicode('public/js/google_calendar_edit.js')) fragment.add_css(RESOURCE_LOADER.load_unicode('public/css/google_edit.css')) diff --git a/google_drive/google_docs.py b/google_drive/google_docs.py index 2825a90..011eeff 100644 --- a/google_drive/google_docs.py +++ b/google_drive/google_docs.py @@ -101,10 +101,11 @@ def studio_view(self, context): # pylint: disable=unused-argument fragment = Fragment() # Need to access protected members of fields to get their default value default_name = self.fields['display_name']._default # pylint: disable=protected-access,unsubscriptable-object - fragment.add_content(RESOURCE_LOADER.render_template(DOCUMENT_EDIT_TEMPLATE, { - 'self': self, - 'defaultName': default_name, - })) + fragment.add_content(RESOURCE_LOADER.render_django_template( + DOCUMENT_EDIT_TEMPLATE, + context={'self': self, 'defaultName': default_name}, + i18n_service=self.runtime.service(self, 'i18n'), + )) fragment.add_javascript(RESOURCE_LOADER.load_unicode('public/js/google_docs_edit.js')) fragment.add_css(RESOURCE_LOADER.load_unicode('public/css/google_edit.css'))