2014-11-05 73 views
0

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

这是我的当前设置:

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,如:

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”。也没有工作。

命令:

django-admin.py makemessages --all 

只会产生语言文件Django的本身,完全不理我想翻译的应用程序。 我也尝试过使用django-rosetta,但是我不能诚实地告诉我已经加深了这个路径,已经自己翻译了这个应用。基本上,我认为找到简单地告诉Django编译django.po的正确方法是我为django-recurrence编写并使用它应该足够了。

我在这里错过了什么?

回答

1

我的答案是试图编译由@catabaran提供的答案中描述的所有步骤一起:

# Make symlink to the application that needs to be translated 
ln -s ~/.virtualenvs/<virtyalenv>/lib/python3.4/site-packages/<app> ./ 

# Makemessages following the symlink 
./manage.py makemessages -s 

# Create a folder called tpa_translation (Third Party Applications Translation) 
# at the main project folder (where settings.py is located). 
# Copy there, the directory tree that springs from your language and is located 
# inside the locale directory of the third party application. 
mkdir <proj>/tpa_translation/<app> 
cp -R ./<app>/locale/<your_lang> <proj>/tpa_translation/<app>/ 

# Include this path in the locale_paths in settings.py: 
... 
LOCALE_PATHS = [ 
    ..., 
    join('path', 'to', '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 at the directory where the new .po file exists. 
1

的我发现,最简单的方法就是将模块分叉,将其克隆到计算机,获取示例项目,然后执行翻译。一旦你将这些翻译推回到你的分叉库,你可以使用它来代替正式版本。你可以用它requirements.txtgit+https://github.com/my-respository.git。您还可以翻译模块并向原作者发送合并请求。如果幸运的话,他们会将其合并到原始回购中,以便您可以切换回原来的回购。

其他解决方案是有问题的。例如,如果您的第一语言是德语,但该模块是用英语书写的,那么在获得正确的翻译时您将遇到问题。

希望有所帮助。