Created
February 18, 2017 11:38
-
-
Save johnnyshields/98a695df51b1e99f3593579d3c9a3fd1 to your computer and use it in GitHub Desktop.
Revisions
-
johnnyshields created this gist
Feb 18, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ 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