rails-i18n 0.5.2 → 0.6.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -17,6 +17,19 @@ or run this command:
17
17
 
18
18
  Note that your rails version must be 3.0 or higher if you want to install `rails-i18n` as a gem. For rails 2.x, install it manually as described below.
19
19
 
20
+ ## Configuration
21
+
22
+ By default `rails-i18n` loads all locale files, pluralization and
23
+ transliteration rules available in the gem. This behaviour can be changed, if you
24
+ specify in `config/environments/*` the locales which have to be loaded via
25
+ `I18n.available_locales` option:
26
+
27
+ config.i18n.available_locales = ['es-CO', :de]
28
+
29
+ or
30
+
31
+ config.i18n.available_locales = :nl
32
+
20
33
  ## Manual installation
21
34
 
22
35
  Download the locale files that are found in the directory [rails/locale](http://github.com/svenfuchs/rails-i18n/tree/master/rails/locale/) and put them into the `config/locales` directory of your Rails application.
@@ -2,11 +2,13 @@ require 'rails'
2
2
 
3
3
  module RailsI18n
4
4
  class Railtie < ::Rails::Railtie #:nodoc:
5
- initializer 'rails-i18n' do
5
+ initializer 'rails-i18n' do |app|
6
6
  RailsI18n::Railtie.instance_eval do
7
- add('rails/locale/*.yml')
8
- add('rails/pluralization/*.rb')
9
- add('rails/transliteration/*.{rb,yml}')
7
+ pattern = pattern_from app.config.i18n.available_locales
8
+
9
+ add("rails/locale/#{pattern}.yml")
10
+ add("rails/pluralization/#{pattern}.rb")
11
+ add("rails/transliteration/#{pattern}.{rb,yml}")
10
12
 
11
13
  init_pluralization_module
12
14
  end
@@ -19,6 +21,11 @@ module RailsI18n
19
21
  I18n.load_path.concat(files)
20
22
  end
21
23
 
24
+ def self.pattern_from(args)
25
+ array = Array(args || [])
26
+ array.blank? ? '*' : "{#{array.join ','}}"
27
+ end
28
+
22
29
  def self.init_pluralization_module
23
30
  I18n.backend.class.send(:include, I18n::Backend::Pluralization)
24
31
  end
@@ -1,65 +1,84 @@
1
+ # encoding: utf-8
2
+
1
3
  # (c) Yaroslav Markin, Julian "julik" Tarkhanov and Co
2
4
  # https://github.com/yaroslav/russian/blob/master/lib/russian/transliteration.rb
3
5
 
4
6
  module RailsI18n
5
7
  module Transliteration
6
8
  module Russian
7
- LOWER_SINGLE = {
8
- "і"=>"i","ґ"=>"g","ё"=>"yo","№"=>"#","є"=>"e",
9
- "ї"=>"yi","а"=>"a","б"=>"b",
10
- "в"=>"v","г"=>"g","д"=>"d","е"=>"e","ж"=>"zh",
11
- "з"=>"z","и"=>"i","й"=>"y","к"=>"k","л"=>"l",
12
- "м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r",
13
- "с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"h",
14
- "ц"=>"ts","ч"=>"ch","ш"=>"sh","щ"=>"sch","ъ"=>"'",
15
- "ы"=>"y","ь"=>"","э"=>"e","ю"=>"yu","я"=>"ya",
16
- }
9
+ class << self
10
+ def rule
11
+ lambda do |string|
12
+ chars = string.scan(%r{#{multi_keys.join '|'}|\w|.})
17
13
 
18
- LOWER_MULTI = {
19
- "ье"=>"ie",
20
- "ьё"=>"ie",
21
- }
14
+ result = ""
22
15
 
23
- UPPER_SINGLE = {
24
- "Ґ"=>"G","Ё"=>"YO","Є"=>"E","Ї"=>"YI","І"=>"I",
25
- "А"=>"A","Б"=>"B","В"=>"V","Г"=>"G",
26
- "Д"=>"D","Е"=>"E","Ж"=>"ZH","З"=>"Z","И"=>"I",
27
- "Й"=>"Y","К"=>"K","Л"=>"L","М"=>"M","Н"=>"N",
28
- "О"=>"O","П"=>"P","Р"=>"R","С"=>"S","Т"=>"T",
29
- "У"=>"U","Ф"=>"F","Х"=>"H","Ц"=>"TS","Ч"=>"CH",
30
- "Ш"=>"SH","Щ"=>"SCH","Ъ"=>"'","Ы"=>"Y","Ь"=>"",
31
- "Э"=>"E","Ю"=>"YU","Я"=>"YA",
32
- }
16
+ chars.each_with_index do |char, index|
17
+ if upper.has_key?(char) && lower.has_key?(chars[index+1])
18
+ # combined case
19
+ result << upper[char].downcase.capitalize
20
+ elsif upper.has_key?(char)
21
+ result << upper[char]
22
+ elsif lower.has_key?(char)
23
+ result << lower[char]
24
+ else
25
+ result << char
26
+ end
27
+ end
33
28
 
34
- UPPER_MULTI = {
35
- "ЬЕ"=>"IE",
36
- "ЬЁ"=>"IE",
37
- }
29
+ result
30
+ end
31
+ end
38
32
 
39
- LOWER = (LOWER_SINGLE.merge(LOWER_MULTI)).freeze
40
- UPPER = (UPPER_SINGLE.merge(UPPER_MULTI)).freeze
41
- MULTI_KEYS = (LOWER_MULTI.merge(UPPER_MULTI)).keys.sort_by {|s| s.length}.reverse.freeze
33
+ private
42
34
 
43
- def self.rule
44
- lambda do |string|
45
- chars = string.scan(%r{#{MULTI_KEYS.join '|'}|\w|.})
35
+ # use instance variables instead of constants to prevent warnings
36
+ # on re-evaling after I18n.reload!
46
37
 
47
- result = ""
38
+ def upper
39
+ @upper ||= begin
40
+ upper_single = {
41
+ "Ґ"=>"G","Ё"=>"YO","Є"=>"E","Ї"=>"YI","І"=>"I",
42
+ "А"=>"A","Б"=>"B","В"=>"V","Г"=>"G",
43
+ "Д"=>"D","Е"=>"E","Ж"=>"ZH","З"=>"Z","И"=>"I",
44
+ "Й"=>"Y","К"=>"K","Л"=>"L","М"=>"M","Н"=>"N",
45
+ "О"=>"O","П"=>"P","Р"=>"R","С"=>"S","Т"=>"T",
46
+ "У"=>"U","Ф"=>"F","Х"=>"H","Ц"=>"TS","Ч"=>"CH",
47
+ "Ш"=>"SH","Щ"=>"SCH","Ъ"=>"'","Ы"=>"Y","Ь"=>"",
48
+ "Э"=>"E","Ю"=>"YU","Я"=>"YA",
49
+ }
48
50
 
49
- chars.each_with_index do |char, index|
50
- if UPPER.has_key?(char) && LOWER.has_key?(chars[index+1])
51
- # combined case
52
- result << UPPER[char].downcase.capitalize
53
- elsif UPPER.has_key?(char)
54
- result << UPPER[char]
55
- elsif LOWER.has_key?(char)
56
- result << LOWER[char]
57
- else
58
- result << char
59
- end
51
+ (upper_single.merge(upper_multi)).freeze
52
+ end
53
+ end
54
+
55
+ def lower
56
+ @lower ||= begin
57
+ lower_single = {
58
+ "і"=>"i","ґ"=>"g","ё"=>"yo","№"=>"#","є"=>"e",
59
+ "ї"=>"yi","а"=>"a","б"=>"b",
60
+ "в"=>"v","г"=>"g","д"=>"d","е"=>"e","ж"=>"zh",
61
+ "з"=>"z","и"=>"i","й"=>"y","к"=>"k","л"=>"l",
62
+ "м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r",
63
+ "с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"h",
64
+ "ц"=>"ts","ч"=>"ch","ш"=>"sh","щ"=>"sch","ъ"=>"'",
65
+ "ы"=>"y","ь"=>"","э"=>"e","ю"=>"yu","я"=>"ya",
66
+ }
67
+
68
+ (lower_single.merge(lower_multi)).freeze
60
69
  end
70
+ end
71
+
72
+ def upper_multi
73
+ @upper_multi ||= { "ЬЕ"=>"IE", "ЬЁ"=>"IE" }
74
+ end
75
+
76
+ def lower_multi
77
+ @lower_multi ||= { "ье"=>"ie", "ьё"=>"ie" }
78
+ end
61
79
 
62
- result
80
+ def multi_keys
81
+ @multi_keys ||= (lower_multi.merge(upper_multi)).keys.sort_by {|s| s.length}.reverse.freeze
63
82
  end
64
83
  end
65
84
  end
@@ -0,0 +1,104 @@
1
+ # encoding: utf-8
2
+
3
+ module RailsI18n
4
+ module Transliteration
5
+ module Ukrainian
6
+ class << self
7
+ def rule
8
+ lambda do |string|
9
+ string.gsub(/./) do |char|
10
+ # Regexp.last_match is local to the thread and method scope
11
+ # of the method that did the pattern match.
12
+ @pre_match, @post_match = $`, $'
13
+
14
+ case char
15
+ when 'Ж'
16
+ lookahead_upcase 'ZH'
17
+ when 'Х'
18
+ lookahead_upcase 'KH'
19
+ when 'Ц'
20
+ lookahead_upcase 'TS'
21
+ when 'Ч'
22
+ lookahead_upcase 'CH'
23
+ when 'Ш'
24
+ lookahead_upcase 'SH'
25
+ when 'Щ'
26
+ lookahead_upcase 'SHCH'
27
+ when 'г'
28
+ behind =~ /з/i ? 'gh' : 'h'
29
+ when 'Г'
30
+ behind =~ /з/i ? lookahead_upcase('GH') : 'H'
31
+ when 'є'
32
+ letter?(behind) ? 'ie' : 'ye'
33
+ when 'Є'
34
+ letter?(behind) ? lookahead_upcase('IE') : lookahead_upcase('YE')
35
+ when 'ї'
36
+ letter?(behind) ? 'i' : 'yi'
37
+ when 'Ї'
38
+ letter?(behind) ? 'I' : lookahead_upcase('YI')
39
+ when 'й'
40
+ letter?(behind) ? 'i' : 'y'
41
+ when 'Й'
42
+ letter?(behind) ? 'I' : 'Y'
43
+ when 'ю'
44
+ letter?(behind) ? 'iu' : 'yu'
45
+ when 'Ю'
46
+ letter?(behind) ? lookahead_upcase('IU') : lookahead_upcase('YU')
47
+ when 'я'
48
+ letter?(behind) ? 'ia' : 'ya'
49
+ when 'Я'
50
+ letter?(behind) ? lookahead_upcase('IA') : lookahead_upcase('YA')
51
+ when "'"
52
+ # remove apostrophe inside a word
53
+ letter?(behind) && letter?(ahead) ? '' : "'"
54
+ else
55
+ straight_lookup[char] || char
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ private
62
+
63
+ def behind
64
+ @pre_match && @pre_match[-1]
65
+ end
66
+
67
+ def ahead
68
+ @post_match && @post_match[0]
69
+ end
70
+
71
+ def downcased?(symbol)
72
+ symbol =~ /\p{Ll}/
73
+ end
74
+
75
+ # apostrophe can be inside a word
76
+ # TODO what about hyphen?
77
+ def letter?(symbol)
78
+ symbol =~ /[\p{L}'’]/
79
+ end
80
+
81
+ def lookahead_upcase(word)
82
+ downcased?(ahead) ? word.capitalize : word.upcase
83
+ end
84
+
85
+ def straight_lookup
86
+ @straight_lookup ||= {
87
+ 'а'=>'a','б'=>'b','в'=>'v','ґ'=>'g','д'=>'d','е'=>'e','ж'=>'zh',
88
+ 'з'=>'z','и'=>'y','і'=>'i','к'=>'k','л'=>'l','м'=>'m','н'=>'n','о'=>'o',
89
+ 'п'=>'p','р'=>'r','с'=>'s','т'=>'t','у'=>'u','ф'=>'f','х'=>'kh','ц'=>'ts',
90
+ 'ч'=>'ch','ш'=>'sh','щ'=>'shch','ь'=>'','’'=>'',
91
+ 'А'=>'A','Б'=>'B','В'=>'V','Ґ'=>'G','Д'=>'D','Е'=>'E',
92
+ 'З'=>'Z','И'=>'Y','І'=>'I','К'=>'K','Л'=>'L','М'=>'M','Н'=>'N','О'=>'O',
93
+ 'П'=>'P','Р'=>'R','С'=>'S','Т'=>'T','У'=>'U','Ф'=>'F','Ь'=>''
94
+ }
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ { :uk => {
102
+ :i18n => {
103
+ :transliterate => {
104
+ :rule => RailsI18n::Transliteration::Ukrainian.rule }}}}
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
5
- prerelease:
4
+ version: 0.6.0.beta1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rails I18n Group
@@ -13,7 +13,7 @@ date: 2012-03-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n
16
- requirement: &7075360 !ruby/object:Gem::Requirement
16
+ requirement: &12820520 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0.5'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *7075360
24
+ version_requirements: *12820520
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rails
27
- requirement: &7074420 !ruby/object:Gem::Requirement
27
+ requirement: &12816640 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.0.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *7074420
35
+ version_requirements: *12816640
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec-rails
38
- requirement: &7070380 !ruby/object:Gem::Requirement
38
+ requirement: &12843140 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.7.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *7070380
46
+ version_requirements: *12843140
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: i18n-spec
49
- requirement: &7097700 !ruby/object:Gem::Requirement
49
+ requirement: &12839960 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.1.1
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *7097700
57
+ version_requirements: *12839960
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: spork
60
- requirement: &7094680 !ruby/object:Gem::Requirement
60
+ requirement: &12837560 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 1.0rc
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *7094680
68
+ version_requirements: *12837560
69
69
  description: A set of common locale data and translations to internationalize and/or
70
70
  localize your Rails applications.
71
71
  email: rails-i18n@googlegroups.com
@@ -243,6 +243,7 @@ files:
243
243
  - rails/pluralization/sms.rb
244
244
  - rails/transliteration/ru.rb
245
245
  - rails/transliteration/bg.yml
246
+ - rails/transliteration/uk.rb
246
247
  - rails/transliteration/hu.yml
247
248
  - README.md
248
249
  - MIT-LICENSE.txt