-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add #translations, #init_translations and #intialized? #97
Conversation
@vipera Thanks for the contribution. |
It would be great to have this, thanks. I just experienced the issue right now. I'll keep JS translations in YAML for the moment. |
I will try to review it next week, so potentially in 1-2 weeks, it should be merged. |
I just tested @vipera repo and it works for me. In case It can helps : Before (PR) I had to add these block in module I18n
def self.reload!
I18n::JS.backend.reload!
super
end
end and I18n::JS.backend = I18n.backend And the full config : # frozen_string_literal: true
module I18n
def self.reload!
I18n::JS.backend.reload!
super
end
end
require "i18n/backend/active_record"
I18n::JS.backend = I18n.backend
I18n.backend = I18n::Backend::ActiveRecord.new
I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Memoize)
I18n::Backend::Simple.send(:include, I18n::Backend::Memoize)
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
# Populate missing translations to database
I18n::Backend::ActiveRecord.send(:include, I18n::Backend::ActiveRecord::Missing)
I18n.backend = I18n::Backend::Chain.new(I18n.backend, I18n::Backend::Simple.new)
I18n::Backend::ActiveRecord.configure do |config|
config.cleanup_with_destroy = true # defaults to false
end With the PR, this config works : # frozen_string_literal: true
require "i18n/backend/active_record"
I18n.backend = I18n::Backend::ActiveRecord.new
I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Memoize)
I18n::Backend::Simple.send(:include, I18n::Backend::Memoize)
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
# Populate missing translations to database
I18n::Backend::ActiveRecord.send(:include, I18n::Backend::ActiveRecord::Missing)
I18n.backend = I18n::Backend::Chain.new(I18n.backend, I18n::Backend::Simple.new)
I18n::Backend::ActiveRecord.configure do |config|
config.cleanup_with_destroy = true # defaults to false
end |
Hi @Timsly, any news for the merge ? Thanks |
796792e
to
9d3ab9e
Compare
9d3ab9e
to
0d01482
Compare
For compatibility with i18n-js, these methods are required to build a complete representation of all translations in the backend.
0d01482
to
3cd993e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@vipera Thanks for the contribution! |
In my case, it did work when using:
But it didn't exported the translations from the database when using:
|
I guess you need to debug how |
Thanks Tim! I just mentioned it here, for people who read the conversation and maybe run into the same problem 👌 |
I'm using fnando/i18n-js in my project, which basically calls
#translations
to fetch an entire hash of translations to output in JavaScript. Their project documents that it is incompatible with anything other than a Simple backend, but it actually only requires a couple of hook methods to get working which I have added in this patch. I think that a number of users would benefit from being able to get translations from the ActiveRecord backend into the frontend.The methods are unused inside the project itself, but I've added some tests to cover their expected behaviour.
Thanks for taking the time to take a look at this :)