Skip to content

Instantly share code, notes, and snippets.

@keram
Created September 11, 2012 00:21
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 keram/3695012 to your computer and use it in GitHub Desktop.
Save keram/3695012 to your computer and use it in GitHub Desktop.
Refinery::Blog::Post.class_eval do
def have_translation?
self[:body].present?
end
def body
body = self[:body]
current_lang = ::Globalize.locale
::Refinery::I18n.frontend_locales.each do |lang|
if lang != current_lang
::I18n.locale = lang
::Globalize.locale = lang
if body.blank? and self[:body].present?
url = ''
url += %Q{/#{lang}} unless lang == ::Refinery::I18n.default_frontend_locale
url += %Q{/blog/posts/#{self.slug}}
body = %Q{<p><a href="#{url}">}
body += ::I18n.t('blog_post_realeased_in_html', {
:in_lang => ::I18n.t("in_#{lang}"),
:url => url
})
body += '</a></p>'
end
end
end unless body.present?
::I18n.locale = current_lang
::Globalize.locale = current_lang
body.to_s
end
def title
title = self[:title]
current_lang = ::Globalize.locale
::Refinery::I18n.frontend_locales.each do |lang|
if lang != current_lang
::I18n.locale = lang
::Globalize.locale = lang
if title.blank? and self[:title].present?
title = self[:title]
end
end
end unless title.present?
::I18n.locale = current_lang
::Globalize.locale = current_lang
title.to_s
end
end
Refinery::Blog::PostsController.class_eval do
def show
@comment = ::Refinery::Blog::Comment.new
@canonical = refinery.url_for(:locale => Refinery::I18n.default_frontend_locale) if canonical?
@post.increment!(:access_count, 1)
respond_with (@post) do |format|
format.html { present(@post) }
format.js { render :partial => 'post', :layout => false }
end
end
protected
def canonical?
@post.present? &&
!@post.have_translation? &&
::Refinery::I18n.default_frontend_locale != ::Refinery::I18n.current_frontend_locale
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment