def _write_generated_js(self): global_js = generate_global_file() user_js = generate_user_file() i18n_js = "window.TRANSLATIONS = {};".format(generate_i18n_file(session.lang)) react_i18n_js = "window.REACT_TRANSLATIONS = {};".format(generate_i18n_file(session.lang, react=True)) gen_path = os.path.join(self._content_dir, 'assets') self._zip_file.writestr(os.path.join(gen_path, 'js-vars', 'global.js'), global_js) self._zip_file.writestr(os.path.join(gen_path, 'js-vars', 'user.js'), user_js) self._zip_file.writestr(os.path.join(gen_path, 'i18n', session.lang + '.js'), i18n_js) self._zip_file.writestr(os.path.join(gen_path, 'i18n', session.lang + '-react.js'), react_i18n_js)
def _get_i18n_locale(locale_name, react=False): """Retrieve a locale in a Jed-compatible format.""" # Ensure we have a valid locale. en_GB is our source locale and thus always considered # valid, even if it doesn't exist (dev setup where the user did not compile any locales) # since otherwise we'd have no valid locales at all and get a redirect loop all_locales = get_all_locales() if locale_name not in all_locales and locale_name != 'en_GB': fallback = config.DEFAULT_LOCALE if config.DEFAULT_LOCALE in all_locales else 'en_GB' return redirect(url_for(request.endpoint, locale_name=fallback)) react_suffix = '-react' if react else '' try: cache_file = os.path.join(config.CACHE_DIR, 'assets_i18n_{}{}_{}_{}.js'.format( locale_name, react_suffix, indico.__version__, config.hash)) except UnicodeEncodeError: raise NotFound if config.DEBUG or not os.path.exists(cache_file): i18n_data = generate_i18n_file(locale_name, react=react) if i18n_data is None: raise NotFound with open(cache_file, 'w') as f: f.write("window.{} = {};".format('REACT_TRANSLATIONS' if react else 'TRANSLATIONS', i18n_data)) return send_file(f'{locale_name}{react_suffix}.js', cache_file, mimetype='application/javascript', conditional=True)
def _get_i18n_locale(locale_name, react=False): """Retrieve a locale in a Jed-compatible format.""" react_suffix = '-react' if react else '' try: cache_file = os.path.join( config.CACHE_DIR, 'assets_i18n_{}{}_{}_{}.js'.format(locale_name, react_suffix, indico.__version__, config.hash)) except UnicodeEncodeError: raise NotFound if config.DEBUG or not os.path.exists(cache_file): i18n_data = generate_i18n_file(locale_name, react=react) if i18n_data is None: raise NotFound with open(cache_file, 'w') as f: f.write("window.{} = {};".format( 'REACT_TRANSLATIONS' if react else 'TRANSLATIONS', i18n_data)) return send_file(f'{locale_name}{react_suffix}.js', cache_file, mimetype='application/javascript', conditional=True)
def _write_generated_js(self): global_js = generate_global_file().encode('utf-8') user_js = generate_user_file().encode('utf-8') i18n_js = u"window.TRANSLATIONS = {};".format(generate_i18n_file(session.lang)).encode('utf-8') gen_path = os.path.join(self._content_dir, 'assets') self._zip_file.writestr(os.path.join(gen_path, 'js-vars', 'global.js'), global_js) self._zip_file.writestr(os.path.join(gen_path, 'js-vars', 'user.js'), user_js) self._zip_file.writestr(os.path.join(gen_path, 'i18n', session.lang + '.js'), i18n_js)
def _get_i18n_locale(locale_name, react=False): """Retrieve a locale in a Jed-compatible format""" react_suffix = '-react' if react else '' cache_file = os.path.join(config.CACHE_DIR, 'assets_i18n_{}{}_{}_{}.js'.format( locale_name, react_suffix, indico.__version__, config.hash)) if config.DEBUG or not os.path.exists(cache_file): i18n_data = generate_i18n_file(locale_name, react=react) with open(cache_file, 'wb') as f: f.write("window.{} = {};".format('REACT_TRANSLATIONS' if react else 'TRANSLATIONS', i18n_data)) return send_file('{}{}.js'.format(locale_name, react_suffix), cache_file, mimetype='application/javascript', no_cache=False, conditional=True)