我目前正在学习Michael Hartl的Rails教程,同时尝试一些书中未涉及的其他内容。完成第5章后,我决定将视图代码更改为HAML,对页面进行国际化处理,并将静态内容放入单独的(非部分)Markdown文件中,使用RDiscount gem进行渲染。例如:
app/views/static_pages/about.html.haml
- provide(:title, t('.about_us'))
:markdown
#{render file: "static_pages/about.#{params[:locale]}.md"}
在 static_pages 目录下,我有像 about.en.md, about.it.md, about.ja.md 这样的 Markdown 文件,因此在
:locale
参数中插入变量会决定哪个语言的 Markdown 文件被渲染。我的问题是:
- The static_pages directory is a bit crowded with Markdown files, so are there any sensible default/best practice locations (perhaps outside of the app 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?
- What better ways are there to implement rendering multi-lingual Markdown files in views? My use of
:locale
and the double string-interpolation seems inelegant. 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
#{language}
variable in the Markdown by just changing about.en.md into a HAML partial (_about.en.html.haml) and change the code to look something like:app/views/static_pages/about.html.haml
- provide(:title, t('.about_us')) :markdown #{render "about.#{params[:locale]}", language: 'Markdown!'}
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?