byCoder
byCoder

Reputation: 9184

Rails display notice in non-english language

I have this code:

  if @art.save
    flash[:notice] = "Successfully saved!"
  end

But I need something like this (in russian):

  if @art.save
    flash[:notice] = "Успешно сохранено в бд!"
  end

Sure it's giving me errors, but are there any ways to use non-english notices in RoR? Or must I use locales? Then how do I translate only that notice? (in html is in .n1 class)

Upvotes: 0

Views: 76

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230521

I think you're missing a magic encoding comment. Add this to the top of the file

# encoding: utf-8

Also, a much better way is to use a built-in internationalization api. With it, your code will look like this:

flash[:notice] = I18n.t(:successful_save)

And all your russian strings will be contained within config/locales/ru.yml and won't cause any troubles in the source code.

Upvotes: 2

Related Questions