Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@johnnyshields
Created February 18, 2017 11:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnnyshields/98a695df51b1e99f3593579d3c9a3fd1 to your computer and use it in GitHub Desktop.
Save johnnyshields/98a695df51b1e99f3593579d3c9a3fd1 to your computer and use it in GitHub Desktop.
def current_path_for_locale(loc = I18n.locale, is_link = true)
return 'javascript: void(0);' if is_link && I18n.locale == loc
url_regex = /\A\/(?:(#{I18n.available_locales.join('|')})\/)?/
current_page.url.gsub(url_regex, '').blank? ?
home_for_locale(loc) :
current_page.url.gsub(url_regex, root_for_locale(loc))
end
def path_for_locale(path, loc = I18n.locale)
root_for_locale(loc) + path
end
def home_for_locale(loc = I18n.locale)
root_for_locale(loc)
end
def root_for_locale(loc = I18n.locale)
loc == :ja ? '/' : "/#{loc}/"
end
@iwarner
Copy link

iwarner commented Mar 17, 2017

You can get the root with :
= extensions[:i18n].options[:mount_at_root]

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