codeforamerica / balance

A text message system for checking one's EBT card balance (SNAP benefits and more)
MIT License
47 stars 37 forks source link

Using standard Ruby `i18n` library #355

Open tbjers opened 8 years ago

tbjers commented 8 years ago

During today’s National Day of Civic Hacking in Charlotte, Jim van Fleet (co-captain for Code for Charlotte) showed off the NC Balance project to me and a few other new people. He was asked the question how it works with different languages, and we looked at the code and noticed the somewhat primitive if/else clauses in the message generator. We figured that we could make this better by using the Ruby i18n package instead.

This change does not change the messages in any way other than using I18n.t to translate them with. New languages can easily be added by adding a new case statement to the language assignment in MessageGenerator.initialize as well as a file in config/locales.

Added support for internationalization to alleviate if/else bloat. Loading locales into Sinatra on initialization. Updated specs to work with i18n and sinatra/i18n. Updated message_generator.rb with I18n.t usage.