本文整理匯總了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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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
示例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)
示例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)
示例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()
示例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('')
############################################################################
示例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()
示例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
示例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)