语言包格式错误引起组件崩溃
2015-07-20 13:18
375 查看
最近在修正一些运行时错误中,发现了类似的错误模式,例如
打开SYSADMIN后,教师面板无法进入,检查lms/log发现
用户注册后不能发送邮件,也不能跳转到注册成功页面,而邮件却已正确配置。检查lms/log发现
共同的错误提示KeyError。在和社区开发者进行探讨后,认为是模板的问题,于是@wwj718修改了模板文件使组件可运行并提交commit到github。而edX社区的开发者提示这是语言包问题。
检查mako.po文件发现,的确是翻译者在变量中加入了错误的空格导致:
{link_start} -> { link_start }
{platform_name} -> { platform_name }
凡是错误加入空格的地方,涉及的组件都会出现KeyError错误。
一劳永逸的做法,我们已在transifex修正了目前发现的几十处类似语言包错误并确认审核。重新下载编译语言包即可修正此类错误。
打开SYSADMIN后,教师面板无法进入,检查lms/log发现
1 | File "/tmp/mako_lms/instructor/instructor_dashboard_2/course_info.html.py" , line 141, in render_body |
2 | link_end= '</a>' |
3 | KeyError: u ' link_start ' |
1 | Jul 15 12:33:10 i-hjpuo2yh [service_variant=lms][django.request][env:sandbox] ERROR [i-hjpuo2yh19843] [base.py:213] - Internal Server Error: /create_account |
2 | Traceback (most recent call last): |
3 | File"/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 109, in get_response |
4 | response = callback(request, *callback_args, **callback_kwargs) |
5 | File"/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 77, in wrapped_view |
6 | return view_func(*args, **kwargs) |
7 | File"/edx/app/edxapp/edx-platform/common/djangoapps/student/views.py", line 1615, in create_account |
8 | create_account_with_params(request, post_override or request.POST) |
9 | File"/edx/app/edxapp/edx-platform/common/djangoapps/student/views.py", line 1534, in create_account_with_params |
10 | message = render_to_string('emails/activation_email.txt', context) |
11 | File"/edx/app/edxapp/edx-platform/common/djangoapps/edxmako/shortcuts.py", line 134, in render_to_string |
12 | return template.render_unicode(**context_dictionary) |
13 | File"/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/template.py", line 452, in render_unicode |
14 | as_unicode=True) |
15 | File"/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py", line 807, in _render |
16 | **_kwargs_for_callable(callable_, data)) |
17 | File"/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py", line 839, in _render_context |
18 | _exec_template(inherit, lclcontext, args=args, kwargs=kwargs) |
19 | File"/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mako/runtime.py", line 865, in _exec_template |
20 | callable_(context, *args, **kwargs) |
21 | File"/tmp/mako_lms/emails/activation_email.txt.py", line 51, in render_body |
22 | platform_name=settings.PLATFORM_NAME |
23 | KeyError: u' platform_name ' |
1 | 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. |
2 |
3 | Can you double-check your translation files to see if there are spaces in the translated string? |
4 |
5 | :-1: on merging this change. |
6 |
7 |
8 | 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. |
{link_start} -> { link_start }
{platform_name} -> { platform_name }
凡是错误加入空格的地方,涉及的组件都会出现KeyError错误。
一劳永逸的做法,我们已在transifex修正了目前发现的几十处类似语言包错误并确认审核。重新下载编译语言包即可修正此类错误。
相关文章推荐