Created
October 10, 2011 18:23
-
-
Save tdreyno/1276089 to your computer and use it in GitHub Desktop.
Middleman localization idea
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
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 |
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
// data/lang_en.yml | |
title: "Hello" |
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
// data/lang_es.yml | |
title: "Hola" |
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
<!-- 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