forked from saurabh/orbit4-5
Add Simplified Chinese
This commit is contained in:
parent
91e8d87d59
commit
6747c00045
1
Gemfile
1
Gemfile
|
@ -40,6 +40,7 @@ gem "chartkick"
|
||||||
gem 'usagewatch_ext'
|
gem 'usagewatch_ext'
|
||||||
gem 'ckeditor'
|
gem 'ckeditor'
|
||||||
gem 'unicorn'
|
gem 'unicorn'
|
||||||
|
gem 'zhconv'
|
||||||
|
|
||||||
#built in modules
|
#built in modules
|
||||||
eval(File.read(File.dirname(__FILE__) + '/built_in_extensions.rb'))
|
eval(File.read(File.dirname(__FILE__) + '/built_in_extensions.rb'))
|
||||||
|
|
|
@ -12,6 +12,14 @@ class ApplicationController < ActionController::Base
|
||||||
def set_locale
|
def set_locale
|
||||||
in_use_locales = current_site.in_use_locales
|
in_use_locales = current_site.in_use_locales
|
||||||
|
|
||||||
|
if params[:locale].eql?("zh_cn")
|
||||||
|
params[:locale] = "zh_tw"
|
||||||
|
I18n.locale = session[:locale]
|
||||||
|
session[:zh_cn] = true
|
||||||
|
else
|
||||||
|
session[:zh_cn] = false
|
||||||
|
end
|
||||||
|
|
||||||
if params[:locale]
|
if params[:locale]
|
||||||
session[:locale] = in_use_locales.include?(params[:locale].to_sym) ? params[:locale] : nil
|
session[:locale] = in_use_locales.include?(params[:locale].to_sym) ? params[:locale] : nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# pass the layout=false for not rendering the layouts and also can specify the methods to in the backend controller.
|
# 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
|
# data-layout-content="arrayname" in layouts can be used to render data in the array
|
||||||
|
require 'zhconv'
|
||||||
|
|
||||||
class PagesController < ApplicationController
|
class PagesController < ApplicationController
|
||||||
before_action :get_key
|
before_action :get_key
|
||||||
|
@ -31,7 +32,9 @@ class PagesController < ApplicationController
|
||||||
impressionist(page)
|
impressionist(page)
|
||||||
OrbitHelper.set_params params
|
OrbitHelper.set_params params
|
||||||
OrbitHelper.set_site_locale locale
|
OrbitHelper.set_site_locale locale
|
||||||
render :html => render_final_page("home",page,true).html_safe
|
final_page = render_final_page("home",page,true)
|
||||||
|
final_page = session[:zh_cn] ? ZhConv.convert("zh-cn", final_page) : final_page
|
||||||
|
render :html => final_page.html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@ -82,7 +85,9 @@ class PagesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
impressionist(page)
|
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)
|
||||||
|
final_page = session[:zh_cn] ? ZhConv.convert("zh-cn", final_page) : final_page
|
||||||
|
render :html => final_page.html_safe
|
||||||
else
|
else
|
||||||
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => :not_found
|
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => :not_found
|
||||||
end
|
end
|
||||||
|
|
|
@ -310,11 +310,12 @@ module ApplicationHelper
|
||||||
|
|
||||||
def switch_language(loc)
|
def switch_language(loc)
|
||||||
url = request.original_fullpath
|
url = request.original_fullpath
|
||||||
if loc != locale
|
|
||||||
url = url.gsub("/#{locale.to_s}/","/#{loc.to_s}/")
|
locale = url.include?("zh_cn") ? :zh_cn : I18n.locale
|
||||||
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
|
url = url.gsub("/#{locale.to_s}/","/#{loc.to_s}/")
|
||||||
end
|
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
|
url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ class Site
|
||||||
field :mobile_api_openness_on, :type => Boolean, :default => false
|
field :mobile_api_openness_on, :type => Boolean, :default => false
|
||||||
field :desktop_closed, :type => Boolean, :default => false
|
field :desktop_closed, :type => Boolean, :default => false
|
||||||
field :enable_language_detection, :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 :default_locale, :default => "en"
|
||||||
field :mobile_on, :type => Boolean, :default => false
|
field :mobile_on, :type => Boolean, :default => false
|
||||||
field :announcement_category, :type => Array, :default=>[]
|
field :announcement_category, :type => Array, :default=>[]
|
||||||
|
|
|
@ -156,6 +156,14 @@
|
||||||
</div>
|
</div>
|
||||||
</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">
|
<div class="control-group">
|
||||||
<label class="control-label muted"><%= t('preferences.lang_enabled') %></label>
|
<label class="control-label muted"><%= t('preferences.lang_enabled') %></label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
|
|
|
@ -83,12 +83,18 @@
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
<li>
|
<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>
|
<ul>
|
||||||
<% @site_valid_locales.each do |l| %>
|
<% @site_valid_locales.each do |l| %>
|
||||||
<li class="<%= l == locale ? "active" : "" %>">
|
<li class="<%= (l == I18n.locale and !session['zh_cn']) ? "active" : "" %>">
|
||||||
<a href="<%= switch_language(l) %>"><%= t(:_locale, :locale => l) %></a>
|
<a href="<%= switch_language(l) %>"><%= t((l==:zh_tw ? :zh_tw_ : :_locale ), :locale => l) %></a>
|
||||||
</li>
|
</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 %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -23,6 +23,8 @@ en:
|
||||||
alternative: Alternative
|
alternative: Alternative
|
||||||
en: English
|
en: English
|
||||||
zh_tw: Chinese
|
zh_tw: Chinese
|
||||||
|
zh_tw_: Traditional Chinese
|
||||||
|
zh_cn: Simplified Chinese
|
||||||
_locale: English
|
_locale: English
|
||||||
access:
|
access:
|
||||||
denied:
|
denied:
|
||||||
|
@ -412,6 +414,7 @@ en:
|
||||||
icon: Icon
|
icon: Icon
|
||||||
language: Language
|
language: Language
|
||||||
lang_detection: Enable User Language Detection
|
lang_detection: Enable User Language Detection
|
||||||
|
enable_zh_cn: Enable Simplified Chinese
|
||||||
lang_enabled: Enable Language
|
lang_enabled: Enable Language
|
||||||
lang_default: Default Language
|
lang_default: Default Language
|
||||||
lang_detection: Enable User Language Detection
|
lang_detection: Enable User Language Detection
|
||||||
|
|
|
@ -2,6 +2,8 @@ zh_tw:
|
||||||
|
|
||||||
_locale: 中文
|
_locale: 中文
|
||||||
zh_tw: 中文
|
zh_tw: 中文
|
||||||
|
zh_tw_: 繁體中文
|
||||||
|
zh_cn: 简体中文
|
||||||
en: 英文
|
en: 英文
|
||||||
access:
|
access:
|
||||||
denied:
|
denied:
|
||||||
|
@ -405,6 +407,7 @@ zh_tw:
|
||||||
backend_open: 開啟後台給所有使用者
|
backend_open: 開啟後台給所有使用者
|
||||||
change: 更改
|
change: 更改
|
||||||
classification: 類別
|
classification: 類別
|
||||||
|
enable_zh_cn: 開啟簡體中文
|
||||||
frontend_open: "設定後, 前台將會開放給所有使用者."
|
frontend_open: "設定後, 前台將會開放給所有使用者."
|
||||||
favicon: 偏好圖示
|
favicon: 偏好圖示
|
||||||
icon: 圖示
|
icon: 圖示
|
||||||
|
|
|
@ -37,7 +37,7 @@ Orbit::Application.routes.draw do
|
||||||
|
|
||||||
locales = Site.first.in_use_locales rescue I18n.available_locales
|
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/form' => "users#form_page"
|
||||||
get 'users/role_page' => "users#role_page"
|
get 'users/role_page' => "users#role_page"
|
||||||
|
|
Loading…
Reference in New Issue