forked from arbisoft/xblock-scorm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MCKIN-23600 Automating scorm xblock extraction process in PO file (#49)
* MCKIN-23600 Automating scorm xblock extraction process in PO file * Update config.yaml
- Loading branch information
1 parent
caaeb46
commit a3df336
Showing
10 changed files
with
479 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
.DEFAULT_GOAL := help | ||
|
||
WORKING_DIR := scormxblock | ||
JS_TARGET := $(WORKING_DIR)/public/js/translations | ||
EXTRACT_DIR := $(WORKING_DIR)/translations/en/LC_MESSAGES | ||
EXTRACTED_DJANGO := $(EXTRACT_DIR)/django-partial.po | ||
EXTRACTED_TEXT := $(EXTRACT_DIR)/text.po | ||
EXTRACTED_DJANGOJS := $(EXTRACT_DIR)/djangojs-partial.po | ||
EXTRACTED_TEXTJS := $(EXTRACT_DIR)/textjs.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}' | ||
|
||
extract_translations: ## extract strings to be translated, outputting .po files | ||
cd $(WORKING_DIR) && i18n_tool extract | ||
mv $(EXTRACTED_DJANGO) $(EXTRACTED_TEXT) | ||
if [ -f "$(EXTRACTED_DJANGOJS)" ]; then mv $(EXTRACTED_DJANGOJS) $(EXTRACTED_TEXTJS); fi | ||
rm -f $(EXTRACTED_DJANGO) | ||
rm -f $(EXTRACTED_DJANGOJS) | ||
find $(EXTRACT_DIR) -type f -name "*.po" -exec sed -i'' -e 's/nplurals=INTEGER/nplurals=2/' {} \; | ||
find $(EXTRACT_DIR) -type f -name "*.po" -exec sed -i'' -e 's/plural=EXPRESSION/plural=\(n != 1\)/' {} \; | ||
|
||
compile_translations: ## compile translation files, outputting .mo files for each supported language | ||
cd $(WORKING_DIR) && i18n_tool generate | ||
python manage.py compilejsi18n --output $(JS_TARGET) | ||
|
||
detect_changed_source_translations: | ||
cd $(WORKING_DIR) && i18n_tool changed | ||
|
||
dummy_translations: ## generate dummy translation (.po) files | ||
cd $(WORKING_DIR) && i18n_tool dummy | ||
|
||
build_dummy_translations: dummy_translations compile_translations ## generate and compile dummy translation files | ||
|
||
validate_translations: build_dummy_translations detect_changed_source_translations ## validate translations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
|
||
if __name__ == "__main__": | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "scormxblock.settings") | ||
|
||
from django.core.management import execute_from_command_line | ||
|
||
execute_from_command_line(sys.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../translations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
|
||
(function(global){ | ||
var ScormxBlockXBlockI18N = { | ||
init: function() { | ||
|
||
|
||
(function (globals) { | ||
|
||
var django = globals.django || (globals.django = {}); | ||
|
||
|
||
django.pluralidx = function (count) { return (count == 1) ? 0 : 1; }; | ||
|
||
|
||
|
||
/* gettext identity library */ | ||
|
||
django.gettext = function (msgid) { return msgid; }; | ||
django.ngettext = function (singular, plural, count) { return (count == 1) ? singular : plural; }; | ||
django.gettext_noop = function (msgid) { return msgid; }; | ||
django.pgettext = function (context, msgid) { return msgid; }; | ||
django.npgettext = function (context, singular, plural, count) { return (count == 1) ? singular : plural; }; | ||
|
||
|
||
django.interpolate = function (fmt, obj, named) { | ||
if (named) { | ||
return fmt.replace(/%\(\w+\)s/g, function(match){return String(obj[match.slice(2,-2)])}); | ||
} else { | ||
return fmt.replace(/%s/g, function(match){return String(obj.shift())}); | ||
} | ||
}; | ||
|
||
|
||
/* formatting library */ | ||
|
||
django.formats = { | ||
"DATETIME_FORMAT": "N j, Y, P", | ||
"DATETIME_INPUT_FORMATS": [ | ||
"%Y-%m-%d %H:%M:%S", | ||
"%Y-%m-%d %H:%M:%S.%f", | ||
"%Y-%m-%d %H:%M", | ||
"%Y-%m-%d", | ||
"%m/%d/%Y %H:%M:%S", | ||
"%m/%d/%Y %H:%M:%S.%f", | ||
"%m/%d/%Y %H:%M", | ||
"%m/%d/%Y", | ||
"%m/%d/%y %H:%M:%S", | ||
"%m/%d/%y %H:%M:%S.%f", | ||
"%m/%d/%y %H:%M", | ||
"%m/%d/%y" | ||
], | ||
"DATE_FORMAT": "N j, Y", | ||
"DATE_INPUT_FORMATS": [ | ||
"%Y-%m-%d", | ||
"%m/%d/%Y", | ||
"%m/%d/%y" | ||
], | ||
"DECIMAL_SEPARATOR": ".", | ||
"FIRST_DAY_OF_WEEK": "0", | ||
"MONTH_DAY_FORMAT": "F j", | ||
"NUMBER_GROUPING": "3", | ||
"SHORT_DATETIME_FORMAT": "m/d/Y P", | ||
"SHORT_DATE_FORMAT": "m/d/Y", | ||
"THOUSAND_SEPARATOR": ",", | ||
"TIME_FORMAT": "P", | ||
"TIME_INPUT_FORMATS": [ | ||
"%H:%M:%S", | ||
"%H:%M:%S.%f", | ||
"%H:%M" | ||
], | ||
"YEAR_MONTH_FORMAT": "F Y" | ||
}; | ||
|
||
django.get_format = function (format_type) { | ||
var value = django.formats[format_type]; | ||
if (typeof(value) == 'undefined') { | ||
return format_type; | ||
} else { | ||
return value; | ||
} | ||
}; | ||
|
||
/* add to global namespace */ | ||
globals.pluralidx = django.pluralidx; | ||
globals.gettext = django.gettext; | ||
globals.ngettext = django.ngettext; | ||
globals.gettext_noop = django.gettext_noop; | ||
globals.pgettext = django.pgettext; | ||
globals.npgettext = django.npgettext; | ||
globals.interpolate = django.interpolate; | ||
globals.get_format = django.get_format; | ||
|
||
}(this)); | ||
|
||
|
||
} | ||
}; | ||
ScormxBlockXBlockI18N.init(); | ||
global.ScormxBlockXBlockI18N = ScormxBlockXBlockI18N; | ||
}(this)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
""" | ||
Django settings for the scormxblock project. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/1.11/topics/settings/ | ||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/1.11/ref/settings/ | ||
""" | ||
|
||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) | ||
import os | ||
import yaml | ||
|
||
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) | ||
|
||
|
||
# Quick-start development settings - unsuitable for production | ||
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
# This is just a container for running tests, it's okay to allow it to be | ||
# defaulted here if not present in environment settings | ||
SECRET_KEY = os.environ.get('SECRET_KEY', 'xydut433=!s!i(n9u&1oiyv!hu1k=(h-)nuu30d(gd(ew%7+1w') | ||
|
||
# SECURITY WARNING: don't run with debug turned on in production! | ||
# This is just a container for running tests | ||
DEBUG = True | ||
|
||
TEMPLATE_DEBUG = True | ||
|
||
ALLOWED_HOSTS = [] | ||
|
||
|
||
# Application definition | ||
|
||
INSTALLED_APPS = ( | ||
'statici18n', | ||
'scormxblock', | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
) | ||
|
||
# Internationalization | ||
# https://docs.djangoproject.com/en/1.6/topics/i18n/ | ||
|
||
LANGUAGE_CODE = 'en-us' | ||
|
||
TIME_ZONE = 'UTC' | ||
|
||
USE_I18N = True | ||
|
||
USE_L10N = True | ||
|
||
USE_TZ = True | ||
|
||
|
||
# Static files (CSS, JavaScript, Images) | ||
# https://docs.djangoproject.com/en/1.6/howto/static-files/ | ||
|
||
STATIC_URL = '/static/' | ||
|
||
LOCALE_PATHS = [ | ||
os.path.join(BASE_DIR, 'scormxblock/translations'), | ||
] | ||
|
||
# statici18n | ||
# http://django-statici18n.readthedocs.io/en/latest/settings.html | ||
|
||
with open(os.path.join(BASE_DIR, 'scormxblock/translations/config.yaml'), 'r') as locale_config_file: | ||
LOCALE_CONFIG = yaml.load(locale_config_file) | ||
|
||
LANGUAGES = [ | ||
(code, code,) | ||
for code in LOCALE_CONFIG['locales'] + LOCALE_CONFIG['dummy_locales'] | ||
] | ||
|
||
STATICI18N_DOMAIN = 'textjs' | ||
|
||
STATICI18N_NAMESPACE = 'ScormxBlockXBlockI18N' | ||
STATICI18N_PACKAGES = ( | ||
'scormxblock', | ||
) | ||
STATICI18N_ROOT = 'scormxblock/public/js' | ||
STATICI18N_OUTPUT_DIR = 'translations' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Configuration for i18n workflow. | ||
|
||
locales: | ||
- en # English - Source Language | ||
- ar # Arabic | ||
- es_419 # Spanish (Latin America) | ||
- ja_JP # Japanese | ||
- ko_KR # Korean | ||
- fr # French | ||
- pt_BR # Portuguese (Brazil) | ||
- zh_CN # Chinese (China) | ||
- de_DE # German | ||
- pl # Polish | ||
|
||
# The locales used for fake-accented English, for testing. | ||
dummy_locales: | ||
- eo | ||
|
||
# Directories we don't search for strings. | ||
ignore_dirs: | ||
- tests | ||
- translations | ||
|
||
# i18n_tools produces just "django-partial.po" by default, but we need "text.po": | ||
generate_merge: | ||
text.po: | ||
- django-partial.po | ||
textjs.po: | ||
- djangojs-partial.po |
Oops, something went wrong.