Skip to content

Instantly share code, notes, and snippets.

@elvisgiv
Last active April 27, 2018 13:55
Show Gist options
  • Save elvisgiv/5bef5b01a575c0d7ea1c to your computer and use it in GitHub Desktop.
Save elvisgiv/5bef5b01a575c0d7ea1c to your computer and use it in GitHub Desktop.
как настроить перевод

First!

Для того, чтобы сделать перевод строк для начала необходимо зайти в файл

     *\config\initializers\lacale.rb 

и заменить в нем язык по умолчанию в строке с :en на, в МОЕМ случае, :ru

    C I18n.default_locale = :en На I18n.default_locale = :ru

и добавляем

I18n.available_locales = [:en, :ru]

для того, чтобы в рутах можно было указать какие языки должны быть (см. ниже)

Second!

Затем заходим в файл

    \config\locales\ru.yml

и создем в нем все, что нам требуется для ЛЮБЫХ форм, в МОЕМ случае так:

    ru:
      order:
        field:
          notes:
            notes_problem: 'Описание проблемы клиентом'
            notes_package: 'Комплектация устройства'
            notes_acceptance: 'Замечания при приемке'

Third!

заходим в любую вьюху, у МЕНЯ:

    *\app\views\orders\_form.html.haml

и создаем поля, Я использовал gem 'simple_form':

    .col-md-12
      = simple_form_horizontal_for @order do |f|
        = f.input :notes_problem, label: t('order.field.notes.notes_problem')
        = f.input :notes_package, label: t('order.field.notes.notes_package')

После КАЖДОГО изменения в папке CONFIG, перегружаем сервер

another example

in route

  scope '/:lang', lang: /#{I18n.available_locales.join('|')}/ do
    resources :startup_proposals, only: [:new, :create]
  end

in application_controller.rb

...
  def set_locale
    @lang = params[:lang] || 'en'
    params[:lang] ||= @lang

    # set locale
    I18n.locale = @lang.to_sym
...
  end

in any controller

...
  before_action :set_locale
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment