Skip to content
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

Meta tags using i18n locale files #83

Open
mtrolle opened this issue Mar 12, 2015 · 1 comment · May be fixed by #84
Open

Meta tags using i18n locale files #83

mtrolle opened this issue Mar 12, 2015 · 1 comment · May be fixed by #84

Comments

@mtrolle
Copy link

mtrolle commented Mar 12, 2015

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
Copy link
Author

mtrolle commented Mar 13, 2015

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.

mtrolle added a commit to mtrolle/meta-tags that referenced this issue Mar 13, 2015
Fixed kpumuk#83 creating support for adding meta tags via locales in the
format:
en:
  meta_tags:
    `controller`:
      `action`:
        title: My title
etc.

I have not created any tests as I’m quite frankly not sure how to write
them using locales data.
@mtrolle mtrolle linked a pull request Mar 13, 2015 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant