Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Consider adding auto_translate filter #2

Closed
ptrin opened this issue Jun 1, 2012 · 1 comment
Closed

Consider adding auto_translate filter #2

ptrin opened this issue Jun 1, 2012 · 1 comment

Comments

@ptrin
Copy link

ptrin commented Jun 1, 2012

Thanks for the excellent localization plugin.

When I was first familiarizing myself with how to use it, I felt that the liquid filter was kind of clumsy because it was necessary to provide each of the language variables individually. I thought that it would be better to be able to pass one variable and let the plugin decide which translation to use based on the filename. I'm no Ruby coder, but I messed around and came up with this and it seems to work:

def auto_translate(*translations)
    if !translations[0][lang].nil?
        translations[0][lang]
    else
        translations[0]["en"]
    end
end

alias_method :at, :auto_translate

I structure my language variables in my front matter like so:

copy:
    header:
        en: "blah blah blah"
        fr: "yadda yadda yadda"

Then the template is much cleaner:

<h1>{{ copy.header | at }}</h1>
@blackwinter
Copy link
Contributor

hey, great idea! what about amending translate_lang (and by extension translate) to accept either an array or a hash? this would give you the same syntax, but you'd still use the same method t.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants