我刚刚排队,觉得我还没完成!我创建并编译了所有消息,以便拥有一个包含2种语言的站点,并且在运行服务器时收到此错误:AttributeError:module' locale'没有属性'规范化'。
有人可以帮帮我吗?
Traceback (most recent call last):
File "/Users/ionutcohen/Dropbox/PycharmProjects/chn/manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/Users/ionutcohen/Dropbox/PycharmProjects/chn/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/Users/ionutcohen/Dropbox/PycharmProjects/chn/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 306, in execute
parser = CommandParser(None, usage="%(prog)s subcommand [options] [args]", add_help=False)
File "/Users/ionutcohen/Dropbox/PycharmProjects/chn/venv/lib/python3.6/site-packages/django/core/management/base.py", line 47, in __init__
super().__init__(**kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/argparse.py", line 1633, in __init__
self._positionals = add_group(_('positional arguments'))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/gettext.py", line 606, in gettext
return dgettext(_current_domain, message)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/gettext.py", line 570, in dgettext
codeset=_localecodesets.get(domain))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/gettext.py", line 505, in translation
mofiles = find(domain, localedir, languages, all=True)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/gettext.py", line 477, in find
for nelang in _expand_lang(lang):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/gettext.py", line 206, in _expand_lang
loc = locale.normalize(loc)
AttributeError: module 'locale' has no attribute 'normalize'
Process finished with exit code 1
这是gettext.py中引用错误的函数。似乎第一行有错误:
def _expand_lang(loc):
loc = locale.normalize(loc)
COMPONENT_CODESET = 1 << 0
COMPONENT_TERRITORY = 1 << 1
COMPONENT_MODIFIER = 1 << 2
# split up the locale into its base components
mask = 0
pos = loc.find('@')
if pos >= 0:
modifier = loc[pos:]
loc = loc[:pos]
mask |= COMPONENT_MODIFIER
else:
modifier = ''
pos = loc.find('.')
if pos >= 0:
codeset = loc[pos:]
loc = loc[:pos]
mask |= COMPONENT_CODESET
else:
codeset = ''
pos = loc.find('_')
if pos >= 0:
territory = loc[pos:]
loc = loc[:pos]
mask |= COMPONENT_TERRITORY
else:
territory = ''
language = loc
ret = []
for i in range(mask+1):
if not (i & ~mask): # if all components for this combo exist ...
val = language
if i & COMPONENT_TERRITORY: val += territory
if i & COMPONENT_CODESET: val += codeset
if i & COMPONENT_MODIFIER: val += modifier
ret.append(val)
ret.reverse()
return ret
稍后编辑:我删除了init文件,现在我收到了这个错误:
File "/Users/ionutcohen/Dropbox/PycharmProjects/chn/manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
File "/Users/ionutcohen/Dropbox/PycharmProjects/chn/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 12, in <module>
from django.core.management.base import (
File "/Users/ionutcohen/Dropbox/PycharmProjects/chn/venv/lib/python3.6/site-packages/django/core/management/base.py", line 7, in <module>
from argparse import ArgumentParser
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/argparse.py", line 93, in <module>
from gettext import gettext as _, ngettext
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/gettext.py", line 409
advance to next entry in the seek tables
^
SyntaxError: invalid syntax
Process finished with exit code 1
答案 0 :(得分:3)
我也一样。在PyCharm中,我已经为我的国际化制作了一个目录“locale”(无条件地export default {
props: ['message'],
data(){
var self = this; // Add this
return{
time: '',
colorArray: ['hsl(210 , 82 , 50 )', 'hsl(130 , 50 , 51 )', 'hsl(337 , 50 , 46 )','hsl(133 , 50 , 65 )', 'hsl(28 , 50 , 70 )','hsl(180 , 50 , 59 )' , 'hsl(274 , 50 , 82 )'],
colorClass:'',
styles: {
'background-color' : self.colorArray[2] // change here
},
}
},
...
),并得到了这样的信息:
$query = db_select('Two', 't');
$query->join('One', 'o', 'o.column1 = t.column1');
$query->fields('t',array('column1','column2'));
$query->orderBy('t.column1', 'DESC');
$res = $query->execute()->fetchAll();
这是因为它正在寻找一个Python模块“locale”,但是被Django目录“locale”掩盖了。
删除__init__.py
和/或重命名目录“locale”。我做了两件事......“如我们在荷兰所说的那样,将两次缝合在一起就好了”。
似乎网上的每个人都使用“locale”作为国际化的目录。嗯..现在在我看来有点像创建一个名为“Class”的类或一个名为“Table”的SQL表。我已经完成了,有时它有效,但我绝不会推荐它。