Should be able to localize individual components in paths/url section
tdreyno opened this issue · comments
es:
paths:
hello: "hola"
mister: "senor"
/hello/mister.html -> /hola/senor.html
Big thumbs up for this
We do this with the existing 2.x version of MiddleMan using the config file here: https://github.com/agamz/FindBigMail-old/blob/master/config.rb. Note, I don't think this fully reflects the latest middleman-i18n goodness, but hopefully its enough to give you an idea.
The relevant parts are:
I18n.load_path += Dir[ File.join(Dir.getwd, 'locale', '*.{rb,yml}') ]
langs = Dir["locale/*.yml"].map { |file| File.basename(file).gsub(".yml", "") }
files = Dir["source/localizable/**"]
langs.each do |lang|
I18n.locale = lang
files.each do |file|
src = file.split("source/").last.gsub(".haml", "")
page_id = File.basename(src, File.extname(src))
new_page = "/" + src.gsub("localizable", lang).
gsub(page_id, I18n.t("paths.#{page_id}", :default => page_id))
page new_page, :proxy => src, :ignore => true do
I18n.locale = lang
@lang = lang
@page_id = page_id
end
end
end
We have a helper to simplify the pages themselves:
helpers do
def path(page)
t("paths.#{page}")
end
end
Then we use path("hello")
in our source files and it does the right thing in the generated files.
i18n is now built in to 3.0, feel free to transfer the issue if still applicable.
@karlfreeman I asked on the forum if there's a way to accomplish this on the current version of Middleman:
http://forum.middlemanapp.com/t/multilingual-sub-paths/1061
Basically we're trying to make, with no luck:
(en) services/painting
(es) servicios/pintura
Do you have any good idea on doing this?
@demogar Sorry for the delay (and lack of answer :(). Do you mind transferring your issue over to Middleman which should give it a bit more visibility.