GithubHelp home page GithubHelp logo

saigesp / json-translate Goto Github PK

View Code? Open in Web Editor NEW
39.0 39.0 16.0 84 KB

Translate json files with DeepL or AWS

License: GNU Lesser General Public License v2.1

Python 100.00%
deepl json python translation

json-translate's Introduction

Hello World!

I'm a full-stack web developer with Industrial Design Engineering background.

I started working as a UX/UI designer, evolving to front-end and later to full-stack developer specialized in data visualization, data platforms and advanced web scrapers. My main stack is PostgreSQL, Python, Django, Vue and D3, and I have extensive experience with MongoDB, PHP, Wordpress, jQuery, Angular, AWS, GIS and design software.

Linkedin Badge Twitter Badge

Some of my public projects are:

  • datahippo: Public database on tourist accommodations.
  • Maindoc: Invoicing platform for small companies and freelancers.
  • 28M-calle-a-calle: Street-by-street results of the 2023 municipal elections in Spain.
  • vue-d3-charts: Charts library build with reusability in mind.
  • json-translate: Translation script for json files with deepl API.
  • provincia53: Storytelling about Western Sahara.
  • Ojito: Visualization of spanish political commitments.
  • DS-Compass: Risk assessment tool for human rights defenders in hostile environments.
  • OpenODS-Index: Fulfillment of the Sustainable Development Goals by public and private entities.
  • stopcasasdeapuestas: Collection, analysis and visualization of betting sites in Madrid & Spain.
  • 5scdgame: Mini-game based on a conference logo.
  • spanishrap: Visualization of the most prolific rappers on the Spanish scene

json-translate's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

json-translate's Issues

Getting AWS related errors when attempting to use DeepL

Hello, I'm getting AWS related errors when I try to use this package with DeepL

When running json_translate deepl locales/common/en.json en-GB

I get the following error

json_translate aws locales/common/en.json en-GB
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.12/bin/json_translate", line 5, in <module>
    from json_translate.commands import main
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/json_translate/commands.py", line 12, in <module>
    from translators import get_translator
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/json_translate/translators/__init__.py", line 3, in <module>
    from .aws import AWSTranslator
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/json_translate/translators/aws.py", line 11, in <module>
    class AWSTranslator(BaseTranslator):
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/json_translate/translators/aws.py", line 14, in AWSTranslator
    client = boto3.client(
             ^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/boto3/__init__.py", line 92, in client
    return _get_default_session().client(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/boto3/session.py", line 299, in client
    return self._session.create_client(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/botocore/session.py", line 997, in create_client
    client = client_creator.create_client(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/botocore/client.py", line 159, in create_client
    client_args = self._get_client_args(
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/botocore/client.py", line 490, in _get_client_args
    return args_creator.get_client_args(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/botocore/args.py", line 100, in get_client_args
    final_args = self.compute_client_args(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/botocore/args.py", line 219, in compute_client_args
    endpoint_config = self._compute_endpoint_config(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/botocore/args.py", line 368, in _compute_endpoint_config
    return self._resolve_endpoint(**resolve_endpoint_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/botocore/args.py", line 473, in _resolve_endpoint
    return endpoint_bridge.resolve(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/botocore/client.py", line 595, in resolve
    resolved = self.endpoint_resolver.construct_endpoint(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/botocore/regions.py", line 229, in construct_endpoint
    result = self._endpoint_for_partition(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/botocore/regions.py", line 277, in _endpoint_for_partition
    raise NoRegionError()
botocore.exceptions.NoRegionError: You must specify a region.

Googling the first thing that comes up is AWS related, as the error is (https://stackoverflow.com/questions/40377662/boto3-client-noregionerror-you-must-specify-a-region-error-only-sometimes)

I've never really used Python so maybe it's me doing something wrong, forgive if me so... I've tried defining the environment variables in an .env file at the root of my project, at the root of the json_translate folder, in my zhsrc, so far nothing has worked.

API key is definetely valid aswell

DEEPL_API_ENDPOINT environment variable not working.

I can't get the DEEPL_API_ENDPOINT environment variable to work. I upgraded to the paid version of DeepL and I am unable to get the environment variable to work for the end point.

However, I opened the setting.py file and replaced https://api-free.deepl.com/v2/translate with https://api.deepl.com/v2/translate and I was able to get it to work.

Here is what my .env file looks like

DEEPL_API_ENDPOINT=https://api.deepl.com/v2/translate
DEEPL_AUTH_KEY=XXXXX
SLEEP_BETWEEN_API_CALLS=0.01
INDENTATION_DEFAULT=2
ENCODING=utf-8

Let me know if there is any more information I can provide.

boto3 installation required

Hey, cool project! Would be good to let people know that they also have to pip install boto3 for this to work.

Variables in the target language

The script also sets variables in the target language, e.g. :number words -> then :nummer words. But the result should be :number wrote.

AttributeError: 'str' object has no attribute '_accessor'

I tried both on MacOS and on VPS running Ubuntu 22.04, I get the same result:

json_translate deepl data/recipes_aeropress.json fr
Traceback (most recent call last):
File "/usr/local/bin/json_translate", line 8, in
sys.exit(main())
File "/usr/local/lib/python3.10/dist-packages/json_translate/commands.py", line 36, in main
data_to_translate = get_data_to_translate(
File "/usr/local/lib/python3.10/dist-packages/json_translate/files.py", line 134, in get_data_to_translate
with Path.open(input_file, "r", encoding=encoding) as file:
File "/usr/lib/python3.10/pathlib.py", line 1119, in open
return self._accessor.open(self, mode, buffering, encoding, errors,
AttributeError: 'str' object has no attribute '_accessor'

HTTP Error 403: Forbidden

Hello! Thanks for fixing #28, I'm no longer having this error, however, now there's another one:
json_translate deepl files/recipes_wilfa.json RU
Traceback (most recent call last):
File "/opt/homebrew/bin/json_translate", line 8, in
sys.exit(main())
File "/opt/homebrew/lib/python3.10/site-packages/json_translate/commands.py", line 51, in main
results = translator.translate(
File "/opt/homebrew/lib/python3.10/site-packages/json_translate/translators/base.py", line 54, in translate
return self._iterate_over_keys(data)
File "/opt/homebrew/lib/python3.10/site-packages/json_translate/translators/base.py", line 68, in _iterate_over_keys
return [self._iterate_over_keys(value) for value in data]
File "/opt/homebrew/lib/python3.10/site-packages/json_translate/translators/base.py", line 68, in
return [self._iterate_over_keys(value) for value in data]
File "/opt/homebrew/lib/python3.10/site-packages/json_translate/translators/base.py", line 64, in _iterate_over_keys
return self._get_dict_iteration(data)
File "/opt/homebrew/lib/python3.10/site-packages/json_translate/translators/base.py", line 86, in _get_dict_iteration
result[key] = self._iterate_over_keys(value)
File "/opt/homebrew/lib/python3.10/site-packages/json_translate/translators/base.py", line 72, in _iterate_over_keys
return self._get_string_iteration(data)
File "/opt/homebrew/lib/python3.10/site-packages/json_translate/translators/base.py", line 100, in _get_string_iteration
result = self.translate_string(text)
File "/opt/homebrew/lib/python3.10/site-packages/json_translate/translators/deepl.py", line 43, in translate_string
response = request.urlopen(req) # nosec
File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 216, in urlopen
return opener.open(url, data, timeout)
File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 525, in open
response = meth(req, response)
File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 634, in http_response
response = self.parent.error(
File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 563, in error
return self._call_chain(*args)
File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 496, in _call_chain
result = func(*args)
File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 643, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

Encoding Format

A way to select the encoding. I just have the issue that I translate certain characters such as ae, etc. and they are then displayed to me like this: �

unable to get local issuer certificate (_ssl.c:997)

json_translate deepl locales/en.json ES
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 1348, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1282, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1328, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1277, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1037, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 975, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1454, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 513, in wrap_socket
    return self.sslsocket_class._create(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1071, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1342, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/bin/json_translate", line 8, in <module>
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/commands.py", line 51, in main
    results = translator.translate(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 54, in translate
    return self._iterate_over_keys(data)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 64, in _iterate_over_keys
    return self._get_dict_iteration(data)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 86, in _get_dict_iteration
    result[key] = self._iterate_over_keys(value)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 64, in _iterate_over_keys
    return self._get_dict_iteration(data)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 86, in _get_dict_iteration
    result[key] = self._iterate_over_keys(value)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 64, in _iterate_over_keys
    return self._get_dict_iteration(data)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 86, in _get_dict_iteration
    result[key] = self._iterate_over_keys(value)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 72, in _iterate_over_keys
    return self._get_string_iteration(data)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 100, in _get_string_iteration
    result = self.translate_string(text)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/deepl.py", line 43, in translate_string
    response = request.urlopen(req)  # nosec
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 519, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 536, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 496, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 1391, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 1351, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>
❯ json_translate deepl locales/en.json ES
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 1348, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1282, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1328, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1277, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1037, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 975, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1454, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 513, in wrap_socket
    return self.sslsocket_class._create(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1071, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1342, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/bin/json_translate", line 8, in <module>
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/commands.py", line 51, in main
    results = translator.translate(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 54, in translate
    return self._iterate_over_keys(data)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 64, in _iterate_over_keys
    return self._get_dict_iteration(data)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 86, in _get_dict_iteration
    result[key] = self._iterate_over_keys(value)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 64, in _iterate_over_keys
    return self._get_dict_iteration(data)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 86, in _get_dict_iteration
    result[key] = self._iterate_over_keys(value)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 64, in _iterate_over_keys
    return self._get_dict_iteration(data)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 86, in _get_dict_iteration
    result[key] = self._iterate_over_keys(value)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 72, in _iterate_over_keys
    return self._get_string_iteration(data)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 100, in _get_string_iteration
    result = self.translate_string(text)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/deepl.py", line 43, in translate_string
    response = request.urlopen(req)  # nosec
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 519, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 536, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 496, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 1391, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 1351, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>
❯ json_translate deepl locales/en.json DE
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 1348, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1282, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1328, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1277, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1037, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 975, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1454, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 513, in wrap_socket
    return self.sslsocket_class._create(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1071, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1342, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/bin/json_translate", line 8, in <module>
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/commands.py", line 51, in main
    results = translator.translate(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 54, in translate
    return self._iterate_over_keys(data)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 64, in _iterate_over_keys
    return self._get_dict_iteration(data)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 86, in _get_dict_iteration
    result[key] = self._iterate_over_keys(value)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 64, in _iterate_over_keys
    return self._get_dict_iteration(data)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 86, in _get_dict_iteration
    result[key] = self._iterate_over_keys(value)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 64, in _iterate_over_keys
    return self._get_dict_iteration(data)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 86, in _get_dict_iteration
    result[key] = self._iterate_over_keys(value)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 72, in _iterate_over_keys
    return self._get_string_iteration(data)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/base.py", line 100, in _get_string_iteration
    result = self.translate_string(text)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/json_translate/translators/deepl.py", line 43, in translate_string
    response = request.urlopen(req)  # nosec
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 519, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 536, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 496, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 1391, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 1351, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>

Tool does not translate data in arrays

Hello,

I need to translate a big json file with a lot of arrays. But the tool only translate the text outside the arrays.

{ "locale": "de", "questions": [ { "question": "Was versteht man unter defensivem Fahren?", "possibleAnswers": [ { "text": "Nicht auf dem eigenen Recht bestehen", "isCorrect": true }, { "text": "Mit Fehlern anderer rechnen", "isCorrect": true }, { "text": "Vorsorglich an jeder Kreuzung anhalten", "isCorrect": false } ] },

Only "de" get translated. It is not possible for Jsoniter to parse arrays? Is there a workaround?

Thanks!

HTTP Error 400: Bad Request

Hi!

I'm trying to use it from osx.

  1. Clone the repo
  2. pip3 install -r requirements.txt
  3. vim .env (DEEPL_AUTH_KEY=XXXXXX)
  4. python3 main.py ~/git/repo/src/i18n/es.json --locale SW --output sw.json
File sw.json already exists. Do you want to override it? [Y/N] y
Traceback (most recent call last):
  File "~/git/json-deepl-translate/main.py", line 306, in <module>
    main()
  File "~/git/json-deepl-translate/main.py", line 299, in main
    results = get_strings_from_file(
  File "~/git/json-deepl-translate/main.py", line 113, in get_strings_from_file
    return iterate_translate(
  File "~/git/json-deepl-translate/main.py", line 138, in iterate_translate
    res[key] = iterate_translate(value, target_locale, sleep, skip)
  File "~/git/json-deepl-translate/main.py", line 150, in iterate_translate
    return translate_string(data, target_locale, sleep)
  File "~/git/json-deepl-translate/main.py", line 194, in translate_string
    response = request.urlopen(req)
  File "/usr/local/Cellar/[email protected]/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/Cellar/[email protected]/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 525, in open
    response = meth(req, response)
  File "/usr/local/Cellar/[email protected]/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 634, in http_response
    response = self.parent.error(
  File "/usr/local/Cellar/[email protected]/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 563, in error
    return self._call_chain(*args)
  File "/usr/local/Cellar/[email protected]/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 496, in _call_chain
    result = func(*args)
  File "/usr/local/Cellar/[email protected]/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 643, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

After update to las python 3.11

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 1348, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 1282, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 1328, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 1277, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 1037, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 975, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/http/client.py", line 1454, in connect
    self.sock = self._context.wrap_socket(self.sock,
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 517, in wrap_socket
    return self.sslsocket_class._create(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 1075, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ssl.py", line 1346, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "~/git/json-deepl-translate/main.py", line 306, in <module>
    main()
  File "~/git/json-deepl-translate/main.py", line 299, in main
    results = get_strings_from_file(
              ^^^^^^^^^^^^^^^^^^^^^^
  File "~/git/json-deepl-translate/main.py", line 113, in get_strings_from_file
    return iterate_translate(
           ^^^^^^^^^^^^^^^^^^
  File "~/git/json-deepl-translate/main.py", line 138, in iterate_translate
    res[key] = iterate_translate(value, target_locale, sleep, skip)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/git/json-deepl-translate/main.py", line 150, in iterate_translate
    return translate_string(data, target_locale, sleep)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/git/json-deepl-translate/main.py", line 194, in translate_string
    response = request.urlopen(req)
               ^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 519, in open
    response = self._open(req, data)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 536, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 496, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 1391, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 1351, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)>

After run /Applications/Python\ 3.11/Install\ Certificates.command the 400 appears again

Traceback (most recent call last):
  File "~/git/json-deepl-translate/main.py", line 306, in <module>
    main()
  File "~/git/json-deepl-translate/main.py", line 299, in main
    results = get_strings_from_file(
              ^^^^^^^^^^^^^^^^^^^^^^
  File "~/git/json-deepl-translate/main.py", line 113, in get_strings_from_file
    return iterate_translate(
           ^^^^^^^^^^^^^^^^^^
  File "~/git/json-deepl-translate/main.py", line 138, in iterate_translate
    res[key] = iterate_translate(value, target_locale, sleep, skip)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/git/json-deepl-translate/main.py", line 150, in iterate_translate
    return translate_string(data, target_locale, sleep)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/git/json-deepl-translate/main.py", line 194, in translate_string
    response = request.urlopen(req)
               ^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 525, in open
    response = meth(req, response)
               ^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 634, in http_response
    response = self.parent.error(
               ^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 563, in error
    return self._call_chain(*args)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 496, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 643, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

I add data = parse.quote(data)as:

   data = parse.quote(data)
    req = request.Request(DEEPL_API_ENDPOINT, data=data)
    response = request.urlopen(req)

and the result

Traceback (most recent call last):
  File "~/git/json-deepl-translate/main.py", line 307, in <module>
    main()
  File "~/git/json-deepl-translate/main.py", line 300, in main
    results = get_strings_from_file(
              ^^^^^^^^^^^^^^^^^^^^^^
  File "~/git/json-deepl-translate/main.py", line 113, in get_strings_from_file
    return iterate_translate(
           ^^^^^^^^^^^^^^^^^^
  File "~/git/json-deepl-translate/main.py", line 138, in iterate_translate
    res[key] = iterate_translate(value, target_locale, sleep, skip)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/git/json-deepl-translate/main.py", line 150, in iterate_translate
    return translate_string(data, target_locale, sleep)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/git/json-deepl-translate/main.py", line 195, in translate_string
    response = request.urlopen(req)
               ^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 516, in open
    req = meth(req)
          ^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/request.py", line 1279, in do_request_
    raise TypeError(msg)
TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.
``

[OSX] TypeError: argument of type 'NoneType' is not iterable

Hi!

I'm on Mac, and I try to use this tool (thanks!)

  1. Clone repo from GitHub
  2. pip3 install -r requirements.txt
  3. vim .env (and write my API_KEY from DeepL free)
  4. python3 -m unittest discover --> Ok
  5. python3 main.py ~/git/myApp/src/i18n/es.json --locale en --output en.json
Traceback (most recent call last):
  File "/Users/sbellver/git/json-deepl-translate/main.py", line 262, in <module>
    main()
  File "/Users/sbellver/git/json-deepl-translate/main.py", line 255, in main
    results = get_strings_from_file(
  File "/Users/sbellver/git/json-deepl-translate/main.py", line 87, in get_strings_from_file
    return iterate_translate(
  File "/Users/sbellver/git/json-deepl-translate/main.py", line 108, in iterate_translate
    if key in skip:
TypeError: argument of type 'NoneType' is not iterable

Try with others like
python3 main.py ~/git/myApp/src/i18n/es.json --locale en --output en.json --indent 4 --sleep 0.5
with same result

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.