Skip to content
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

Extend and configure translation class. #421

Closed
phlegx opened this issue Aug 3, 2020 · 2 comments
Closed

Extend and configure translation class. #421

phlegx opened this issue Aug 3, 2020 · 2 comments

Comments

@phlegx
Copy link

phlegx commented Aug 3, 2020

I want to extend the translation class to work with some other plugins. Where can I find a HowTo or can someone help me to start?

I use the table backend and I need to include some things.

@shioyama
Copy link
Owner

shioyama commented Aug 6, 2020

Thanks for reaching out! If I understand correctly, you'd like to extend the translation class for your model class to work with other (non-Mobility) plugins?

Here's where it's defined (on the master branch):

translation_class =
if self.const_defined?(subclass_name, false)
const_get(subclass_name, false)
else
const_set(subclass_name, Class.new(Mobility::ActiveRecord::ModelTranslation))
end

If your model name is Post, it defines a constant Post::Translation which you can simply modify:

class Post::Translation
  # .. your custom stuff
end

It's a bit more tricky if you want to modify the translation class for all models. Mobility has a class, Mobility::ActiveRecord::ModelTranslation which it subclasses, so if you wanted to change the translation class for all models you could modify that one:

class Mobility::ActiveRecord::ModelTranslation
  # ... your custom stuff
end

Put that in an initializer and it should work.

@shioyama
Copy link
Owner

shioyama commented Aug 6, 2020

Mind you, the namespace of Mobility::ActiveRecord::ModelTranslation will probably change in v1.0, in part to fix #258.

@phlegx phlegx closed this as completed Aug 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants