def djangular_catalog(request): locale = to_locale(get_language_from_request(request)) if request.GET and 'lang' in request.GET: if check_for_language(request.GET['lang']): locale = to_locale(request.GET['lang']) django_catalog, plural = get_javascript_catalog(locale, 'django', []) angular_catalog, plural = get_javascript_catalog(locale, 'djangular', []) django_catalog.update(angular_catalog) return JsonResponse(django_catalog)
def handle_noargs(self, **options): locale = options.get('locale') domain = options['domain'] packages = options['packages'] or settings.STATICI18N_PACKAGES outputdir = options['outputdir'] verbosity = int(options.get('verbosity')) if locale is not None: languages = [locale] else: languages = [to_locale(lang_code) for (lang_code, lang_name) in settings.LANGUAGES] if outputdir is None: outputdir = os.path.join(settings.STATICI18N_ROOT, settings.STATICI18N_OUTPUT_DIR) for locale in languages: if verbosity > 0: self.stdout.write("processing language %s\n" % locale) jsfile = os.path.join(outputdir, get_filename(locale, domain)) basedir = os.path.dirname(jsfile) if not os.path.isdir(basedir): os.makedirs(basedir) activate(locale) catalog, plural = get_javascript_catalog(locale, domain, packages) response = render_javascript_catalog(catalog, plural) with io.open(jsfile, "w", encoding="utf-8") as fp: fp.write(force_text(response.content))
def djangular_catalog(request): locale = to_locale(get_language_from_request(request)) if request.GET and 'lang' in request.GET: if check_for_language(request.GET['lang']): locale = to_locale(request.GET['lang']) catalog, plural = get_javascript_catalog(locale, 'djangular', ['django.conf']) return JsonResponse(catalog)
def _create_json_catalog(self, locale, domain, packages): activate(locale) catalog, plural = get_javascript_catalog(locale, domain, packages) data = { 'catalog': catalog, 'formats': get_formats(), 'plural': plural, } return force_text(json.dumps(data, ensure_ascii=False))
def _create_javascript_catalog(self, locale, domain, packages): activate(locale) if django.VERSION < (2, 0): catalog, plural = get_javascript_catalog(locale, domain, packages) response = render_javascript_catalog(catalog, plural) else: catalog = JavaScriptCatalog() packages = get_packages(packages) # we are passing None as the request, as the request object is currently not used by django response = catalog.get(self, None, domain=domain, packages=packages) return force_text(response.content)
def javascript_catalog(request, domain='djangojs', packages=None): locale = _get_locale(request) packages = _parse_packages(packages) catalog, plural = get_javascript_catalog(locale, domain, packages) data = { 'catalog': catalog, 'formats': get_formats(), 'plural': plural, } s = """$(document).ready(function () {var js = %s;Katrid.i18n.initialize(js.plural, js.catalog, js.formats)});""" % json.dumps(data) return HttpResponse(s)
def javascript_catalog(request, domain='djangojs', packages=None): locale = _get_locale(request) packages = _parse_packages(packages) catalog, plural = get_javascript_catalog(locale, domain, packages) data = { 'catalog': catalog, 'formats': get_formats(), 'plural': plural, } s = """$(document).ready(function () {var js = %s;Katrid.i18n.initialize(js.plural, js.catalog, js.formats)});""" % json.dumps( data) return HttpResponse(s)
def _create_javascript_catalog(self, locale, domain, packages): activate(locale) if django.VERSION < (2, 0): catalog, plural = get_javascript_catalog(locale, domain, packages) response = render_javascript_catalog(catalog, plural) else: catalog = JavaScriptCatalog() packages = get_packages(packages) # we are passing None as the request, as the request object is # currently not used by django response = catalog.get(self, None, domain=domain, packages=packages) return force_text(response.content)
def _create_json_catalog(self, locale, domain, packages): activate(locale) if django.VERSION < (2, 0): catalog, plural = get_javascript_catalog(locale, domain, packages) data = { 'catalog': catalog, 'formats': get_formats(), 'plural': plural, } return force_text(json.dumps(data, ensure_ascii=False)) else: catalog = JSONCatalog() packages = get_packages(packages) # we are passing None as the request, as the request object is currently not used by django response = catalog.get(self, None, domain=domain, packages=packages) return force_text(response.content)
def _create_json_catalog(self, locale, domain, packages): activate(locale) if django.VERSION < (2, 0): catalog, plural = get_javascript_catalog(locale, domain, packages) data = { 'catalog': catalog, 'formats': get_formats(), 'plural': plural, } return force_text(json.dumps(data, ensure_ascii=False)) else: catalog = JSONCatalog() packages = get_packages(packages) # we are passing None as the request, as the request object is # currently not used by django response = catalog.get(self, None, domain=domain, packages=packages) return force_text(response.content)
def generate_widget_js(lang): code = [] with language(lang): # Provide isolation code.append('(function (siteglobals) {\n') code.append('var module = {}, exports = {};\n') code.append('var lang = "%s";\n' % lang) catalog, plural = get_javascript_catalog(lang, 'djangojs', ['pretix']) catalog = dict( (k, v) for k, v in catalog.items() if k.startswith('widget\u0004')) template = Engine().from_string(js_catalog_template) context = Context({ 'catalog_str': indent(json.dumps(catalog, sort_keys=True, indent=2)) if catalog else None, 'formats_str': indent(json.dumps(get_formats(), sort_keys=True, indent=2)), 'plural': plural, }) code.append(template.render(context)) files = [ 'vuejs/vue.js' if settings.DEBUG else 'vuejs/vue.min.js', 'pretixpresale/js/widget/docready.js', 'pretixpresale/js/widget/floatformat.js', 'pretixpresale/js/widget/widget.js', ] for fname in files: f = finders.find(fname) with open(f, 'r') as fp: code.append(fp.read()) if settings.DEBUG: code.append('})(this);\n') else: # Do not expose debugging variables code.append('})({});\n') return ''.join(code)
def js_catalog(request, lang): packages = ['pretix'] catalog, plural = get_javascript_catalog(to_locale(lang), 'djangojs', packages) return render_javascript_catalog(catalog, plural)
def _create_javascript_catalog(self, locale, domain, packages): activate(locale) catalog, plural = get_javascript_catalog(locale, domain, packages) response = render_javascript_catalog(catalog, plural) return force_text(response.content)