Should Sinatra::Reloader reload i18n files (.yml)? #179

Closed
bmsatierf opened this Issue Nov 26, 2015 · 7 comments

Comments

Projects
None yet
5 participants
@bmsatierf

The extension Sinatra::Reloader should reload other files such as yml with translations used by the gem i18n? Here is the setup:

# Gemfile

gem 'i18n'
gem 'sinatra'
gem 'sinatra-contrib'
# my_app.rb

require "sinatra/base"
require "sinatra/reloader"

class MyApp < Sinatra::Base
  configure :development do
    register Sinatra::Reloader
  end

  configure do
    I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
    I18n.load_path = Dir[File.join(settings.root, 'config/locales', '*.yml')]
    I18n.backend.load_translations
  end

  ...
end
# config/locales/pt.yml

pt:
  hello: "Olá Sinatra"

After changing the pt.yml file, the changes would be visible only after restarting the server.

@canton7

This comment has been minimized.

Show comment
Hide comment

canton7 commented Nov 27, 2015

Can't you use also_reload to include the .yml files, see http://www.sinatrarb.com/contrib/reloader.html#label-Changing+the+Reloading+Policy ?

@bmsatierf

This comment has been minimized.

Show comment
Hide comment
@bmsatierf

bmsatierf Nov 27, 2015

Hi @canton7, thank you for the suggestion.

Before opening this issue I tried to use also_reload, however I ended up with an error while trying to require an .yml file, and then I realised that perhaps only .rb would be reloaded, but I am still not sure.

Hi @canton7, thank you for the suggestion.

Before opening this issue I tried to use also_reload, however I ended up with an error while trying to require an .yml file, and then I realised that perhaps only .rb would be reloaded, but I am still not sure.

@ireneybean

This comment has been minimized.

Show comment
Hide comment
@ireneybean

ireneybean Mar 27, 2016

I'm having the same experience, I tried using also_reload and it is fine starting up, but after changing the content in my yml file I get an error saying it can't load the file and the error message says it is looking in my home directory even though I have specified the path the same way as other also_reload files that are .rb.

I'm having the same experience, I tried using also_reload and it is fine starting up, but after changing the content in my yml file I get an error saying it can't load the file and the error message says it is looking in my home directory even though I have specified the path the same way as other also_reload files that are .rb.

@zzak

This comment has been minimized.

Show comment
Hide comment
@zzak

zzak Apr 21, 2016

Member

I think because '.yml' files aren't technically required but read from source?

It looks like, from here, that the reloaded essentially just calls require on the file after removing the element from Sinatra and removing the file from $LOADED_FEATURES.

Member

zzak commented Apr 21, 2016

I think because '.yml' files aren't technically required but read from source?

It looks like, from here, that the reloaded essentially just calls require on the file after removing the element from Sinatra and removing the file from $LOADED_FEATURES.

@stjhimy

This comment has been minimized.

Show comment
Hide comment
@stjhimy

stjhimy Apr 23, 2016

Contributor

We could add a method after_reload that would accept a block allowing the user to call I18n to update yml files or run anything he needs after the reload. What do you think @zzak ?

Contributor

stjhimy commented Apr 23, 2016

We could add a method after_reload that would accept a block allowing the user to call I18n to update yml files or run anything he needs after the reload. What do you think @zzak ?

@zzak

This comment has been minimized.

Show comment
Hide comment
@zzak

zzak Jul 7, 2016

Member

@stjhimy Sounds good to me, will you work up a patch for after_reload feature as well as documentation regarding this behavior?

Member

zzak commented Jul 7, 2016

@stjhimy Sounds good to me, will you work up a patch for after_reload feature as well as documentation regarding this behavior?

@stjhimy

This comment has been minimized.

Show comment
Hide comment
@stjhimy

stjhimy Jul 21, 2016

Contributor

@zzak yes, I'm on it.

Contributor

stjhimy commented Jul 21, 2016

@zzak yes, I'm on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment