Compare commits

...

2 Commits

Author SHA1 Message Date
manson a2c25c4192 fix url for zh_cn 2014-07-08 19:59:46 +08:00
manson 6747c00045 Add Simplified Chinese 2014-07-08 19:38:19 +08:00
10 changed files with 53 additions and 11 deletions

View File

@ -40,6 +40,7 @@ gem "chartkick"
gem 'usagewatch_ext'
gem 'ckeditor'
gem 'unicorn'
gem 'zhconv'
#built in modules
eval(File.read(File.dirname(__FILE__) + '/built_in_extensions.rb'))

View File

@ -12,6 +12,14 @@ class ApplicationController < ActionController::Base
def set_locale
in_use_locales = current_site.in_use_locales
if params[:locale].eql?("zh_cn") or (!params[:locale] and session[:zh_cn])
params[:locale] = "zh_tw"
I18n.locale = session[:locale]
session[:zh_cn] = true
else
session[:zh_cn] = false
end
if params[:locale]
session[:locale] = in_use_locales.include?(params[:locale].to_sym) ? params[:locale] : nil
end

View File

@ -1,5 +1,6 @@
# pass the layout=false for not rendering the layouts and also can specify the methods to in the backend controller.
# data-layout-content="arrayname" in layouts can be used to render data in the array
require 'zhconv'
class PagesController < ApplicationController
before_action :get_key
@ -31,7 +32,12 @@ class PagesController < ApplicationController
impressionist(page)
OrbitHelper.set_params params
OrbitHelper.set_site_locale locale
render :html => render_final_page("home",page,true).html_safe
final_page = render_final_page("home",page,true)
if session[:zh_cn]
final_page = ZhConv.convert("zh-cn", final_page)
final_page.gsub!('/zh_tw/','/zh_cn/')
end
render :html => final_page.html_safe
end
def show
@ -82,7 +88,12 @@ class PagesController < ApplicationController
end
impressionist(page)
render :html => render_final_page("#{module_app}/#{params[:target_action]}",page,layout).html_safe
final_page = render_final_page("#{module_app}/#{params[:target_action]}",page,layout)
if session[:zh_cn]
final_page = ZhConv.convert("zh-cn", final_page)
final_page.gsub!('/zh_tw/','/zh_cn/')
end
render :html => final_page.html_safe
else
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => :not_found
end

View File

@ -310,11 +310,12 @@ module ApplicationHelper
def switch_language(loc)
url = request.original_fullpath
if loc != locale
url = url.gsub("/#{locale.to_s}/","/#{loc.to_s}/")
url = url.gsub("locale=#{locale.to_s}","locale=#{loc.to_s}") if url == request.original_fullpath
url = url + "#{url.include?("?") ? "&" : "?"}locale=#{loc.to_s}" if url == request.original_fullpath
end
locale = url.include?("zh_cn") ? :zh_cn : I18n.locale
url = url.gsub("/#{locale.to_s}/","/#{loc.to_s}/")
url = url.gsub("locale=#{locale.to_s}","locale=#{loc.to_s}") if url == request.original_fullpath
url = url + "#{url.include?("?") ? "&" : "?"}locale=#{loc.to_s}" if url == request.original_fullpath and !url.include?(locale.to_s)
url
end

View File

@ -19,6 +19,7 @@ class Site
field :mobile_api_openness_on, :type => Boolean, :default => false
field :desktop_closed, :type => Boolean, :default => false
field :enable_language_detection, :type => Boolean, :default => false
field :enable_zh_cn, :type => Boolean, :default => true
field :default_locale, :default => "en"
field :mobile_on, :type => Boolean, :default => false
field :announcement_category, :type => Array, :default=>[]

View File

@ -156,6 +156,14 @@
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('preferences.enable_zh_cn') %>
</label>
<div class="controls">
<%= f.check_box :enable_zh_cn, :class => "toggle-check", data: {disabled: true} %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%= t('preferences.lang_enabled') %></label>
<div class="controls">

View File

@ -83,12 +83,18 @@
</li>
<% end %>
<li>
<span id="language"><%= t(locale.to_s) %></span>
<% locale = session[:zh_cn] ? :zh_cn : I18n.locale %>
<span id="language"><%= t((locale==:zh_tw ? :zh_tw_ : locale.to_s)) %></span>
<ul>
<% @site_valid_locales.each do |l| %>
<li class="<%= l == locale ? "active" : "" %>">
<a href="<%= switch_language(l) %>"><%= t(:_locale, :locale => l) %></a>
<li class="<%= (l == I18n.locale and !session['zh_cn']) ? "active" : "" %>">
<a href="<%= switch_language(l) %>"><%= t((l==:zh_tw ? :zh_tw_ : :_locale ), :locale => l) %></a>
</li>
<% if current_site.enable_zh_cn and l == :zh_tw %>
<li class="">
<a href="<%= switch_language(:zh_cn) %>"><%= t(:zh_cn, :locale => :zh_tw) %></a>
</li>
<% end %>
<% end %>
</ul>
</li>

View File

@ -23,6 +23,8 @@ en:
alternative: Alternative
en: English
zh_tw: Chinese
zh_tw_: Traditional Chinese
zh_cn: Simplified Chinese
_locale: English
access:
denied:
@ -412,6 +414,7 @@ en:
icon: Icon
language: Language
lang_detection: Enable User Language Detection
enable_zh_cn: Enable Simplified Chinese
lang_enabled: Enable Language
lang_default: Default Language
lang_detection: Enable User Language Detection

View File

@ -2,6 +2,8 @@ zh_tw:
_locale: 中文
zh_tw: 中文
zh_tw_: 繁體中文
zh_cn: 简体中文
en: 英文
access:
denied:
@ -405,6 +407,7 @@ zh_tw:
backend_open: 開啟後台給所有使用者
change: 更改
classification: 類別
enable_zh_cn: 開啟簡體中文
frontend_open: "設定後, 前台將會開放給所有使用者."
favicon: 偏好圖示
icon: 圖示

View File

@ -37,7 +37,7 @@ Orbit::Application.routes.draw do
locales = Site.first.in_use_locales rescue I18n.available_locales
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
scope "(:locale)", locale: Regexp.new((locales+[:zh_cn]).join("|")) do
get 'users/form' => "users#form_page"
get 'users/role_page' => "users#role_page"