Full localization implementation

This commit is contained in:
2013-03-03 16:43:27 +01:00
parent 27c188773a
commit 1eb181b043
5 changed files with 32 additions and 7 deletions
+16
View File
@@ -109,4 +109,20 @@ module ApplicationHelper
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
+2 -2
View File
@@ -5,8 +5,8 @@
span.icon-bar
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: 'show', name: 'about') ? :active : nil)]= link_to t('menu.about'), page_path('about')
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 find_page('about').try(:menu_text), page_path('about')
.nav-collapse.collapse
ul.nav
- Page.top_menu.each do |page|
+1 -1
View File
@@ -50,7 +50,7 @@ module Qwaiter
# 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.default_locale = :de
config.i18n.default_locale = :nl
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
+4 -4
View File
@@ -155,10 +155,10 @@ Qwaiter::Application.routes.draw do
# just remember to delete public/index.html.
#
#root :to => 'dashboard#home'
root :to => 'pages#home'
scope '(/:locale)', constraints: {locale: /nl|be|de|fr|en/}, defaults: { locale: :nl } do
get "/:name" => "pages#show", constraints: {name: /.*/}, as: :page
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
get "/:name" => "pages#show", constraints: {name: /.*/}, as: :go_to
end
# See how all your routes lay out with "rake routes"
+9
View File
@@ -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