glebm / i18n-tasks

Manage translation and localization with static analysis, for Ruby i18n
http://glebm.github.io/i18n-tasks
MIT License
2.08k stars 264 forks source link

Request: Support for `dotenv-rails`, to load `GOOGLE_TRANSLATE_API_KEY` from `.env.development` #395

Open ndbroadbent opened 3 years ago

ndbroadbent commented 3 years ago

Hello, I use the dotenv-rails gem to define configuration vars in .env, .env.test, .env.development, etc. This doesn't seem to be working with i18n-tasks. I've set GOOGLE_TRANSLATE_API_KEY in my .env.development file, but it looks like i18n-tasks doesn't load the Rails environment, so I get this error:

$ i18n-tasks translate-missing
i18n-tasks: Set Google API key via GOOGLE_TRANSLATE_API_KEY environment variable or translation.google_translate_api_key in config/i18n-tasks.yml. Get the key at https://code.google.com/apis/console.

It would be nice if i18n-tasks could work together with dotenv-rails to load these env vars from .env files.

Also I realize that it's very difficult to maintain an open source project, so if this is too much work or no-one else wants it, then please feel free to close it. Thanks for all your work!

lorenzk commented 2 years ago

@ndbroadbent Just an idea: I recently found https://direnv.net/, which is a more general solution to the same problem and should fix your problem as well.

dssjoblom commented 2 years ago

This would be good for DeepL as well, which can't be controlled by environment variables at all.

fschwahn commented 2 years ago

you can do the following to pick up variables from dotenv:

bundle exec dotenv -f ".env.development" i18n-tasks translate-missing
glebm commented 2 years ago

This would be good for DeepL as well, which can't be controlled by environment variables at all.

https://github.com/glebm/i18n-tasks/blob/105c0f4bddebdab7a840cb55baa9be6f909adedf/lib/i18n/tasks/configuration.rb#L66-L68

dssjoblom commented 2 years ago

@glebm ok, it's been there for years, apparently :D I think this should be mentioned in the README.md though, as it's only obvious from reading the source.