Note that there are some explanatory texts on larger screens.

plurals
  1. POi18n markdown files in Rails 3 views
    text
    copied!<p>I am currently working through Michael Hartl's <a href="http://ruby.railstutorial.org/ruby-on-rails-tutorial-book?version=3.2" rel="nofollow">Rails Tutorial</a> while experimenting with some other things not covered in the book. After completing <a href="http://ruby.railstutorial.org/chapters/filling-in-the-layout?version=3.2#top" rel="nofollow">Chapter 5</a>, where the static pages are created, I decided change the view code to HAML, internationalize the pages, and put the static content into separate (non-partial) Markdown files, using the RDiscount gem to render them. For example:</p> <p><strong>app/views/static_pages/about.html.haml</strong></p> <pre><code>- provide(:title, t('.about_us')) :markdown #{render file: "static_pages/about.#{params[:locale]}.md"} </code></pre> <p>Under the <strong>static_pages</strong> directory, I have Markdown files like <strong>about.en.md</strong>, <strong>about.it.md</strong>, <strong>about.ja.md</strong> etc, so interpolating in the <code>:locale</code> parameter is what determines which language Markdown file gets rendered.</p> <p>My questions are:</p> <ol> <li>The <strong>static_pages</strong> directory is a bit crowded with Markdown files, so are there any sensible default/best practice locations (perhaps outside of the <strong>app</strong> directory) to keep these Markdown files, where they could be presumably be edited by people who don't need to know about the inner workings of the app?</li> <li>What better ways are there to implement rendering multi-lingual Markdown files in views? My use of <code>:locale</code> and the double string-interpolation seems inelegant.</li> <li><p>Is there a way to change this code so that I can pass Ruby variables into the Markdown file? I know I can, for example, use a <code>#{language}</code> variable in the Markdown by just changing <strong>about.en.md</strong> into a HAML partial (<strong>_about.en.html.haml</strong>) and change the code to look something like:</p> <p><strong>app/views/static_pages/about.html.haml</strong></p> <pre><code>- provide(:title, t('.about_us')) :markdown #{render "about.#{params[:locale]}", language: 'Markdown!'} </code></pre> <p>But, is there a way to do this without changing the Markdown file into another type of file? If such a way exists, is it recommended/feasible? </p></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload