Full localization implementation
This commit is contained in:
@@ -109,4 +109,20 @@ module ApplicationHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def page_path(record)
|
||||||
|
str = case record
|
||||||
|
when Page then record.name
|
||||||
|
else record
|
||||||
|
end
|
||||||
|
go_to_path(str, locale: I18n.locale)
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_page(name)
|
||||||
|
Page.find_by_name_and_locale(name, I18n.locale)
|
||||||
|
end
|
||||||
|
|
||||||
|
def locale_root_path
|
||||||
|
I18n.locale == I18n.default_locale ? '/' : "/#{I18n.locale}"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
span.icon-bar
|
span.icon-bar
|
||||||
|
|
||||||
ul.nav
|
ul.nav
|
||||||
li[class=(current_page?(controller: '/pages', action: 'home') ? :active : nil)]= link_to t('menu.home'), root_path
|
li[class=(current_page?(controller: '/pages', action: 'home') ? :active : nil)]= link_to find_page('home').try(:menu_text), locale_root_path
|
||||||
li[class=(current_page?(controller: '/pages', action: 'show', name: 'about') ? :active : nil)]= link_to t('menu.about'), page_path('about')
|
li[class=(current_page?(controller: '/pages', action: 'show', name: 'about') ? :active : nil)]= link_to find_page('about').try(:menu_text), page_path('about')
|
||||||
.nav-collapse.collapse
|
.nav-collapse.collapse
|
||||||
ul.nav
|
ul.nav
|
||||||
- Page.top_menu.each do |page|
|
- Page.top_menu.each do |page|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ module Qwaiter
|
|||||||
|
|
||||||
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
||||||
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
||||||
# config.i18n.default_locale = :de
|
config.i18n.default_locale = :nl
|
||||||
|
|
||||||
# Configure the default encoding used in templates for Ruby 1.9.
|
# Configure the default encoding used in templates for Ruby 1.9.
|
||||||
config.encoding = "utf-8"
|
config.encoding = "utf-8"
|
||||||
|
|||||||
+4
-4
@@ -155,10 +155,10 @@ Qwaiter::Application.routes.draw do
|
|||||||
# just remember to delete public/index.html.
|
# just remember to delete public/index.html.
|
||||||
#
|
#
|
||||||
#root :to => 'dashboard#home'
|
#root :to => 'dashboard#home'
|
||||||
root :to => 'pages#home'
|
root :to => 'pages#home', defaults: {locale: 'nl'}
|
||||||
|
get '/:locale' => 'pages#home', constraints: {locale: /nl|be|de|fr|en/}
|
||||||
scope '(/:locale)', constraints: {locale: /nl|be|de|fr|en/}, defaults: { locale: :nl } do
|
scope '(/:locale)', constraints: {locale: /nl|be|de|fr|en/}, defaults: { locale: 'nl' } do
|
||||||
get "/:name" => "pages#show", constraints: {name: /.*/}, as: :page
|
get "/:name" => "pages#show", constraints: {name: /.*/}, as: :go_to
|
||||||
end
|
end
|
||||||
|
|
||||||
# See how all your routes lay out with "rake routes"
|
# See how all your routes lay out with "rake routes"
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
require "spec_helper"
|
||||||
|
|
||||||
|
describe "routing" do
|
||||||
|
it('roots to pages#home'){get('/').should route_to('pages#home', locale: 'nl')}
|
||||||
|
it('roots to pages#home for en locale'){get('/en').should route_to('pages#home', locale: 'en')}
|
||||||
|
it('handles about page as root'){ get('/about').should route_to('pages#show', name: 'about', locale: 'nl')}
|
||||||
|
it('handles about page in nl'){ get('/nl/about').should route_to('pages#show', name: 'about', locale: 'nl')}
|
||||||
|
it('handles about page in en'){ get('/en/about').should route_to('pages#show', name: 'about', locale: 'en')}
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user