Created
September 6, 2017 22:53
-
-
Save bastienrobert/43c53f27763e56b231982b4f575a2c84 to your computer and use it in GitHub Desktop.
URL helper for middleman : translate the same page in another language
This file contains 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
module URLHelper | |
def link_translate(lang) | |
return link_to data.languages.send(lang.to_s), | |
if lang === I18n.default_locale | |
config[:host] + '/' + | |
path_translate(lang) + | |
t("paths.#{current_page.data.title}", locale: lang) | |
else | |
config[:host] + '/' + | |
lang.to_s + '/' + | |
path_translate(lang) + | |
t("paths.#{current_page.data.title}", locale: lang) | |
end | |
end | |
def path_translate(lang) | |
begin | |
current_page.data.dir.map { |dir| t("paths.#{dir}", locale: lang) + '/'}.join('/') | |
rescue | |
return '' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment