需要Google App Engine国际化帮助(Python) [英] Google App Engine Internationalization Help needed (Python)

查看:84
本文介绍了需要Google App Engine国际化帮助(Python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于如何在app engine / webapp / python中使用国际化有任何建议。我已经看到一些重新django - 翻译支持,但我似乎无法找到足够的信息,如何使其工作。



我需要的是一个解决方案, p>


  1. 浏览器可检测语言

  2. 用户可以覆盖并设置
  3. 模板中的字符串和代码中的字符串可以本地化

  4. 简单的文件编辑功能可支持语言支持。

我是新来的应用程序引擎,所以需要一些易于遵循/理解指针/代码帮助



多于

解决方案

有几个选项需要考虑。


  • 标准gettext()。请参阅代码示例。代码已过时:有一种管理cookie和会话的标准方式,因此应根据实际用途重新编写代码。


有时此方法失败,请参阅这个问题。通常只需重新上传应用程序即可解决问题,但这很奇怪。


  • 使用babel。它是纯Python,所以它可以轻松集成。缺点是外部依赖,但它很小,工作良好。 这里是解释的答案。


  • 不要在代码中执行l10n和i18n。我的观点是,GAE应该是后端服务,只是偶尔提供html服务。


    最近,我做了一个需要多种语言的Web UI的项目。这一次,我通过使用_()和gettext()(python模块,而不是django标签)创建主模板,提取字符串并迭代语言,生成了所需语言的一组模板。一个简单的模板加载器检查当前的语言并加载一个合适的模板。这个想法从p被无耻地偷走了。 1.

    Has anyone any suggestions on how to use internationalization in app engine / webapp / python. I have seen some posts re - django - translation support but i cant seem to find enough info on how to make it work.

    What i need is a solution where

    1. browser can detect language
    2. user can override and set
    3. strings in templates and from code can be localized
    4. easy file editing for language support.

    I'm new to app engine so need some easy to follow/understand pointers/code assistance

    many than

    解决方案

    There are several options to consider.

    • Standard gettext(). See this code example. The code is outdated: there is a standard way to manage cookies and sessions, so it should be rewritten for the real usage.

    Sometimes this method fails, see this issue. Usually it's resolved by just reuploading an application, but this is weird.

    • Use babel. It's pure python, so it can be integrated easily. The drawback is an external dependency, but it's small and good working. Here is an answer with explanations.

    • Don't do l10n and i18n in the code. My vision is that GAE should be a backend service, serving html just occasionally.

    Recently I did the project requiring web UI in several languages. This time I've generated a set of templates in all languages needed by making a 'master' template using _() and gettext() (python module, not django tags), extracting strings and iterating over the languages. A simple template loader checks the current language and loads an appropriate template. The idea is shamelessly stolen from p. 1.

    这篇关于需要Google App Engine国际化帮助(Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆