当我运行此命令时:
django-admin makemessages -l ar
它给出了这个错误:
Traceback (most recent call last):
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\site-packages\django\utils\encoding.py", line 65, in force_text
s = str(s, encoding, errors)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 3107: invalid continuation byte
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Ahmed\AppData\Local\Programs\Python\Python36-32\Scripts\django-admin.exe\__main__.py", line 9, in <module>
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\site- packages\django\core\management\__init__.py", line 371, in execute_from_command_line
utility.execute()
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\site- packages\django\core\management\base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\base.py", line 335, in execute
output = self.handle(*args, **options)
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\commands\makemessages.py", line 384, in handle
potfiles = self.build_potfiles()
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\commands\makemessages.py", line 426, in build_potfiles
self.process_files(file_list)
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\commands\makemessages.py", line 522, in process_files
self.process_locale_dir(locale_dir, files)
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\commands\makemessages.py", line 590, in process_locale_dir
msgs, errors, status = popen_wrapper(args)
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\site-packages\django\core\management\utils.py", line 23, in popen_wrapper
force_text(output, stdout_encoding, strings_only=True, errors='strict'),
File "c:\users\ahmed\appdata\local\programs\python\python36-32\lib\site-packages\django\utils\encoding.py", line 69, in force_text
raise DjangoUnicodeDecodeError(s, *e.args)
django.utils.encoding.DjangoUnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 3107: invalid continuation byte. You passed in
除了错误之外,还为每个html文件创建了html.py
个文件。例如:对于index.html
,在模板文件夹中使用index.html.py
创建html.py
。这些BBBBBBBB
BBBBB BBBBBBB
XXXX XXXXXXXXXXXXXXXXXXXXX
XXXX XXXXXXXXX XXXXX XXX
XXXX XXXXXXXXXXXXXXXXXX
XXXX XXXXXXXXXXXXX
XXXX XXXXXXXXXXXXXXXXXX XX
XXX XXXXXXXXXXXXXX gettext(u'Les appels à projet') XXXXX
XXXX XXXXXXXXXXXXXXXXXXXXXXXXXX
XXX XXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXX
XXX XXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXX XXXXXXXXXXXXXX XXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXX XXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXX
XXXXXX
XXXXXX
XXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXX
XXXX XXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXX XXXXXXXXXXXX XXXXXXXXXXXX XXXXXXXXXXXXX XXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX
XXXXXXX
XXXX
XXXX gettext(u'Appel à projet') XXXXX
XXXX gettext(u'Date de lencement') XXXXX
XXXX gettext(u'Date de clature') XXXXX
XXXX gettext(u'Année budjitaire') XXXXX
XXXX gettext(u"N° d'apppel à projet") XXXXX
XXXX gettext(u"Etat d'appel") XXXXX
XXXX XXXX gettext(u'Action') XXXXX XXX
XXXXX
XXXXXXXX
XXXXXXX
BBB BBBBBB BB BBBBBBBBBBB
XXXX
XXXXXXXXX
XXXXXXXXX
XXXXXXXXX
文件只包含“X”和“B”字符以及要翻译的文本。
例如:
.po
我已经有一个用于Ar的makemessages
文件,其中有一些要翻译的文本,这是我在2个月前创建的,并且它已经完美翻译了。
但是当我运行@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(data,
getApplicationContext());
StringBuilder stBuilder = new StringBuilder();
Double latitude1 = Double.valueOf(place.getLatLng().latitude);
Double longitude1 = Double.valueOf(place.getLatLng().longitude);
myPosition = new LatLng(latitude1, longitude1);
mMap.clear();
mMap.addCircle(new CircleOptions()
.center(myPosition)
.radius(2000)
.strokeColor(Color.BLACK)
.fillColor(0x220000FF)
.strokeWidth(1)
);
mMap.moveCamera(CameraUpdateFactory.newLatLng(myPosition));
}
}
命令添加要翻译的新文本时,它会出现上述错误。
有什么想法吗?
答案 0 :(得分:1)
我找到了解决方案,我忘记了一些基础知识:p
问题出在模板名称中,我有两个名为CritéreGlobale.html
的模板文件和CritéreSpecifique.html
问题是文件名中的字符é
,在我将名称编辑为CritereGlobale.html
和CritereSpecifique.html
问题已解决,并且没有.html.py文件,命令运行完美。
希望能帮助别人
答案 1 :(得分:1)
.html.py
重复的文件存在相同的问题。我最后也得到了重复的.txt.py
文件,即使在我的静态文件夹中也是如此!而且解决方案与utf-8无关。
我的问题是我在项目级目录中执行了django-admin makemessages -l <locale>
。 makemessages
和compilemessages
命令必须在 app 目录中执行。
请注意,在执行命令之前,请不要忘记首先在应用程序内部创建locale
文件夹。另外,请使用区域设置名称字符串(格式为makemessages
,并用下划线和大写字母表示国家/地区)并使用 not 语言,执行ll_LL
命令代码(格式为ll-ll
,带短划线和大写字母)
我希望这对其他人有帮助,因为这是我在stackoverflow中发现的与此问题相关的唯一问题。
答案 2 :(得分:0)
而不是:
gettext(u'Les appels à projet')
尝试:
gettext('Les appels à projet')
希望它有所帮助。