New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to make a multiple language site with Middle Man? #1144

Closed
PrideChung opened this Issue Jan 3, 2014 · 6 comments

Comments

Projects
None yet
4 participants
@PrideChung
Copy link

PrideChung commented Jan 3, 2014

Hi, everyone

I'm creating my tech blog with Middle Man, and kind of confused. My goal is to create a multiple language site with localized contents, not only the navigation bar and the footer.

I'm expecting the URLs would be something like these:

mysite.com/2014/1/4/i-love-middle-man => Default language
mysite.com/en/2014/1/4/i-love-middle-man => English translation
mysite.com/zh/2014/1/4/i-love-middle-man => Chinese translation

And the RSS feed need to be generated separately.
mysite.com/zh/feed.xml => For Chinese translation
mysite.com/en/feed.xml => For English translation

And the same goes for the About and Contact pages, this part is pretty easy though.

I already know the multiple site trick (use ln -S command to create symbolic link for reusable files, and use different subdomains for each translation) but I want to host the site on GitHub pages and one user can has only one site, so this trick won't work.

I've digged up some old issues in Middle Man's repo, but they seems not working for new version anymore.

Could you kindly point me in the right direction? Many thanks.

@tdreyno

This comment has been minimized.

Copy link
Member

tdreyno commented Jan 3, 2014

@tdreyno tdreyno closed this Jan 3, 2014

@lolmaus

This comment has been minimized.

Copy link
Contributor

lolmaus commented Jan 3, 2014

Hey @PrideChung, i've got through same difficulties recently.

First of all, you should understand that middleman and middleman-blog have separate configuration for i18n. Middleman's page sources should be placed under /source/localizable/ and middleman-blog's pages should not.

In addition to @tdreyno's link, also read this: http://middlemanapp.com/basics/blogging/#toc_15

middleman-blog does not support mount_as_root, so in order to have no language prefix for the default character, you'll have to create a separate blog configuration. Something like this:

activate :blog do |blog|
  blog.name = 'blog_default_lang'
  blog.sources = "blog/en/{year}-{month}-{day}-{title}.html"
  blog.permalink = "{year}/{month}/{day}/{title}.html"
end

activate :blog do |blog|
  blog.name = 'blog_non_default_langs'
  blog.sources = "blog/{lang}/{year}-{month}-{day}-{title}.html"
  blog.permalink = "{lang}/{year}/{month}/{day}/{title}.html"
end

Note that there's a bug with {lang} that has recently been fixed but hasn't been released yet. If you have a fixed set of languages, i suggest that you don't use {lang} at all and instead create a separate blog configuration for each language.

If your set of langauges is arbitrary, then you'll have to use a Github version of middleman-blog until next release. Provide a Github repo link instead of a version number in your Gemfile.

@PrideChung

This comment has been minimized.

Copy link
Author

PrideChung commented Jan 4, 2014

@lolmaus Thanks! Your solution works perfectly. About the localized RSS feeds, here's my solution:

I created two blogs like this:

activate :blog do |blog|
  blog.name = 'zh' #must name the blog with an unique id
  blog.sources = "blog/zh/{year}-{month}-{day}-{title}.html"
  blog.permalink = "{year}/{month}/{day}/{title}.html"
  blog.default_extension = ".md"
  blog.layout = "layouts/_article"
end

activate :blog do |blog|
  blog.name = "en"
  blog.sources = "blog/en/{year}-{month}-{day}-{title}.html"
  blog.permalink = "en/{year}/{month}/{day}/{title}.html"
  blog.layout = "layouts/_article"
  blog.default_extension = ".md"
end

In config.rb, replace this line page "feed.xml", :layout => flase with these two lines (or more if you need more translations)

page "feed-zh.xml", :layout => false 
page "feed-en.xml", :layout => false

Put feed-zh.xml.builder and feed-en.xml.builder in your source folder, my feed-zh.xml.builder looks like this:

xml.instruct!
xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do

 blog = blog('en')  # this is the key, you have to specify which blog to use, put it at the top. The same goes for other translations.

  site_url = "mysite.com"
  xml.title "mysite"
  xml.subtitle "Blog subtitle"
  xml.id URI.join(site_url, blog.options.prefix.to_s)
  xml.link "href" => URI.join(site_url, blog.options.prefix.to_s)
  xml.link "href" => URI.join(site_url, current_page.path), "rel" => "self"
  xml.updated(blog.articles.first.date.to_time.iso8601) unless blog.articles.empty?
  xml.author { xml.name "Pride Chung" }

  blog.articles[0..5].each do |article|
    xml.entry do
      xml.title article.title
      xml.link "rel" => "alternate", "href" => URI.join(site_url, article.url)
      xml.id URI.join(site_url, article.url)
      xml.published article.date.to_time.iso8601
      xml.updated File.mtime(article.source_file).iso8601
      xml.author { xml.name "Pride Chung" }
      xml.summary article.summary, "type" => "html"
      xml.content article.body, "type" => "html"
    end
  end
end

That's it, thank you again.

@waiting-for-dev

This comment has been minimized.

Copy link

waiting-for-dev commented Dec 29, 2014

Thanks @lolmaus & @PrideChung , this is the best resource I have found about this issue... looking forward for new i18n api to get stuff like that resolved :)

@tdreyno

This comment has been minimized.

Copy link
Member

tdreyno commented Dec 30, 2014

@waiting-for-dev We'll definitely need to heavily test the new i18n stuff. Anyone opinions you have on the subject are very welcome. Hoping to get it right for v4.

@waiting-for-dev

This comment has been minimized.

Copy link

waiting-for-dev commented Dec 30, 2014

great @tdreyno , count on me

@sn3p sn3p referenced this issue Jul 31, 2015

Closed

[WIP] Localize Blog #87

3 of 6 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment