简体   繁体   中英

Multilingual ruby on rails app

I want to have Greek support in my rails app for the messages/flashes etc. I took a quick look at the I18n framework but it seems like a lot of configuration for something so simple. I thing that there should be a very easy way to do something like this but ( apparently ) I don't know it. If anyone would be willing to help me I'll be glad. Thanks.

Rails has conventions so you don't have to configure.

Create a file in config/locales/el.yml with the contents:

el:
  flash_messages:
    success: "επιτυχία"
    fail: "αποτυγχάνουν"

Then in your controller:

flash[:notice] = t('flash_messages.success')

and you'll get the translated string in your view.

You can change the locale like this:

I18n.locale = :el

I don't know how it could be easier. The "Rails I18n Guide": http://guides.rubyonrails.org/i18n.html has all the gory details if you want to fight the conventions or go beyond simple.

I18N ain't simple .

Here are some of the reasons why internationalization is hard.

First, every piece of text that might be shown to the user is a potential candidate for translation. That means not just properties of components (like menu items and button labels), but also text drawn with stroke drawing calls, and text embedded in pixel images (like this one taken from the MIT EECS web page). Translation can easily change the size or aspect ratio of the text; German labels tend to be much longer than English ones, for example.

Error messages also need to be translated, of course — which is another reason not to expose internal system names in error messages. An English-reading user might be able to figure out what FileNotFoundException means, but it won't internationalize well.

Don't know Ruby so I can't help you more.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM