edX语言包格式错误引起组件崩溃

最近在修正一些运行时错误中,发现了类似的错误模式,例如

打开SYSADMIN后,教师面板无法进入,检查lms/log发现

File "/tmp/mako_lms/instructor/instructor_dashboard_2/course_info.html.py", line 141, in render_body
    link_end='</a>'
KeyError: u' link_start '

用户注册后不能发送邮件,也不能跳转到注册成功页面,而邮件却已正确配置。检查lms/log发现

Jul 15 12:33:10 i-hjpuo2yh [service_variant=lms][django.request][env:sandbox] ERROR [i-hjpuo2yh  19843] [base.py:213] - Internal Server Error: /create_account
Traceback (most recent call last):
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 109, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 77, in wrapped_view
    return view_func(*args, **kwargs)
  File "/edx/app/edxapp/edx-platform/common/djangoapps/student/views.py", line 1615, in create_account
    create_account_with_params(request, post_override or request.POST)
  File "/edx/app/edxapp/edx-platform/common/djangoapps/student/views.py", line 1534, in create_account_with_params
    message = render_to_string('emails/activation_email.txt', context)
  File "/edx/app/edxapp/edx-platform/common/djangoapps/edxmako/shortcuts.py", line 134, in render_to_string
    return template.render_unicode(**context_dictionary)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/template.py", line 452, in render_unicode
    as_unicode=True)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py", line 807, in _render
    **_kwargs_for_callable(callable_, data))
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py", line 839, in _render_context
    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
  File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py", line 865, in _exec_template
    callable_(context, *args, **kwargs)
  File "/tmp/mako_lms/emails/activation_email.txt.py", line 51, in render_body
    platform_name=settings.PLATFORM_NAME
KeyError: u' platform_name '

共同的错误提示KeyError。在和社区开发者进行探讨后,认为是模板的问题,于是@wwj718修改了模板文件使组件可运行并提交commit到github。而edX社区的开发者提示这是语言包问题。

This looks to me like a translator added spaces into the format placeholder, turning {link_start} into { link_start }. The fix is to remove the spaces in the translation. Removing the placeholder names as you have done will make it impossible to translate this string in the future.

Can you double-check your translation files to see if there are spaces in the translated string?

:-1: on merging this change.


PS, the command i18n_tool validate will find errors with all translation files you have, so you can correct them if you wish. On master, all translation files pass this check.

检查mako.po文件发现,的确是翻译者在变量中加入了错误的空格导致:

{link_start} -&gt; { link_start }
{platform_name} -&gt; { platform_name }

凡是错误加入空格的地方,涉及的组件都会出现KeyError错误。

一劳永逸的做法,我们已在transifex修正了目前发现的几十处类似语言包错误并确认审核。重新下载编译语言包即可修正此类错误。

`N9GM7DC@DJTH6HJ2_TK2]K D0D6E921-CCD7-4964-A919-8FA0329B13BF

Posted in Open edX.

edustack

edustack webmaster

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据