GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
We just added exists? to check if a certain key exists in the translations. Also, there was a typo in test/i18n_test.rb. Both in separate commits. :)
"given" instead of "givan" in /test/i18n_test
Add exists? to check if a certain key exists in the translations
+1 on idea (much needed), but need a better method name
+1 on the idea but the implementation needs to be improved.
Although I18n::Backend::Base implements lookup(), lookup() is not part of the API required for backends to implement, so we cannot rely on it. Instead, we can implement exists?() in I18n::Backend::Base that calls lookup() as you did and I18n.exists? would simply delegate to it. This is different because someone would still be able to implement exists?() without being forced to implement lookup.
Following this implementation, we need to add specific tests to the backend as well. Here is a good candidate to put them:
This way we will be able to ensure that all backends will pass the exists?() specification!
+1 ... I just had to write my own method to do this!
+1 - This would be very useful.
My dirty workaround: t("translation_key", :default => 0) != 0
t("translation_key", :default => 0) != 0
I was just googling for this again, and found my own workaround... so I decided it was time to submit an updated pull request 😄
@josevalim, could you please take a look at #182 and let me know if I've implemented your suggestions correctly? Thanks!
bump - If you have time, please take a look at #182 and let me know if I need to make any changes
Merge pull request #182 from ndbroadbent/exists
Updated #69 - Add exists? to check if a certain key exists in the translations