Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.

Added Caching #4

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Added Caching #4

wants to merge 6 commits into from

Conversation

serafdev
Copy link

Here I added Caching to the translation script. First the output files need to remain in the new tmp/ folder that I created (changed the output from /tmp/ to ./tmp/ which is root of project. You need to keep the translated files so we can reuse the translated strings. For example if you modify the base json, it will only translate the newly added keys.

Fixed a bug with Special Characters stopping the script running because of encodeURI, we now use encodeURIComponent to be able to encode special characters.

I found a bug where the Script stopped when it found a # (Specific case of special characters).

Using the encodeURIComponent instead of encodeURI solves this issue.
Here, I added a caching feature. It overrides the existing translated file, if the key already exist in the previously translated file, it doesn't make the request to the Google Translate API, instead it reuses the value. The only condition is that you keep your files in the tmp folder on the root level of the project and when you update your original JSON File it will check bot the updated JSON and updates the older translated versions with new keys and values.
@yps1978
Copy link

yps1978 commented Sep 4, 2019

Hi,

I just grabbed the changes from your PR and tested locally. It works well.
My translation files are big so definitely I needed this to avoid unnecessary calls to the API.

Thank you for your work.

@serafdev
Copy link
Author

serafdev commented Sep 5, 2019

@yps1978 Happy to contribute! Have fun coding 😄

Sent with GitHawk

@urielgolab
Copy link
Collaborator

Ohh I've just seen t his PR, and since it wans't merger to master, I'd to develope this feature for myself.

Also, i added a different way of translating string using package "google-translate-api-browser" which lets you use Google Translet without an API key.

@serafdev
Copy link
Author

serafdev commented Jun 3, 2020

Cool stuff @urielgolab I merged my caching branch to master from my fork

I think this project is dead, we might want someone to take over somehow, maybe create a new repo with the continuation of the code in it? Also we might want to consider bumping the node version

Let me know what you think

@tewen
Copy link
Owner

tewen commented Jun 3, 2020

@serafdev Nice to see some activity. I missed this years ago with the original pull request for some reason. Clearly, I haven't updated this recently. I am happy to redirect the repo to one of you, and make that clear in the README. Just let me know.

@urielgolab
Copy link
Collaborator

urielgolab commented Jun 3, 2020 via email

@tewen
Copy link
Owner

tewen commented Jun 3, 2020

Will do @urielgolab

@serafdev
Copy link
Author

serafdev commented Jun 3, 2020

@tewen hey Trevor, thank you for this code by the way! Are you able to add an open License on the main repo too? We’ll pull that on the inherited repository.

@urielgolab if you are actively working with google translates it would be better if you take care of this, I’ll be happy to continue contributing

@urielgolab
Copy link
Collaborator

urielgolab commented Jun 3, 2020 via email

@serafdev
Copy link
Author

serafdev commented Jun 3, 2020

Great, are you able to merge this one @urielgolab, I use this version of the code, and we should still be able to have both options (free and with api), we should keep that in mind!

Some cases won't work with the free version (chat bots, etc) where throughput can be high

@urielgolab
Copy link
Collaborator

urielgolab commented Jun 3, 2020 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants