Вопрос

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)

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top