当前位置: 首页>>代码示例>>Python>>正文


Python settings.LOCALE_PATHS属性代码示例

本文整理汇总了Python中django.conf.settings.LOCALE_PATHS属性的典型用法代码示例。如果您正苦于以下问题:Python settings.LOCALE_PATHS属性的具体用法?Python settings.LOCALE_PATHS怎么用?Python settings.LOCALE_PATHS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在django.conf.settings的用法示例。


在下文中一共展示了settings.LOCALE_PATHS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOCALE_PATHS [as 别名]
def handle(self, *args, **options):
        self.set_options(**options)

        assert getattr(settings, 'USE_I18N', False), 'i18n framework is disabled'
        assert getattr(settings, 'LOCALE_PATHS', []), 'locale paths is not configured properly'
        for directory in settings.LOCALE_PATHS:
            # walk through all the paths
            # and find all the pot files
            for root, dirs, files in os.walk(directory):
                for file in files:
                    if not file.endswith('.po'):
                        # process file only
                        # if its a pot file
                        continue

                    # get the target language from the parent folder name
                    target_language = os.path.basename(os.path.dirname(root))

                    if self.locale and target_language not in self.locale:
                        logger.info('skipping translation for locale `{}`'.format(target_language))
                        continue

                    self.translate_file(root, file, target_language) 
开发者ID:ankitpopli1891,项目名称:django-autotranslate,代码行数:25,代码来源:translate_messages.py

示例2: _add_local_translations

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOCALE_PATHS [as 别名]
def _add_local_translations(self):
        """Merges translations defined in LOCALE_PATHS."""
        for localedir in reversed(settings.LOCALE_PATHS):
            translation = self._new_gnu_trans(localedir)
            self.merge(translation) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:7,代码来源:trans_real.py

示例3: all_locale_paths

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOCALE_PATHS [as 别名]
def all_locale_paths():
    """
    Returns a list of paths to user-provides languages files.
    """
    globalpath = os.path.join(
        os.path.dirname(upath(sys.modules[settings.__module__].__file__)), 'locale')
    return [globalpath] + list(settings.LOCALE_PATHS) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:9,代码来源:trans_real.py

示例4: _add_local_translations

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOCALE_PATHS [as 别名]
def _add_local_translations(self):
        """Merge translations defined in LOCALE_PATHS."""
        for localedir in reversed(settings.LOCALE_PATHS):
            translation = self._new_gnu_trans(localedir)
            self.merge(translation) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:7,代码来源:trans_real.py

示例5: all_locale_paths

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOCALE_PATHS [as 别名]
def all_locale_paths():
    """
    Return a list of paths to user-provides languages files.
    """
    globalpath = os.path.join(
        os.path.dirname(sys.modules[settings.__module__].__file__), 'locale')
    return [globalpath] + list(settings.LOCALE_PATHS) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:9,代码来源:trans_real.py

示例6: deploy

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOCALE_PATHS [as 别名]
def deploy():
    hidden_imports = ['http.cookies', 'html.parser',
                      'settings', 'apps', 'django.template.defaulttags',
                      'django.templatetags.i18n', 'django.template.loader_tags',
                      'django.utils.translation'
                      ]
    for app in settings.INSTALLED_APPS:
        if app.startswith('django.'):
            hidden_imports.append(app + '.apps')
        else:
            hidden_imports.append(app)

            cmd = "pyinstaller __main__.py "
    for i in hidden_imports:
        cmd += " --hidden-import "
        cmd += i

    os.system(cmd)
    if settings.DATABASES['default']['ENGINE'] == 'django.db.backends.sqlite3':
        dist_dir = os.path.join(os.path.join(settings.BASE_DIR, 'dist'), '__main__')
        if os.path.isdir(dist_dir):
            shutil.copy(settings.DATABASES['default']['NAME'], dist_dir)
    if settings.LANGUAGES is not None:
        for lang in settings.LANGUAGES:
            execute_django_command(["makemessages", "-l", lang[0]])
        execute_django_command(["compilemessages"])
        try:
            shutil.copytree(settings.LOCALE_PATHS[0], os.path.join(dist_dir, '.locale'))
        except Exception as e:
            print(e) 
开发者ID:ZedObaia,项目名称:django-pyqt,代码行数:32,代码来源:manage.py

示例7: deploy

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOCALE_PATHS [as 别名]
def deploy():
    if not os.path.isfile(configFile):
        print("Missing config.json")
        hidden_imports = []
    else:
        with open(configFile) as f:
            config = json.load(f)
        hidden_imports = config["hidden-imports"]
    if config["django"] :
        for app in settings.INSTALLED_APPS:
            if app.startswith('django.'):
                hidden_imports.append(app + '.apps')
            else:
                hidden_imports.append(app)

    cmd = "pyinstaller __main__.py "
    for i in hidden_imports:
        cmd += " --hidden-import "
        cmd += i

    os.system(cmd)
    if config["django"]:
        dist_dir = os.path.join(os.path.join(settings.BASE_DIR, 'dist'), '__main__')
        if settings.DATABASES['default']['ENGINE'] == 'django.db.backends.sqlite3':
            if os.path.isfile(settings.DATABASES['default']['NAME']) :
                if os.path.isdir(dist_dir):
                    shutil.copy(settings.DATABASES['default']['NAME'], dist_dir)
            else:
                print("{} was not found".format(settings.DATABASES['default']['NAME'])  )
        if settings.LANGUAGES is not None:
            for lang in settings.LANGUAGES:
                execute_django_command(["makemessages", "-l", lang[0]])
            execute_django_command(["compilemessages"])
            try:
                shutil.copytree(settings.LOCALE_PATHS[0], os.path.join(dist_dir, '.locale'))
            except Exception as e:
                print(e) 
开发者ID:ZedObaia,项目名称:django-pyqt,代码行数:39,代码来源:manage.py

示例8: all_locale_paths

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOCALE_PATHS [as 别名]
def all_locale_paths():
    """
    Return a list of paths to user-provides languages files.
    """
    globalpath = os.path.join(
        os.path.dirname(sys.modules[settings.__module__].__file__), 'locale')
    app_paths = []
    for app_config in apps.get_app_configs():
        locale_path = os.path.join(app_config.path, 'locale')
        if os.path.exists(locale_path):
            app_paths.append(locale_path)
    return [globalpath] + list(settings.LOCALE_PATHS) + app_paths 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:14,代码来源:trans_real.py

示例9: all_locale_paths

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOCALE_PATHS [as 别名]
def all_locale_paths():
    """
    Returns a list of paths to user-provides languages files.
    """
    from django.conf import settings
    globalpath = os.path.join(
        os.path.dirname(upath(sys.modules[settings.__module__].__file__)), 'locale')
    return [globalpath] + list(settings.LOCALE_PATHS) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:10,代码来源:trans_real.py

示例10: compile_messages

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOCALE_PATHS [as 别名]
def compile_messages(stderr, locale=None):
    basedirs = [os.path.join('conf', 'locale'), 'locale']
    if os.environ.get('DJANGO_SETTINGS_MODULE'):
        from django.conf import settings
        basedirs.extend(settings.LOCALE_PATHS)

    # Gather existing directories.
    basedirs = set(map(os.path.abspath, filter(os.path.isdir, basedirs)))

    if not basedirs:
        raise CommandError("This script should be run from the Django Git checkout or your project or app tree, or with the settings module specified.")

    for basedir in basedirs:
        if locale:
            basedir = os.path.join(basedir, locale, 'LC_MESSAGES')
        for dirpath, dirnames, filenames in os.walk(basedir):
            for f in filenames:
                if f.endswith('.po'):
                    stderr.write('processing file %s in %s\n' % (f, dirpath))
                    fn = os.path.join(dirpath, f)
                    if has_bom(fn):
                        raise CommandError("The %s file has a BOM (Byte Order Mark). Django only supports .po files encoded in UTF-8 and without any BOM." % fn)
                    pf = os.path.splitext(fn)[0]
                    # Store the names of the .mo and .po files in an environment
                    # variable, rather than doing a string replacement into the
                    # command, so that we can take advantage of shell quoting, to
                    # quote any malicious characters/escaping.
                    # See http://cyberelk.net/tim/articles/cmdline/ar01s02.html
                    os.environ['djangocompilemo'] = npath(pf + '.mo')
                    os.environ['djangocompilepo'] = npath(pf + '.po')
                    if sys.platform == 'win32': # Different shell-variable syntax
                        cmd = 'msgfmt --check-format -o "%djangocompilemo%" "%djangocompilepo%"'
                    else:
                        cmd = 'msgfmt --check-format -o "$djangocompilemo" "$djangocompilepo"'
                    os.system(cmd) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:37,代码来源:compilemessages.py

示例11: set_rels

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOCALE_PATHS [as 别名]
def set_rels(apps, schema_editor):
    TranslationEntry = apps.get_model('translation_manager', 'TranslationEntry')
    for row in TranslationEntry.objects.all():
        row.locale_path = os.path.relpath(settings.LOCALE_PATHS[0], get_settings('TRANSLATIONS_BASE_DIR'))
        row.save()

    TranslationBackup = apps.get_model('translation_manager', 'TranslationBackup')
    for row in TranslationBackup.objects.all():
        row.locale_path = os.path.relpath(settings.LOCALE_PATHS[0], get_settings('TRANSLATIONS_BASE_DIR'))
        row.save() 
开发者ID:COEXCZ,项目名称:django-translation-manager,代码行数:12,代码来源:0004_set_new_relative_paths.py

示例12: backup_po_to_db

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOCALE_PATHS [as 别名]
def backup_po_to_db(self):
        """ Backup Po file to db model """

        for lang, lang_name in settings.LANGUAGES:
            for path in settings.LOCALE_PATHS:
                po_pattern = os.path.join(path, get_dirname_from_lang(lang), "LC_MESSAGES", "*.po")
                for pofile in glob(po_pattern):
                    logger.debug("Backuping file {} to db".format(pofile))

                    domain = os.path.splitext(os.path.basename(pofile))[0]
                    with codecs.open(pofile, 'r', 'utf-8') as pofile_opened:
                        content = pofile_opened.read()
                        backup = TranslationBackup(
                            language=lang,
                            locale_path=get_relative_locale_path(pofile),
                            domain=domain,
                            locale_parent_dir=get_locale_parent_dirname(pofile),
                            content=content,
                        )
                        backup.save()

                    if get_settings('TRANSLATIONS_CLEAN_PO_AFTER_BACKUP'):
                        with open(pofile, 'w') as pofile_opened:
                            pofile_opened.write('')

    ############################################################################ 
开发者ID:COEXCZ,项目名称:django-translation-manager,代码行数:28,代码来源:manager.py

示例13: load_data_from_po

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOCALE_PATHS [as 别名]
def load_data_from_po(self):
        import os

        for lang, lang_name in settings.LANGUAGES:
            for path in settings.LOCALE_PATHS:
                locale = get_dirname_from_lang(lang)
                po_pattern = os.path.join(path, locale, "LC_MESSAGES", "*.po")
                for pofile in glob(po_pattern):
                    logger.debug("Processing pofile {}".format(pofile))
                    self.store_to_db(pofile=pofile, locale=locale, store_translations=True)

        self.postprocess() 
开发者ID:COEXCZ,项目名称:django-translation-manager,代码行数:14,代码来源:manager.py

示例14: enable_theming

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOCALE_PATHS [as 别名]
def enable_theming():
    """
        Add directories and relevant paths to settings for comprehensive theming.
    """
    for theme in get_themes():
        locale_dir = theme.path / "conf" / "locale"
        if locale_dir.isdir():
            settings.LOCALE_PATHS = (locale_dir, ) + settings.LOCALE_PATHS 
开发者ID:edx,项目名称:ecommerce,代码行数:10,代码来源:core.py

示例15: test_enable_theming

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import LOCALE_PATHS [as 别名]
def test_enable_theming(self):
        """
        Tests for enable_theming method.
        """
        themes_dirs = settings.COMPREHENSIVE_THEME_DIRS

        expected_locale_paths = (
            themes_dirs[0] / "test-theme" / "conf" / "locale",
            themes_dirs[0] / "test-theme-2" / "conf" / "locale",
            themes_dirs[1] / "test-theme-3" / "conf" / "locale",
        ) + settings.LOCALE_PATHS

        enable_theming()

        six.assertCountEqual(self, expected_locale_paths, settings.LOCALE_PATHS) 
开发者ID:edx,项目名称:ecommerce,代码行数:17,代码来源:test_core.py


注:本文中的django.conf.settings.LOCALE_PATHS属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。