Skip to content

Instantly share code, notes, and snippets.

@bastienrobert
Created September 6, 2017 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bastienrobert/43c53f27763e56b231982b4f575a2c84 to your computer and use it in GitHub Desktop.
Save bastienrobert/43c53f27763e56b231982b4f575a2c84 to your computer and use it in GitHub Desktop.
URL helper for middleman : translate the same page in another language
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