Skip to content

Commit

Permalink
first stab at moving js_strings into a .js file
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed May 10, 2012
1 parent 25a47e1 commit 159d62c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions ckan/config/routing.py
Expand Up @@ -297,6 +297,7 @@ def make_map():
m.connect('storage_file', '/storage/f/{label:.*}',
action='file')

map.connect('/i18n/strings_{lang}.js', controller='i18n', action='strings')

for plugin in routing_plugins:
map = plugin.after_map(map)
Expand Down
12 changes: 12 additions & 0 deletions ckan/controllers/i18n.py
@@ -0,0 +1,12 @@
import re
import ckan.lib.base as base
import ckan.lib.i18n as i18n

class I18NController(base.BaseController):

def strings(self, lang):
i18n.set_lang(lang)
html = base.render('js_strings.html', cache_force=True)
html = re.sub('<[^\>]*>', '', html)
base.response.headers['Content-type'] = "text/javascript; charset=utf-8"
return html
5 changes: 5 additions & 0 deletions ckan/lib/i18n.py
Expand Up @@ -104,3 +104,8 @@ def get_lang():
return langs[0]
else:
return 'en'

def set_lang(language_code):
''' Wrapper to pylons call '''
if language_code != 'en':
i18n.set_lang(language_code)

0 comments on commit 159d62c

Please sign in to comment.