jakul / python-transifex Goto Github PK
View Code? Open in Web Editor NEWPython Transifex API
Python Transifex API
Executing pull_translations on project pitchupcom
Pulling translations for "pitchupcom" project, in "en_GB" source language
Traceback (most recent call last):
File "manage.py", line 12, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/app/pitchup/campsite/management/commands/tx.py", line 80, in handle
command_func(*args[1:], **options)
File "/app/pitchup/campsite/management/commands/tx.py", line 164, in transifex_pull_translations
project_slug=self.project_slug, source_language=self.source_language
File "/app/lib/djangotransifex/api.py", line 157, in pull_translations
resources = self.list_resources(project_slug)
File "/usr/local/lib/python2.7/site-packages/transifex/api.py", line 106, in list_resources
return json.loads(response.content)
File "/usr/local/lib/python2.7/json/__init__.py", line 339, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python2.7/json/decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python2.7/json/decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
Using it in django-transifex but error is in here.
the response.content is no longer json encoded
according to the response headers it's python pickle format
My guess is that the request headers which by default set to accept / and a user agent of python-requests cause their api to issue a different format in response.
It would be useful if .get_translation()
return data instead of writing to file. In order to not to break backward compatibility it can return data if path_to_pofile
argument is None
. Something like that:
def get_translation(self, project_slug, resource_slug, language_code,
path_to_pofile=None):
...
url = '%s/project/%s/resource/%s/translation/%s/' % (
self._base_api_url, project_slug, resource_slug, language_code
)
output_path = path_to_pofile
query = {
'file': ''
}
response = requests.get(url, auth=self._auth, params=query)
if response.status_code != requests.codes['OK']:
raise TransifexAPIException(response)
else:
if path_to_file is not None:
handle = open(output_path, 'w')
for line in response.iter_content():
handle.write(line)
handle.close()
else:
return response.content
The purpose of changes in my case is to load a bunch of translated files then ask a user where to save them and then write them to that directory.
.... and document how to run tests
setup.py is reading the contents of requirements.txt and using that for the install_requires attribute. However, this has several problems:
[10:44:05] abadger1999: yes, setup.py requirements are abstract, they don't specify anything about where to get it from, it's jsut "I need a list of things that claim to be X, Y and Z", where requirements.txt is "I need X from pypi.python.org, Y from foo.example.com, Z from foo.com"
The recommendation from pip authors is that requirements.txt and setup.py should have two separate lists since they serve two different purposes.
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.