prometheus-ev / jekyll-localization

Jekyll plugin that adds localization features to the rendering engine.
http://rdoc.info/gems/jekyll-localization
Other
68 stars 7 forks source link

undefined local variable or method page for Liquid #1

Closed rubyconvict closed 14 years ago

rubyconvict commented 14 years ago
Maruku tells you: +--------------------------------------------------------------------------- String finished while reading (break on []) already read: "page' for #Liquid::Strainer:0xa0c0828 text."
ned local variable or method `page' for # text.EOF
---------------------------------------------------------------------------
+--- Byte 100
Shown bytes [25 to 75] of 100:
>Some Liquid error: undefined local variable or method`page' for #Liquid::Strainer:0xa0c0828 text.
At line 5
header1 ================
empty
text Some Liquid error: undefined local variable or method `page' for #Liquid::Strainer:0xa0c0828 text.
empty -->
text Kilkanaście lat prowadzenia własnej firmy w branży produkcji

The problem is here. It works when I hardcode "en" in localization.rb:

def t(*translations)
  translations.flatten!

  index = Localization::LANGUAGES.index("en") #page.lang
  index && translations[index] || translations.first
end

$ cat _extensions/_plugins/ext.rb require 'jekyll/localization'

i have the same problem when i put ext.rb in MYJEKYLLAPP/_plugins.

Please fix it if you can.

My gems: jekyll (0.7.0) jekyll-localization (0.0.3) jekyll-rendering (0.0.2) jekyll_ext (0.1.2) liquid (2.2.2) maruku (0.6.0)

rubyconvict commented 14 years ago

UPDATE: My first impression was that it works when hardcoded, but I can't really figure out how this is better than just writing a separate page in another language, could you elaborate on this or give some practical example, more than this: Some {{['default', 'translation'] | t}} text. How do I mix oneliners with whole page translations?

blackwinter commented 14 years ago

Fixed filter to work with Liquid. [Closed by 3aecb613bc9c398fe28479bfbd6a053cd17a74c5]

blackwinter commented 14 years ago

sorry, the example didn't work at all because i'm not familiar with liquid by any stretch ;-) but it should be fixed now. thanks for reporting this issue!

as for the rationale: we use it for example in code or layout heavy pages where you don't want to replicate everything in another file just to translate a single word or sentence.

cheers jens

rubyconvict commented 14 years ago

Thanks. I get no error now. This makes sense. So lets say I want to translate a single word with a filter or any other way you do: {{ t: word }}

where and how syntactically do I put the translation for it? in separate yaml file, in yaml header of the translation file with .en.html extension? Sorry, but somehow I can't figure out how to do this.

blackwinter commented 14 years ago

this is how you do it: {{ 'hi' | t: 'cześć' }}. that is, 'hi' is the word you want to translate and 'cześć' is the translation. in this case you would set Localization::LANGUAGES to 'en' + 'pl' and configure the page to have either of those languages (e.g. by choosing an appropriate file extension as you mentioned).

hope that helps. i know that we are pretty short on examples and documentation ;-)

rubyconvict commented 14 years ago

I know, when I put {{ 'hi' | t: 'cześć' }} in post.html or in post.en.html i get hi, the t: 'blabla' part is always blank

blackwinter commented 14 years ago

it uses the translation appropriate for the current page. i.e. if you set Localization::LANGUAGES.replace(%w[en pl]) in your ext.rb and put {{ 'hi' | t: 'cześć' }} inside post.pl.html you get 'cześć' in the output. does that answer your question?

rubyconvict commented 14 years ago

You mean: Jekyll::Localization::LANGUAGES.replace(%w[en pl]) Yay! That's what I needed. Thank you for helping me out and sharing this plugin of course. Cześć ;-)

blackwinter commented 14 years ago

yeah, thanks. i fixed the readme. great that you got it working!

proszę bardzo ;-)