Google translate integration for threads and comments
eternaltyro opened this issue · comments
I can't seem to find a way to integrate Google Translate and it's certainly not done by default. Are there some special steps that I need to follow?
https://github.com/googleapis/google-cloud-ruby is the starting point to learn how to configure a google cloud account and generate a translation credentials json file.
To enable google translate, you just need a TRANSLATE_CREDENTIALS environment variable, with the content of that json file as a string. Once this is present the translation features will show up when they can be used.
The json file looks like what you can see on this page: https://cloud.google.com/iam/docs/creating-managing-service-account-keys
I hope that's enough to help you on your way, please let me know how you get on.
Thanks. I'm using loomio-deploy for my deployment and I'm assuming that the environment variable should be set for the loomio-app
container. Is my assumption right?
yes, that looks right. That should work. If you write a comment in another language it should bring up the translate button. it might need to be a sentence or two long
Hmmm, that doesn't work for some reason. No requests are being made to the API either:
What could I be doing wrong? Is there a specific way service accounts need to be configured? I can see that the service account has owner
permission to the Google Cloud project and Translation API is enabled.
Anything to do on the app?
docker-compose config
does not list the TRANSLATE_CREDENTIALS
variable
I think docker compose can only have one of env_file
and environment
. I could be wrong though.
I set TRANSLATE_CREDENTIALS
in the environment key and it seems to have worked partially. I see the google translate icon but clicking on it does nothing.
You need to remove the containers, not just stop them, for new environment variables to be taken in. So docker-compose down and up are required, not just stop and start.
Yes, I've been doing this. But it still doesn't take the envvars in the .env
file.
If the translate button is appearing, then the ENV is detected and the in-app language detection is working, the problem is with your credentials and google translate is not translating for you. Have a look at your logs with docker-compose logs -f and see if there is anything in there.
Yes, you are correct. I have a problem with the way the JSON string is placed in the environment variable. I'm not sure how to make docker-compose read the contents of a file as value to an ENVVAR. Even though the string I sent was a valid JSON, there are issues with serializing it.
So the way I see it, there are three options that I can try
Option 1. Use one of the multi-line formats like so
TRANSLATE_CREDENTIALS: |
{
"JSON": "STRING",
...
}
or
TRANSlATE_CREDENTIALS: >
{
"JSON": "STRING",
...
}
Option 2: Mount the JSON file as a volume and refer to it
Option 3: Pass it as a secret with value defined from file.
Can we add this to the documentation too, please?