From 968bcd5acbbb52038a895e54acfb34810b435d74 Mon Sep 17 00:00:00 2001 From: Erick Guan Date: Sat, 8 Nov 2014 20:17:51 +0800 Subject: [PATCH 1/2] Add zh_CN translation for emoji plugin --- plugins/emoji/config/locales/client.zh_CN.yml | 6 ++++++ plugins/emoji/config/locales/server.zh_CN.yml | 3 +++ 2 files changed, 9 insertions(+) create mode 100644 plugins/emoji/config/locales/client.zh_CN.yml create mode 100644 plugins/emoji/config/locales/server.zh_CN.yml diff --git a/plugins/emoji/config/locales/client.zh_CN.yml b/plugins/emoji/config/locales/client.zh_CN.yml new file mode 100644 index 00000000000..cdf886ae897 --- /dev/null +++ b/plugins/emoji/config/locales/client.zh_CN.yml @@ -0,0 +1,6 @@ +zh_CN: + admin_js: + admin: + site_settings: + categories: + plugins: "插件" diff --git a/plugins/emoji/config/locales/server.zh_CN.yml b/plugins/emoji/config/locales/server.zh_CN.yml new file mode 100644 index 00000000000..5124f0651d9 --- /dev/null +++ b/plugins/emoji/config/locales/server.zh_CN.yml @@ -0,0 +1,3 @@ +zh_CN: + site_settings: + enable_emoji: "启用绘文字(emoji)插件" From 667758ff40f21b088caa151618adb19b07fe1ce9 Mon Sep 17 00:00:00 2001 From: Erick Guan Date: Tue, 16 Sep 2014 19:15:05 +0800 Subject: [PATCH 2/2] Add stringex for Chinese slug generation --- Gemfile | 2 ++ Gemfile.lock | 2 ++ config/locales/server.en.yml | 4 ++++ lib/slug.rb | 7 +++++++ spec/components/search_spec.rb | 4 ++-- spec/components/slug_spec.rb | 7 ++++++- spec/models/category_spec.rb | 10 ++++++++-- spec/models/topic_spec.rb | 8 ++++++++ 8 files changed, 39 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index b3aa247122d..4a70689a78c 100644 --- a/Gemfile +++ b/Gemfile @@ -241,6 +241,8 @@ gem 'memory_profiler', require: false, platform: :mri_21 gem 'rmmseg-cpp', require: false +gem 'stringex', require: false + gem 'logster' # perftools only works on 1.9 atm diff --git a/Gemfile.lock b/Gemfile.lock index 18cd36b58bb..17f8b4931e0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -371,6 +371,7 @@ GEM activesupport (>= 3.0) sprockets (~> 2.8) stackprof (0.2.7) + stringex (2.5.2) therubyracer (0.12.1) libv8 (~> 3.16.14.0) ref @@ -488,6 +489,7 @@ DEPENDENCIES sinatra spork-rails stackprof + stringex therubyracer thin timecop diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 684bd7dfebc..8ad6bd26bfb 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -15,6 +15,10 @@ # http://yamllint.com/ en: + stringex: + characters: + ellipsis: "" + number: "-" # some default transliteration rules may be missing, add them to your locale i18n: transliterate: diff --git a/lib/slug.rb b/lib/slug.rb index d30833cb1ff..848746cf363 100644 --- a/lib/slug.rb +++ b/lib/slug.rb @@ -1,10 +1,17 @@ # encoding: utf-8 + module Slug def self.for(string) slug = string.gsub("'", "").parameterize slug.gsub!("_", "-") + if ['zh_CN', 'ja', 'ko'].include?(SiteSetting.default_locale) + unless defined? Stringex + require 'stringex_lite' + end + slug = string.to_url + end slug =~ /[^\d]/ ? slug : '' # Reject slugs that only contain numbers, because they would be indistinguishable from id's. end diff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rb index ffe61971ddf..a80d6483150 100644 --- a/spec/components/search_spec.rb +++ b/spec/components/search_spec.rb @@ -302,10 +302,10 @@ describe Search do it 'finds chinese topic based on title' do SiteSetting.default_locale = 'zh_TW' - topic = Fabricate(:topic, title: 'My Title Discourse社区指南') + topic = Fabricate(:topic, title: 'My Title Discourse社區指南') post = Fabricate(:post, topic: topic) - Search.execute('社区指南').posts.first.id.should == post.id + Search.execute('社區指南').posts.first.id.should == post.id Search.execute('指南').posts.first.id.should == post.id end end diff --git a/spec/components/slug_spec.rb b/spec/components/slug_spec.rb index 6491b300205..8967dd33125 100644 --- a/spec/components/slug_spec.rb +++ b/spec/components/slug_spec.rb @@ -48,12 +48,17 @@ describe Slug do end it "doesn't generate slugs that are just numbers" do - Slug.for('電車男 2').should be_blank + Slug.for('2').should be_blank end it "doesn't keep single quotes within word" do Slug.for("Jeff hate's this").should == "jeff-hates-this" end + it "translate the chineses" do + SiteSetting.default_locale = 'zh_CN' + Slug.for("习近平:中企承建港口电站等助斯里兰卡发展").should == "xi-jin-ping-zhong-qi-cheng-jian-gang-kou-dian-zhan-deng-zhu-si-li-lan-qia-fa-zhan" + end + end diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb index f366b566c35..6defee8fee6 100644 --- a/spec/models/category_spec.rb +++ b/spec/models/category_spec.rb @@ -169,16 +169,22 @@ describe Category do end describe 'non-english characters' do - let(:category) { Fabricate(:category, name: "電車男") } + let(:category) { Fabricate(:category, name: "测试") } it "creates a blank slug, this is OK." do category.slug.should be_blank category.slug_for_url.should == "#{category.id}-category" end + + it "creates a localized slug if default locale is zh_CN" do + SiteSetting.default_locale = 'zh_CN' + category.slug.should_not be_blank + category.slug_for_url.should == "ce-shi" + end end describe 'slug would be a number' do - let(:category) { Fabricate(:category, name: "電車男 2") } + let(:category) { Fabricate(:category, name: "2") } it 'creates a blank slug' do category.slug.should be_blank diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 4fa690804d1..63e17eb5ba0 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -21,6 +21,14 @@ describe Topic do Fabricate.build(:topic, title: title).slug.should == slug end + let(:chinese_title) { "习近平:中企承建港口电站等助斯里兰卡发展" } + let(:chinese_slug) { "xi-jin-ping-zhong-qi-cheng-jian-gang-kou-dian-zhan-deng-zhu-si-li-lan-qia-fa-zhan" } + + it "returns a symbolized slug for a chinese title" do + SiteSetting.default_locale = 'zh_CN' + Fabricate.build(:topic, title: chinese_title).slug.should == chinese_slug + end + it "returns 'topic' when the slug is empty (say, non-english chars)" do Slug.expects(:for).with(title).returns("") Fabricate.build(:topic, title: title).slug.should == "topic"