jakul / django-transifex Goto Github PK
View Code? Open in Web Editor NEWDjango integration with python-transifex
Django integration with python-transifex
When you install this library with pip:
pip install djangotransifex
It'll fail with the following error:
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "/private/var/folders/jc/c_vnhmp15sn_pbbssg69y95w0000gn/T/pip-build-oZlR_T/djangotransifex/setup.py", line 21, in <module>
long_description=open('README.md').read(),
IOError: [Errno 2] No such file or directory: 'README.md'
Looks like current source doesn't make this call anymore, can a new version be put on pypi?
When I run
./manage.py tx pull_translations
without having specified TRANSIFEX_PROJECT_PATH
in the settings I get the following exception:
Executing pull_translations on project test-392
Pulling translations for "test-392" project, in "en" source language
Traceback (most recent call last):
File "./manage.py", line 7, in <module>
execute_from_command_line(sys.argv)
File "/Users/harris/Workspaces/Unleash12/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Users/harris/Workspaces/Unleash12/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/harris/Workspaces/Unleash12/env/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/harris/Workspaces/Unleash12/env/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/Users/harris/Src/django-transifex/djangotransifex/management/commands/tx.py", line 75, in handle
command_func(*args[1:], **options)
File "/Users/harris/Src/django-transifex/djangotransifex/management/commands/tx.py", line 159, in transifex_pull_translations
project_slug=self.project_slug, source_language=self.source_language
File "/Users/harris/Src/django-transifex/djangotransifex/api.py", line 171, in pull_translations
'LC_MESSAGES'
File "/Users/harris/Workspaces/Unleash12/env/bin/../lib/python2.7/posixpath.py", line 70, in join
elif path == '' or path.endswith('/'):
AttributeError: 'function' object has no attribute 'endswith'
This is with Django 1.6.
It seems that if the path is not explicitly set, then django-transifex tries to figure out where the project is located using a lazy
function. There are two problems in the code:
str
as an additional parameter.There is also the problem that the actual helper function app_settings._get_project_path
does not handle the case where the settings file is not top-level in the project. In my case, all my settings are stored in a submodule structure.
The tests do not catch this, because the tests explicitly define TRANSIFEX_PROJECT_PATH
.
pull_translations does map from Transifex codes to Django codes and it works well, but it seems that upload_translations just uses the Django's language code, ignoring the mapping, which then creates the language as duplicate into the Transifex. As an example:
TRANSIFEX_LANGUAGE_MAPPING = {
"ru_ee": "ru",
"cs_CZ": "cs",
}
Now doing ./manage.py tx upload_translations ru
causes "Russian" to be created in Transifex, even though we already have "Russian (Estonia)" there and it is mapped in settings.
Not sure if this is intended behaviour, but personally I think it would be logical to also map the language codes when uploading.
djangotransifex
TRANSIFEX_
SOURCE_LANGUAGE_CODE
is TRANSIFEX_SOURCE_LANGUAGE
With django moving to argparse the management command now fails:
usage: manage.py tx [-h] [--version] [-v {0,1,2,3}] [--settings SETTINGS]
[--pythonpath PYTHONPATH] [--traceback] [--no-color]
manage.py tx: error: unrecognized arguments: pull_translations
basically this SO answer http://stackoverflow.com/questions/30230490/django-custom-command-error-unrecognized-arguments
A work around until the package is updated in pypi is to copy the tx.py file and put this in:
def add_arguments(self, parser):
parser.add_argument('args', nargs="+")
For some reason django-transifex requires some specific test package versions:
djangotransifex==0.1.10 requires django, mock==1.0.1, pytest-django==2.7, pytest==2.6.4, python-transifex>=0.1.7
This means we can't install our own versions of those packages.
There is no need for these test packages and can be moved to a requirements-dev.txt
We've been using django transfiex 1.6 with django 1.6 for ages now. Went to upgrade to 1.8 and it uninstall django and starts installing 1.5.12.
It's because this is in the requirements.txt:
django>=1.3,<1.6
Why the old version of django?
The default host https://www.transifex.net gives an SSL exception, as the site cert is for *.transifex.com. Would be good to update the default host to https://www.transifex.com
.
Running this:
python manage.py tx push --help
Gives this output:
usage: manage.py tx [-h] [--version] [-v {0,1,2,3}] [--settings SETTINGS]
[--pythonpath PYTHONPATH] [--traceback] [--no-color]
args [args ...]
Available Commands: * create_project Usage: ./manage.py tx create_project
Create the project on Transifex. * ping Ping the server to verify connection
details and auth details * pull_translations Usage: ./manage.py tx
pull_translations [options] Pull all translations from the Transifex server to
the local machine. This will overwrite any translations made locally *
upload_source_translations Usage: ./manage.py tx upload_source_translation
[options] Upload the source translation to Transifex. * upload_translations
Usage: ./manage.py tx upload_translations language_code [options] Upload the
translations for the given language to Transifex. This will overwrite any
translations made on the Transifex server
positional arguments:
args
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
-v {0,1,2,3}, --verbosity {0,1,2,3}
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on CommandError exceptions
--no-color Don't colorize the command output.
The list of available commands isn't that readable.
(venv)(venv) matt@Cronus[/Users/matt/Source/Pitchup.com]$ ./manage.py shell
Using settings: pitchup.settings.local
Traceback (most recent call last):
File "./manage.py", line 17, in <module>
execute_from_command_line(sys.argv)
File "/Users/matt/Source/Pitchup.com/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Users/matt/Source/Pitchup.com/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/matt/Source/Pitchup.com/venv/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/matt/Source/Pitchup.com/venv/lib/python2.7/site-packages/django/core/management/base.py", line 280, in execute
translation.activate('en-us')
File "/Users/matt/Source/Pitchup.com/venv/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 130, in activate
return _trans.activate(language)
File "/Users/matt/Source/Pitchup.com/venv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 188, in activate
_active.value = translation(language)
File "/Users/matt/Source/Pitchup.com/venv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/Users/matt/Source/Pitchup.com/venv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/Users/matt/Source/Pitchup.com/venv/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Users/matt/Source/Pitchup.com/venv/lib/python2.7/site-packages/djangotransifex/__init__.py", line 6, in <module>
VERSION = open(_version_path).read().rstrip() #rstrip() removes newlines
IOError: [Errno 2] No such file or directory: '/Users/matt/Source/Pitchup.com/venv/lib/python2.7/site-packages/djangotransifex/version.txt'
directory doesn't have version.txt (must be missing from the pypi package). Also version file in github at https://github.com/jakul/django-transifex/blob/master/djangotransifex/version.txt lists 1.7
Pypi lists version 1.8
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.