Created
February 18, 2017 11:38
-
-
Save johnnyshields/98a695df51b1e99f3593579d3c9a3fd1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can get the root with :
= extensions[:i18n].options[:mount_at_root]