rubyatscale / packs-rails

packs-rails establishes and implements a set of conventions for splitting up large monoliths.
MIT License
268 stars 26 forks source link

Add translations to packs #57

Closed matiaseche closed 7 months ago

matiaseche commented 1 year ago

Hi! I am having an issue with my translations inside my pack.

I have a pack with some attribute translations inside packs/my_pack/config/locales/models/entity.rb. The only way I have managed to make it work is adding the following line inside config/application.rb:

config.i18n.load_path += Dir[Rails.root.join('packs', '**', 'config', 'locales', '**', '*.yml').to_s]

This looks like something that should be done inside the gem, doesn't it? I managed to make it work adding the following to the gem:

# lib/packs/rails/integrations/rails.rb
...
def inject_paths
  Packs.all.reject(&:is_gem?).each do |pack|
    Packs::Rails.config.paths.each do |path|
      @app.paths[path] << pack.relative_path.join(path).to_s
    end
  end
  i18n_translations
end

private

def i18n_translations
  if @app.config.respond_to?(:i18n)
    @app.config.i18n.load_path += Dir[::Rails.root.join('packs', '**', 'config', 'locales', '**', '*.yml').to_s]
  end
end

Is this something that should be added or not? If it is I can create a PR :smile:

TastyPi commented 1 year ago

With zero extra config, you should be able to put files under packs/my_pack/config/locales like you would with the standard config/locales. packs-rails adds pack paths to config.paths["config/locales"], which should be enough to get the files working.

alexevanczuk commented 1 year ago

Thank you @TastyPi for the comment. @matiaseche , can you confirm if that worked for you? If not, do you think you'd be able to write a test case (as a PR or branch) that fails and replicates the issue?

matiaseche commented 1 year ago

I have a suspicion that this occurs in Rails 6.x, but I'm not sure. I will try to replicate this in an isolated project later

alexevanczuk commented 1 year ago

Hey @matiaseche were you able to replicate this issue?

matiaseche commented 1 year ago

Hey @alexevanczuk, unfortunately I haven't had the time to try and replicate this on an isolated environment. I might be able to try today though