This repository has been archived by the owner on Jan 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix admin localization not actually working. Oops. Add tests too.
- Loading branch information
Showing
11 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,6 @@ config/environments/*.local.yml | |
|
||
# Test coverage reports | ||
/coverage | ||
|
||
# Generated assets | ||
/public/test-assets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//= depend_on "de.yml" | ||
//= require polyglot | ||
<%= JsLocaleHelper.output_locale(:de) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//= depend_on "es-419.yml" | ||
//= require polyglot | ||
<%= JsLocaleHelper.output_locale(:"es-419") %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//= depend_on "fi.yml" | ||
//= require polyglot | ||
<%= JsLocaleHelper.output_locale(:fi) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//= depend_on "fr.yml" | ||
//= require polyglot | ||
<%= JsLocaleHelper.output_locale(:fr) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//= depend_on "it.yml" | ||
//= require polyglot | ||
<%= JsLocaleHelper.output_locale(:it) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//= depend_on "ru.yml" | ||
//= require polyglot | ||
<%= JsLocaleHelper.output_locale(:ru) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
class Admin::SessionsController < Devise::SessionsController | ||
before_filter :set_locale | ||
|
||
def new | ||
end | ||
|
||
def after_sign_out_path_for(resource_or_scope) | ||
admin_path | ||
end | ||
|
||
private | ||
|
||
def set_locale | ||
I18n.locale = http_accept_language.compatible_language_from(I18n.available_locales) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require "spec_helper" | ||
|
||
describe "locales", :js => true do | ||
describe "login page" do | ||
I18n.available_locales.each do |locale| | ||
it "translates in #{locale}" do | ||
page.driver.add_headers("Accept-Language" => locale.to_s) | ||
visit "/admin/login" | ||
page.should have_content(I18n.t("omniauth_providers.developer", :locale => locale)) | ||
end | ||
|
||
it "falls back to english for unknown languages" do | ||
page.driver.add_headers("Accept-Language" => "zz") | ||
visit "/admin/login" | ||
page.should have_content(I18n.t("omniauth_providers.developer", :locale => "en")) | ||
end | ||
end | ||
end | ||
|
||
describe "admin" do | ||
login_admin | ||
|
||
describe "server-side and client-side js translations" do | ||
I18n.available_locales.each do |locale| | ||
it "translates in #{locale}" do | ||
page.driver.add_headers("Accept-Language" => locale.to_s) | ||
visit "/admin/#/apis/new" | ||
|
||
# Server-side rendered i18n | ||
page.should have_content(I18n.t("admin.nav.analytics", :locale => locale)) | ||
|
||
# Client-side rendered i18n | ||
page.should have_content(I18n.t("admin.api.servers.add", :locale => locale)) | ||
end | ||
|
||
it "falls back to english for unknown languages" do | ||
page.driver.add_headers("Accept-Language" => "zz") | ||
visit "/admin/#/apis/new" | ||
|
||
# Server-side rendered i18n | ||
page.should have_content(I18n.t("admin.nav.analytics", :locale => "en")) | ||
|
||
# Client-side rendered i18n | ||
page.should have_content(I18n.t("admin.api.servers.add", :locale => "en")) | ||
end | ||
end | ||
end | ||
end | ||
end |