Storing application text: embedded or separate file

I am working on a Merb application using Haml as my templating language. Since haml encourages moving logic out of the view and into the helpers, I soon started thinking about removing the copy / text from the templates themselves. In the past, I either just left the text inside the templates or moved it into separate yaml files separated by the controller. I found that leaving the text on the line is more convenient but uglier and suggests using Ack to find out where a particular piece of text is saved. Saving it in a yaml file is easier to find, but harder to come up with a sensible naming scheme for finding a specific piece of text in a given area.

I am also interested in other approaches to this problem.

+1


a source to share


1 answer


Keeping texts separate is useful if you want to globalize / internationalize your application. There are many great plugins for rails for this (Rails 2.3 even has an api for this), but they usually work for merb as well. There are various approaches to this, the two main approaches are how you store the key:

  • A YAML-like interface, you use storage symbols which I think assign text to that symbol.
  • The gettext-style method is that the text is a character and you can override it in a separate file if you want (but if you don't, you will return the same string as the key).


Both approaches have their advantages and disadvantages. Apart from the key, there are tons of repositories you can use, like YAML, or you can actually create a complete ActiveRecord / DataMapper / etc. based storage engine.

You can check out how rails 2.3 does with globalization, because their naming scheme might be a good starting point for you. Or, use namespaces to separate YAML files so it's easier to find them. You can also try the gettext approach, but it is not really considered DRY or safe (but there are many tools that will create mapping files containing all the text your application has).

+1


a source







All Articles