【问题标题】:Django custom locale directoryDjango 自定义语言环境目录
【发布时间】:2010-03-29 19:03:00
【问题描述】:

我正在开发一个包含两个不同站点的项目,除以 语言。也许我错了,但现在我的目录结构 看起来像:

/ruapp/settings.py # SITE_ID = 1 
/ruapp/manage.py 
/enapp/settings.py # SITE_ID = 2 
/enapp/manage.py 
/common/urls.py 
/common/ # almost every other file 
/common/templates/ # templates with {% trans %} 
/locale/ # with locales ru-ru and en-us, generated by calling 
makemessages from the root of all this structure

如何告诉 django 语言环境?似乎不会 自行查找 /locale/ 文件夹

【问题讨论】:

    标签: django internationalization locale


    【解决方案1】:

    AFAIK,python-gettext 不能使用不同的文件夹,所以...使用符号链接,Luke!

    【讨论】:

      【解决方案2】:

      确保本地化文件的目录结构如下所示:

      locale/en/LC_MESSAGES/django.mo 
      locale/ru/LC_MESSAGES/django.mo
      

      如果您将它们命名为其他名称,或者将它们放在其他地方,它可能不会起作用。

      您还需要在设置文件中提供适当的 l18n 信息。 LANGUAGE_CODE = 'en' 在一个中,LANGUAGE_CODE = 'ru' 在另一个中。

      编辑:您是否创建了两个独立的应用程序或两个独立的项目?应用程序通常没有自己的 settings.py 和 manage.py...

      您可以拥有一个项目,其中包含多个设置文件并运行多个网站。如果你的目录结构看起来像这样,会更加 django-ish(并且更容易处理):

      /settings_ru.py # SITE_ID = 1 
      /settings_en.py # SITE_ID = 2 
      /manage.py # use --settings option to distinguish between settings files.
      /urls.py 
      /templates/ # templates with {% trans %} 
      /locale/ # locale/en/LC_MESSAGES/django.mo and locale/ru/LC_MESSAGES/django.mo 
      (+ other common code, inside their respective apps)
      

      【讨论】:

        猜你喜欢
        • 2017-02-25
        • 2014-02-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多