Skip to content

Commit

Permalink
Hack for l10n/gettext use in angularJs templates.
Browse files Browse the repository at this point in the history
The purpose of the hack is to make translated strings in angularJs
templates discoverable by ./manage.py makemessages
  • Loading branch information
slaweet committed Aug 31, 2014
1 parent 7f88e22 commit e7483c5
Show file tree
Hide file tree
Showing 7 changed files with 357 additions and 182 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ Geography.egg-info
node_modules
main/templates/generated
main/geography/static/css
main/geography/static/hack/tpl
22 changes: 21 additions & 1 deletion main/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ module.exports = function(grunt) {
src: ['geography/static/tpl/homepage.html'],
dest: 'templates/generated/homepage.html',
},
'tpl-gettext-hack': {
options: {
replacements: [
{
pattern: /\{\{\s*(("[^"]+")|('[^']+'))\s*\|\s*trans\s*\}\}/g,
replacement: '\ngettext($1);\n '
}, {
pattern: /( |<).*\n/g,
replacement: ''
}
]
},
files: [{
expand: true,
cwd: 'geography/static',
src: 'tpl/*',
dest: 'geography/static/hack/',
ext: '.js'
}]
},
hashes: {
options: {
replacements: [
Expand Down Expand Up @@ -237,7 +257,7 @@ module.exports = function(grunt) {
grunt.registerTask('runserver', ['shell:runserver','watch']);
grunt.registerTask('hashes', ['shell:hashes', 'string-replace:hashes']);
grunt.registerTask('bboxcacheall', ['bboxcache', 'string-replace:bboxcache']);
grunt.registerTask('templates', ['string-replace:homepage', 'ngtemplates']);
grunt.registerTask('templates', ['string-replace:homepage', 'ngtemplates', 'string-replace:tpl-gettext-hack']);
grunt.registerTask('minifyjs', ['hashes', 'templates', 'uglify']);
grunt.registerTask('default', ['styles', 'jshint', 'bboxcache', 'minifyjs']);
grunt.registerTask('deploy', ['styles', 'string-replace:bboxcache', 'minifyjs']);
Expand Down
Loading

0 comments on commit e7483c5

Please sign in to comment.