第三方应用程序的Django翻译

编程入门 行业动态 更新时间:2024-10-24 22:30:53
本文介绍了第三方应用程序的Django翻译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试翻译Django第三方应用程序( django-recurrence )在我的Django 1.7项目中.尽管我已经在这里阅读了有关同一问题的所有答案,但我仍然无法让Django为该应用程序生成django.po.

I'm trying to translate a Django third-party app (django-recurrence) within my Django 1.7 project. Despite all the answers I've been reading here about the same problem, I'm still being unable to have Django generate the django.po for this app.

这些是我当前的设置:

settings.py

LANGUAGE_CODE = 'it-IT' gettext = lambda s: s LANGUAGES = ( ('en-us', gettext('English')), ('it-it', gettext('Italian')), ) LOCALE_PATHS = ( '/home/seether/.virtualenvs/mytime/lib/python2.7/site-packages/recurrence/locale',) TIME_ZONE = 'Europe/Rome' USE_I18N = True USE_L10N = True

我尝试了几种修改LOCALE_PATHS的方法,例如:

I've tried modifying LOCALE_PATHS in several ways, like:

LOCALE_PATHS = (os.path.join(BASE_DIR,'locale-recurrence')) LOCALE_PATHS = (os.path.join(BASE_DIR,'locale')) ...

,依此类推.我已经从该应用程序手动翻译了django.po,尝试将其复制到此类目录中,使其与我不时尝试的设置相对应,但从未成功.我尝试将LANGUAGES和LANGUAGE_CODE更改为以下几乎所有可能的组合:"it","it-it","it_it","it-IT"和"it_IT".也没用.

and so on. I've manually translated the django.po from this app tried copying it in such directories accordingly to the settings I was trying time by time, but it never worked. I've tried changing LANGUAGES and LANGUAGE_CODE to almost every possible combination among: 'it', 'it-it', 'it_it', 'it-IT' and 'it_IT'. Didn't work either.

命令:

django-admin.py makemessages --all

只会为Django本身生成语言环境文件,而完全忽略了我要翻译的应用程序.我也尝试过使用django-rosetta,但是老实说,我自己已经翻译了该应用程序,所以我不能说要加深这条路.基本上,我认为找到正确的方法来简单地告诉Django编译我为django-recurrence编写的django.po并使用它就足够了.

would only produce locale files for Django itself, totally ignoring the app I want to translate. I've tried using django-rosetta as well, but I can't honestly tell to have deepen this path too much, having already translated the app myself. Basically, I think that finding the correct way of simply telling Django to compile the django.po I've written for django-recurrence and using it should be enough.

我在这里想念什么?

推荐答案

我的答案试图将 @ catabaran :

# From the root of your project (BASE_DIR): # Create a symlink to the application that needs to be translated ln -s /<path_to_virtualenv>/lib/pythonx.x/site-packages/<app> ./ # Instruct makemessages to follow the symlink ./manage.py makemessages -s # Create a folder called "tpa_translation" # (Third Party Applications Translation) mkdir ./<proj>/tpa_translation/<app> # Copy inside, the directory tree that springs from your language. # This is usually located inside the locale directory # of the third party application. cp -R ./<app>/locale/<your_lang> ./<proj>/tpa_translation/<app>/ # Result: # If <your_lang> is "en", the resulting folder will be: # f"{BASE_DIR / 'tpa_translation' / '<app>' / 'en'}" # Set accordingly the LOCALE_PATHS in settings.py: ... LOCALE_PATHS = [ ..., f"{BASE_DIR / 'tpa_translation' / '<app>'}", ..., ] ... #Remove the symlink rm ./<app> # Translate the .po file: vim <proj>/tpa_translation/<app>/<your_lang>/LC_MESSAGES/django.po # Compile messages ./manage.py compilemessages # At this point django will message that a .mo file was created # inside the directory where the new .po file exists.

更多推荐

第三方应用程序的Django翻译

本文发布于:2023-11-27 03:31:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636390.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:第三方   应用程序   Django

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!