Skip to content

Instantly share code, notes, and snippets.

@tdreyno
Created October 10, 2011 18:23
Show Gist options
  • Save tdreyno/1276089 to your computer and use it in GitHub Desktop.
Save tdreyno/1276089 to your computer and use it in GitHub Desktop.
Middleman localization idea
langs = Dir["data/lang_*.yml"].map { |file| File.basename(file).gsub("lang_", "") }
# Option A, file all files in a folder, make them all localized
Dir["source/localizable/**"].each do |file|
# Convert source/localizable/template.html.erb to localizable/template.html
path = file.split("source/").last.gsub(".erb", "")
langs.each do |lang|
page path.gsub("localizable", lang), :proxy => path, :ignore => true do
@lang = lang
end
end
end
# Options B, store all the path mappings in a data file (paths.yml or something)
data.paths do |lang|
lang.each do |to, from|
page to, :proxy => from, :ignore => true do
@lang = lang
end
end
end
// data/lang_en.yml
title: "Hello"
// data/lang_es.yml
title: "Hola"
<!-- source/localizable/template.html.erb -->
<title><%= data[@lang].title %></title>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment