Skip to content
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ cover/

# Translations
*.mo
*.po
**/conf/locale/**/LC_MESSAGES/*
*.pot

# Django stuff:
Expand Down
74 changes: 11 additions & 63 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
.PHONY: help requirements upgrade lint format test docs clean
.PHONY: extract_translations compile_translations
.PHONY: detect_changed_source_translations dummy_translations build_dummy_translations
.PHONY: validate_translations pull_translations push_translations install_transifex_client
.PHONY: help requirements upgrade lint format test test-with-coverage docs clean
.PHONY: extract_translations


REPO_ROOT := $(shell pwd)
SRC_DIRECTORY := src
EXTRACT_DIR := conf/locale/en/LC_MESSAGES
COMBINED_LOCALE_DIR := conf/locale/en/LC_MESSAGES
# XBlock directories
XBLOCKS=$(shell find $(shell pwd)/$(SRC_DIRECTORY) -mindepth 2 -maxdepth 2 -type d -name 'conf' -exec dirname {} \;)
XBLOCKS=$(shell find $(REPO_ROOT)/$(SRC_DIRECTORY) -mindepth 2 -maxdepth 2 -type d -name 'conf' -exec dirname {} \;)


help: ## Show this help message
Expand Down Expand Up @@ -49,71 +48,20 @@ clean: ## Clean build artifacts

## Localization targets

extract_translations: ## extract strings to be translated, outputting .po files for each XBlock
extract_translations: ## extract strings to be translated, outputting .po files under <module_name>/conf/locale/
@for xblock in $(XBLOCKS); do \
echo "Extracting translations for $$xblock..."; \
module_name=$$(basename $$xblock); \
echo "Extracting translations for $$module_name..."; \
cd $$xblock && i18n_tool extract --no-segment; \
if [ -f $$xblock/$(EXTRACT_DIR)/djangojs.po ]; then \
cd $$xblock/$(EXTRACT_DIR) && msgcat django.po djangojs.po -o django.po && rm -f djangojs.po; \
msgcat $$xblock/$(EXTRACT_DIR)/django.po $$xblock/$(EXTRACT_DIR)/djangojs.po \
-o $$xblock/$(EXTRACT_DIR)/django.po && rm -f $$xblock/$(EXTRACT_DIR)/djangojs.po; \
fi; \
mkdir -p $(REPO_ROOT)/$$module_name/$(EXTRACT_DIR); \
if [ -f $$xblock/$(EXTRACT_DIR)/django.po ]; then \
mv $$xblock/$(EXTRACT_DIR)/django.po $$xblock/$(EXTRACT_DIR)/text.po; \
mv $$xblock/$(EXTRACT_DIR)/django.po $(REPO_ROOT)/$$module_name/$(EXTRACT_DIR)/django.po; \
fi; \
done
@# Merge all per-xblock text.po files into a single combined file for the
@# openedx-translations pipeline (OEP-58), which expects one conf/locale/en per repo.
@mkdir -p $(COMBINED_LOCALE_DIR)
@PO_FILES=""; \
for xblock in $(XBLOCKS); do \
if [ -f $$xblock/$(EXTRACT_DIR)/text.po ]; then \
PO_FILES="$$PO_FILES $$xblock/$(EXTRACT_DIR)/text.po"; \
fi; \
done; \
if [ -n "$$PO_FILES" ]; then \
msgcat --use-first $$PO_FILES -o $(COMBINED_LOCALE_DIR)/django.po; \
echo "Combined translation source file written to $(COMBINED_LOCALE_DIR)/django.po"; \
fi

compile_translations: ## compile translation files, outputting .mo files for each supported language for each XBlock
@for xblock in $(XBLOCKS); do \
echo "Compiling translations for $$xblock..."; \
cd $$xblock && django-admin compilemessages --locale en; \
done

detect_changed_source_translations:
@for xblock in $(XBLOCKS); do \
echo "Detecting changed translations for $$xblock..."; \
cd $$xblock && i18n_tool changed; \
done

dummy_translations: ## generate dummy translation (.po) files for each XBlock
@for xblock in $(XBLOCKS); do \
echo "Generating dummy translations for $$xblock..."; \
cd $$xblock && i18n_tool dummy; \
done

build_dummy_translations: extract_translations dummy_translations compile_translations ## generate and compile dummy translation files

validate_translations: build_dummy_translations detect_changed_source_translations ## validate translations

pull_translations: ## pull translations from Transifex for each XBlock
@for xblock in $(XBLOCKS); do \
echo "Pulling translations for $$xblock..."; \
cd $$xblock && i18n_tool transifex pull; \
done

push_translations: extract_translations ## push translations to Transifex for each XBlock
@for xblock in $(XBLOCKS); do \
echo "Pushing translations for $$xblock..."; \
cd $$xblock && i18n_tool transifex push; \
done

install_transifex_client: ## Install the Transifex client
# Instaling client will skip CHANGELOG and LICENSE files from git changes
# so remind the user to commit the change first before installing client.
git diff -s --exit-code HEAD || { echo "Please commit changes first."; exit 1; }
curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash
git checkout -- LICENSE README.md ## overwritten by Transifex installer

selfcheck: ## check that the Makefile is well-formed
@echo "The Makefile is well-formed."