kpumuk / meta-tags

Search Engine Optimization (SEO) for Ruby on Rails applications.
MIT License
2.73k stars 275 forks source link

Meta tags using i18n locale files #83

Open mtrolle opened 9 years ago

mtrolle commented 9 years ago

Has it been considered to add ability to add meta tags using i18n locale files?

E.g. in a namespace like:

en:
  meta_tags:
   [controller]:
     [action]:
       title: My locale title
       description: Foo baa

etc. ?

mtrolle commented 9 years ago

A very simple solution for this request is to paste the following code to your ApplicationController

  before_filter :read_meta_tags_from_locales

  def read_meta_tags_from_locales
    name_space = "meta_tags.#{controller_name}.#{action_name}"

    @page_title = I18n.t("#{name_space}.title") unless I18n.t("#{name_space}.title", default: '').blank?
    @page_description = I18n.t("#{name_space}.description") unless I18n.t("#{name_space}.description", default: '').blank?
    @page_keywords = I18n.t("#{name_space}.keywords") unless I18n.t("#{name_space}.keywords", default: '').blank?
  end
  protected :read_meta_tags_from_locales

This will support the locales structure given above for title, description and keywords.