當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。