from django.core.management.commands.compilemessages import compile_messages
और अपने setup.py
लिपि में इसका इस्तेमाल करते हैं इससे पहले कि आप setup
विधि में setup
चलाने के लिए और उसके बाद बनाई गई फ़ाइलों में शामिल हैं।
#!/usr/bin/env python
from setuptools import setup, find_packages
from setuptools.command.install_lib import install_lib as _install_lib
from distutils.command.build import build as _build
from distutils.cmd import Command
class compile_translations(Command):
description = 'compile message catalogs to MO files via django compilemessages'
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
import os
import sys
from django.core.management.commands.compilemessages import \
compile_messages
curdir = os.getcwd()
os.chdir(os.path.realpath('app_name'))
compile_messages(stderr=sys.stderr)
os.chdir(curdir)
class build(_build):
sub_commands = [('compile_translations', None)] + _build.sub_commands
class install_lib(_install_lib):
def run(self):
self.run_command('compile_translations')
_install_lib.run(self)
setup(name='app',
packages=find_packages(),
include_package_data=True,
setup_requires=['django'],
...
cmdclass={'build': build, 'install_lib': install_lib,
'compile_translations': compile_translations}
)
यह आपको पो फ़ाइलें संकलन जब आप अंडे के निर्माण या पैकेज स्थापित करने में मदद मिलेगी:
प्रश्न यह कार्य स्वचालित करने के बारे में है –
सेटअप स्क्रिप्ट एक सामान्य 'पायथन' स्क्रिप्ट है, इसलिए आप इसके अंदर 'Django' से कोड का उपयोग कर सकते हैं। एक सामान्य प्रोग्राम 'setup.py' पर विचार करें, जिसका लक्ष्य आपके पैकेज को स्थापित करना है और उसे विभिन्न चरणों का पालन करना होगा। उनमें से एक 'Django' से 'compile_messages' का आह्वान कर रहा है। यह स्वचालित रूप से पैकेज को स्थापित करने का कार्य करेगा - आपको 'setup.py' चलाने से पहले 'django-admin compilemessages' को कॉल करने की आवश्यकता नहीं है। – gruszczy