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/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')) 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 51ac00c..0000000 Binary files a/google_drive/translations/en/LC_MESSAGES/text.mo and /dev/null differ 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"]), )