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

How to conditionally use route translator #75

Closed
bricesanchez opened this issue Nov 25, 2014 · 1 comment
Closed

How to conditionally use route translator #75

bricesanchez opened this issue Nov 25, 2014 · 1 comment

Comments

@bricesanchez
Copy link

Hello all!

I work with RefineryCMS (https://github.com/refinery/refinerycms) and i would like to use your gem in order to translate some refinerycms routes, see my PR on this project :
refinery/refinerycms-i18n#51

Is there another way to use conditionally localized method than :

if defined? localized 
  localized do
    routes
  end
else
  routes
end

I do this because for some english countries, they doesn't want to load localized routes if they doesn't use refinerycms-i18n.

@enriclluelles
Copy link
Owner

Right now, from the top off my head I can't think of another way to achieve this.

Of course you could encapsulate that into something like this:

def try_localized(&block)
  if defined?(localized)
    localized(&block)
  else
    block.call
  end
end

and then use like you would with localized. To decide whether that little abstraction worth it or not is for you to decide 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants