Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set html lang attribute on rails

I have a multilingual rails application. On the base.html.erb I am setting the lang attribute like that :

<html lang="<%= I18n.locale %>" ng-app="myApp">

Is that a good way to do it or there is a better one ?

like image 391
Petran Avatar asked Jun 26 '14 13:06

Petran


1 Answers

It might work okay; although you might prefer setting the current locale within your controllers for better flexibility

class ApplicationController < ActionController::Base
  helper_method :current_locale
  ...

  private

  def current_locale
    @current_locale ||= begin
      # complex logic, switching locale based on
      # user defined locale, subdomain, params, etc...
    end
  end
end

Then in your view :

<html lang="<%= current_locale %>" ng-app="myApp">
...
like image 169
Ben Avatar answered Sep 22 '22 11:09

Ben