russian 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +37 -1
- data/Rakefile +1 -1
- data/TODO +1 -0
- data/lib/russian.rb +13 -2
- data/lib/russian/active_support_ext/parameterize.rb +24 -0
- data/lib/russian/transliteration.rb +54 -0
- data/spec/transliteration_spec.rb +42 -0
- metadata +6 -2
data/README.textile
CHANGED
@@ -182,6 +182,19 @@ Russian.p(3.14, "вещь", "вещи", "вещей", "вещи") # послед
|
|
182
182
|
|
183
183
|
-- упрощенная (без использования хешей I18n) плюрализация для русского языка
|
184
184
|
|
185
|
+
<pre><code>
|
186
|
+
Russian::transliterate
|
187
|
+
Russian::translit
|
188
|
+
|
189
|
+
Russian.translit("рубин")
|
190
|
+
=> "rubin"
|
191
|
+
Russian.translit("Hallo Юлику Тарханову")
|
192
|
+
=> "Hallo Yuliku Tarhanovu"
|
193
|
+
</code></pre>
|
194
|
+
|
195
|
+
-- транслитерация русских букв в строке.
|
196
|
+
|
197
|
+
|
185
198
|
h2. Ruby on Rails
|
186
199
|
|
187
200
|
h3. Переводы
|
@@ -218,7 +231,6 @@ ru-RU:
|
|
218
231
|
<label for="user_name">Имя</label>
|
219
232
|
</code></pre>
|
220
233
|
|
221
|
-
|
222
234
|
h3. Валидация
|
223
235
|
|
224
236
|
Обработка ошибок в ActiveRecord перегружается -- в Russian включен популярный плагин custom_error_message, с помощью которого можно переопределять стандартное отображение сообщений об ошибках. Так, например,
|
@@ -245,8 +257,32 @@ h3. Валидация
|
|
245
257
|
|
246
258
|
_NB:_ в сообщениях валидации можно использовать такие макросы как @{{attribute}}@, @{{value}}@ -- подробнее см. документацию по I18n.
|
247
259
|
|
260
|
+
h3. Параметризация строк
|
261
|
+
|
262
|
+
Перегружается метод @parameterize@ инфлектора ActiveSupport (он же -- @String#parameterize@), теперь в нем идет транслитерация букв русского алфавита.
|
263
|
+
|
264
|
+
Пример:
|
265
|
+
|
266
|
+
<pre><code>
|
267
|
+
class Person
|
268
|
+
def to_param
|
269
|
+
"#{id}-#{name.parameterize}"
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
@person = Person.find(1)
|
274
|
+
# => #<Person id: 1, name: "Дональд Кнут">
|
275
|
+
|
276
|
+
<%= link_to(@person.name, person_path %>
|
277
|
+
# => <a href="/person/1-donald-knut">Дональд Кнут</a>
|
278
|
+
</code></pre>
|
279
|
+
|
248
280
|
h1. Автор
|
249
281
|
|
250
282
|
Для сообщений об ошибках, обнаруженных неточностях и предложений:
|
251
283
|
|
252
284
|
Ярослав Маркин ("yaroslav@markin.net":mailto:yaroslav@markin.net)
|
285
|
+
|
286
|
+
Огромное спасибо:
|
287
|
+
|
288
|
+
Юлику Тарханову (me@julik.nl) за "rutils":http://rutils.rubyforge.org/
|
data/Rakefile
CHANGED
data/TODO
CHANGED
data/lib/russian.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
$KCODE='u'
|
2
2
|
|
3
3
|
$:.push File.join(File.dirname(__FILE__), 'russian')
|
4
|
+
require 'transliteration'
|
4
5
|
|
5
6
|
# I18n require
|
6
7
|
unless defined?(I18n)
|
7
8
|
$:.push File.join(File.dirname(__FILE__), 'vendor', 'i18n', 'lib')
|
8
9
|
require 'i18n'
|
9
10
|
end
|
10
|
-
|
11
11
|
# Advanced backend
|
12
12
|
require 'backend/advanced'
|
13
13
|
|
@@ -17,12 +17,13 @@ if defined?(ActionView::Helpers)
|
|
17
17
|
require 'action_view_ext/helpers/date_helper'
|
18
18
|
require 'vendor/i18n_label/init'
|
19
19
|
end
|
20
|
+
require 'active_support_ext/parameterize' if defined?(ActiveSupport::Inflector)
|
20
21
|
|
21
22
|
module Russian
|
22
23
|
module VERSION
|
23
24
|
MAJOR = 0
|
24
25
|
MINOR = 0
|
25
|
-
TINY =
|
26
|
+
TINY = 8
|
26
27
|
|
27
28
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
28
29
|
end
|
@@ -81,6 +82,16 @@ module Russian
|
|
81
82
|
I18n.backend.send(:pluralize, LOCALE, variants_hash, n)
|
82
83
|
end
|
83
84
|
alias :p :pluralize
|
85
|
+
|
86
|
+
# Transliteration for russian language
|
87
|
+
#
|
88
|
+
# Usage:
|
89
|
+
# Russian.translit("рубин")
|
90
|
+
# Russian.transliterate("рубин")
|
91
|
+
def transliterate(str)
|
92
|
+
Russian::Transliteration.transliterate(str)
|
93
|
+
end
|
94
|
+
alias :translit :transliterate
|
84
95
|
|
85
96
|
protected
|
86
97
|
# Returns all locale files shipped with library
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ActiveSupport
|
2
|
+
module Inflector
|
3
|
+
# Replaces special characters in a string so that it may be used as part of a 'pretty' URL.
|
4
|
+
#
|
5
|
+
# ==== Examples
|
6
|
+
#
|
7
|
+
# class Person
|
8
|
+
# def to_param
|
9
|
+
# "#{id}-#{name.parameterize}"
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# @person = Person.find(1)
|
14
|
+
# # => #<Person id: 1, name: "Дональд Кнут">
|
15
|
+
#
|
16
|
+
# <%= link_to(@person.name, person_path %>
|
17
|
+
# # => <a href="/person/1-donald-knut">Дональд Кнут</a>
|
18
|
+
def parameterize_with_russian(string, sep = '-')
|
19
|
+
parameterize_without_russian(Russian::transliterate(string), sep)
|
20
|
+
end
|
21
|
+
alias_method :parameterize_without_russian, :parameterize
|
22
|
+
alias_method :parameterize, :parameterize_with_russian
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Russian
|
2
|
+
# Russian transliteration
|
3
|
+
module Transliteration
|
4
|
+
extend self
|
5
|
+
|
6
|
+
# Transliteration heavily based on rutils gem by Julian "julik" Tarkhanov and Co.
|
7
|
+
# <http://rutils.rubyforge.org/>
|
8
|
+
# Cleaned up and optimized.
|
9
|
+
|
10
|
+
LOWER = {
|
11
|
+
"і"=>"i","ґ"=>"g","ё"=>"yo","№"=>"#","є"=>"e",
|
12
|
+
"ї"=>"yi","а"=>"a","б"=>"b",
|
13
|
+
"в"=>"v","г"=>"g","д"=>"d","е"=>"e","ж"=>"zh",
|
14
|
+
"з"=>"z","и"=>"i","й"=>"y","к"=>"k","л"=>"l",
|
15
|
+
"м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r",
|
16
|
+
"с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"h",
|
17
|
+
"ц"=>"ts","ч"=>"ch","ш"=>"sh","щ"=>"sch","ъ"=>"'",
|
18
|
+
"ы"=>"yi","ь"=>"","э"=>"e","ю"=>"yu","я"=>"ya"
|
19
|
+
}.freeze
|
20
|
+
|
21
|
+
UPPER = {
|
22
|
+
"Ґ"=>"G","Ё"=>"YO","Є"=>"E","Ї"=>"YI","І"=>"I",
|
23
|
+
"А"=>"A","Б"=>"B","В"=>"V","Г"=>"G",
|
24
|
+
"Д"=>"D","Е"=>"E","Ж"=>"ZH","З"=>"Z","И"=>"I",
|
25
|
+
"Й"=>"Y","К"=>"K","Л"=>"L","М"=>"M","Н"=>"N",
|
26
|
+
"О"=>"O","П"=>"P","Р"=>"R","С"=>"S","Т"=>"T",
|
27
|
+
"У"=>"U","Ф"=>"F","Х"=>"H","Ц"=>"TS","Ч"=>"CH",
|
28
|
+
"Ш"=>"SH","Щ"=>"SCH","Ъ"=>"'","Ы"=>"YI","Ь"=>"",
|
29
|
+
"Э"=>"E","Ю"=>"YU","Я"=>"YA",
|
30
|
+
}.freeze
|
31
|
+
|
32
|
+
# Transliterate a string with russian characters
|
33
|
+
def transliterate(str)
|
34
|
+
chars = str.split(//)
|
35
|
+
|
36
|
+
result = ""
|
37
|
+
|
38
|
+
chars.each_with_index do |char, index|
|
39
|
+
if UPPER.has_key?(char) && LOWER.has_key?(chars[index+1])
|
40
|
+
# combined case
|
41
|
+
result << UPPER[char].downcase.capitalize
|
42
|
+
elsif UPPER.has_key?(char)
|
43
|
+
result << UPPER[char]
|
44
|
+
elsif LOWER.has_key?(char)
|
45
|
+
result << LOWER[char]
|
46
|
+
else
|
47
|
+
result << char
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
return result
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe Russian do
|
4
|
+
describe "transliteration" do
|
5
|
+
def t(str)
|
6
|
+
Russian::transliterate(str)
|
7
|
+
end
|
8
|
+
|
9
|
+
%w(transliterate translit).each do |method|
|
10
|
+
it "#{method} method should perform transliteration" do
|
11
|
+
str = mock(:str)
|
12
|
+
Russian::Transliteration.should_receive(:transliterate).with(str)
|
13
|
+
Russian.send(method, str)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# These tests are from rutils, <http://rutils.rubyforge.org>.
|
18
|
+
|
19
|
+
it "should transliterate properly" do
|
20
|
+
t("Это просто некий текст").should == "Eto prosto nekiy tekst"
|
21
|
+
t("щ").should == "sch"
|
22
|
+
t("стансы").should == "stansyi"
|
23
|
+
t("упущение").should == "upuschenie"
|
24
|
+
t("ш").should == "sh"
|
25
|
+
t("Ш").should == "SH"
|
26
|
+
t("ц").should == "ts"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should properly transliterate mixed russian-english strings" do
|
30
|
+
t("Это кусок строки русских букв v peremeshku s latinizey i амперсандом (pozor!) & something").should ==
|
31
|
+
"Eto kusok stroki russkih bukv v peremeshku s latinizey i ampersandom (pozor!) & something"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should properly transliterate mixed case chars in a string" do
|
35
|
+
t("НЕВЕРОЯТНОЕ УПУЩЕНИЕ").should == "NEVEROYATNOE UPUSCHENIE"
|
36
|
+
t("Невероятное Упущение").should == "Neveroyatnoe Upuschenie"
|
37
|
+
t("Шерстяной Заяц").should == "Sherstyanoy Zayats"
|
38
|
+
t("Н.П. Шерстяков").should == "N.P. Sherstyakov"
|
39
|
+
t("ШАРОВАРЫ").should == "SHAROVARYI"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: russian
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yaroslav Markin
|
@@ -9,7 +9,7 @@ autorequire: russian
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-11-
|
12
|
+
date: 2008-11-21 00:00:00 +03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -35,6 +35,8 @@ files:
|
|
35
35
|
- lib/russian/action_view_ext/helpers/date_helper.rb
|
36
36
|
- lib/russian/active_record_ext
|
37
37
|
- lib/russian/active_record_ext/custom_error_message.rb
|
38
|
+
- lib/russian/active_support_ext
|
39
|
+
- lib/russian/active_support_ext/parameterize.rb
|
38
40
|
- lib/russian/backend
|
39
41
|
- lib/russian/backend/advanced.rb
|
40
42
|
- lib/russian/core_ext
|
@@ -44,6 +46,7 @@ files:
|
|
44
46
|
- lib/russian/locale/activesupport.yml
|
45
47
|
- lib/russian/locale/datetime.yml
|
46
48
|
- lib/russian/locale/pluralize.rb
|
49
|
+
- lib/russian/transliteration.rb
|
47
50
|
- lib/russian.rb
|
48
51
|
- lib/vendor
|
49
52
|
- lib/vendor/i18n
|
@@ -86,6 +89,7 @@ files:
|
|
86
89
|
- spec/locale_spec.rb
|
87
90
|
- spec/russian_spec.rb
|
88
91
|
- spec/spec_helper.rb
|
92
|
+
- spec/transliteration_spec.rb
|
89
93
|
has_rdoc: true
|
90
94
|
homepage: http://github.com/yaroslav/russian/
|
91
95
|
post_install_message:
|