Skip to content

Commit

Permalink
Merge pull request #58 from Zeit-Labs/shadinaif/FC-0012-OEP-58
Browse files Browse the repository at this point in the history
feat: standardize make extract_translations
  • Loading branch information
brian-smith-tcril authored May 30, 2023
2 parents 8c76be4 + 2dd8e9b commit 400fc44
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 19 deletions.
25 changes: 17 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <target>' where <target> 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}'
Expand Down Expand Up @@ -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.
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions google_drive/conf/locale/en/LC_MESSAGES/text.po
15 changes: 10 additions & 5 deletions google_drive/google_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand Down
9 changes: 5 additions & 4 deletions google_drive/google_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand Down
1 change: 1 addition & 0 deletions google_drive/translations
Binary file removed google_drive/translations/en/LC_MESSAGES/text.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion locale
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]),
)

0 comments on commit 400fc44

Please sign in to comment.