File: //home/arjun/projects/buyercall_forms/buyercall/buyercall/lib/i18n.py
from os import path
from flask_webpack import Webpack
from flask_babel import get_locale
import time
class I18nWebpack(Webpack):
def __init__(self, *args, **kwargs):
super(I18nWebpack, self).__init__(*args, **kwargs)
def _add_prefix(self, f, ext):
head, tail = path.split(f)
languages = [get_locale().language, 'en']
for lang in languages:
candidate = path.join(head, '{}.{}'.format(lang, tail))
if '{}.{}'.format(candidate, ext) in self.assets:
return candidate
return f
def javascript_tag(self, *args):
return super(I18nWebpack, self).javascript_tag(
*[self._add_prefix(f, 'js') for f in args]
)
def stylesheet_tag(self, *args):
return super(I18nWebpack, self).stylesheet_tag(
*[self._add_prefix(f, 'css') for f in args]
)
def asset_url_for(self, *arg):
param = '?timestamp={}'.format(time.time()) # will result in something like ?timestamp=1355563265.81
return "{}{}".format(super(I18nWebpack, self).asset_url_for(*arg), param)