Пример #1
0
    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))
Пример #2
0
Файл: i18n.py Проект: laoyin/nyf
def javascript_catalog(request, domain='djangojs', packages=None):
    """
    Returns the selected language catalog as a javascript library.

    Receives the list of packages to check for translations in the
    packages parameter either from an infodict or as a +-delimited
    string from the request. Default is 'django.conf'.

    Additionally you can override the gettext domain for this view,
    but usually you don't want to do that, as JavaScript messages
    go to the djangojs domain. But this might be needed if you
    deliver your JavaScript source from Django templates.
    """
    locale = to_locale(get_language())

    if request.session and 'django_language' in request.session:
        if check_for_language(request.session['django_language']):
            locale = to_locale(request.session['django_language'])

    if request.GET and 'language' in request.GET:
        if check_for_language(request.GET['language']):
            locale = to_locale(request.GET['language'])

    if packages is None:
        packages = ['django.conf']
    if isinstance(packages, six.string_types):
        packages = packages.split('+')

    catalog, plural = get_javascript_catalog(locale, domain, packages)
    return render_javascript_catalog(catalog, plural)
Пример #3
0
 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)
Пример #4
0
    def i18n_javascript(self, request):
        """
        Displays the i18n JavaScript that the Django admin requires.

        This takes into account the USE_I18N setting. If it's set to False, the
        generated JavaScript will be leaner and faster.
        """
        if settings.USE_I18N:
            from django.views.i18n import render_javascript_catalog
        else:
            from django.views.i18n import null_javascript_catalog as render_javascript_catalog
        return render_javascript_catalog()
Пример #5
0
 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)
Пример #6
0
def cached_javascript_catalog(request):

    language = request.GET.get(LANGUAGE_QUERY_PARAMETER)
    if not (language and check_for_language(language)):
        language = get_language()
    locale = to_locale(language)

    packages = ['wirecloud.commons', 'wirecloud.catalogue', 'wirecloud.platform']

    for plugin in get_plugins():
        packages.append(plugin.__module__.rsplit('.', 1)[0])

    for theme in get_available_themes():
        packages.append(theme)

    catalog, plural = get_javascript_catalog(locale, 'djangojs', packages)
    return render_javascript_catalog(catalog, plural)
Пример #7
0
def cached_javascript_catalog(request):

    language = request.GET.get(LANGUAGE_QUERY_PARAMETER)
    if not (language and check_for_language(language)):
        language = get_language()
    locale = to_locale(language)

    packages = ['wirecloud.commons', 'wirecloud.catalogue', 'wirecloud.platform']

    for plugin in get_plugins():
        packages.append(plugin.__module__.rsplit('.', 1)[0])

    for theme in get_available_themes():
        packages.append(theme)

    catalog, plural = get_javascript_catalog(locale, 'djangojs', packages)
    return render_javascript_catalog(catalog, plural)
Пример #8
0
def js_catalog(request, lang):
    packages = ['pretix']
    catalog, plural = get_javascript_catalog(to_locale(lang), 'djangojs', packages)
    return render_javascript_catalog(catalog, plural)
Пример #9
0
    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)
Пример #10
0
    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)
Пример #11
0
def js_catalog(request, lang):
    c = JavaScriptCatalog()
    c.translation = DjangoTranslation(lang, domain='djangojs')
    return render_javascript_catalog(c.get_catalog(), c.get_plural())