Permalink
Browse files

Improvements for 1.8 support

* set unicode mode in railtie too;
* clean up Ukrainian transliteration;
* add 1.8.7 and 1.9.3 MRI to the Travis config.
  • Loading branch information...
1 parent b42bbba commit e3fca5ef12bb2ccdcbc2b4166a7aff61dcbaef22 @nashbridges nashbridges committed Mar 28, 2012
Showing with 39 additions and 15 deletions.
  1. +4 −1 .travis.yml
  2. +1 −0 lib/rails_i18n.rb
  3. +1 −0 lib/rails_i18n/unicode.rb
  4. +31 −10 rails/transliteration/uk.rb
  5. +1 −0 spec/spec_helper.rb
  6. +1 −4 spec/support/transliteration_file.rb
View
@@ -1 +1,4 @@
-rvm: 1.9.2
+rvm:
+ - 1.8.7
+ - 1.9.2
+ - 1.9.3
View
@@ -1 +1,2 @@
+require 'rails_i18n/unicode'
require 'rails_i18n/railtie'
@@ -0,0 +1 @@
+$KCODE = "U" if RUBY_VERSION < '1.9' && $KCODE == 'NONE'
@@ -60,24 +60,45 @@ def rule
private
- def behind
- @pre_match && @pre_match.split(//).last
- end
+ if RUBY_VERSION < '1.9'
+ # two bytes will be enough for Cyrillic
+ class_eval <<-END, __FILE__, __LINE__ + 1
+ def behind
+ tail = @pre_match && @pre_match[-2..-1]
+ tail && tail.split(//).last
+ end
+
+ def ahead
+ @post_match && @post_match[0..1].split(//).first
+ end
+ END
+ else
+ class_eval <<-END, __FILE__, __LINE__ + 1
+ def behind
+ @pre_match && @pre_match[-1]
+ end
- def ahead
- @post_match && @post_match.split(//).first
+ def ahead
+ @post_match && @post_match[0]
+ end
+ END
end
def downcased?(symbol)
- symbol =~ /[гєїйюя]/ ||
- straight_lookup[symbol] =~ /[a-z]/
+ symbol =~ downcased_regexp
+ end
+
+ def downcased_regexp
+ @downcased_regexp ||= /[а-яґєії]/
end
# apostrophe can be inside a word
- # TODO what about hyphen?
def letter?(symbol)
- symbol =~ /[ЖХЦЧШЩгГєЄїЇйЙюЮяЯЬ'’]/ ||
- straight_lookup[symbol] =~ /[a-z]/i
+ symbol =~ letter_regexp
+ end
+
+ def letter_regexp
+ @letter_regexp ||= /[а-яґєіїА-ЯҐЄІЇ'’]/
end
def lookahead_upcase(word)
View
@@ -2,6 +2,7 @@
require 'rspec'
require 'i18n-spec'
+require 'rails_i18n/unicode'
require 'i18n/core_ext/hash'
require 'active_support/core_ext/kernel/reporting'
require 'support/fake_app'
@@ -2,8 +2,6 @@
require 'support/ruby_content'
require 'yaml'
-$KCODE = "U"
-
module RailsI18n
module Spec
class TransliterationFile
@@ -23,8 +21,7 @@ def initialize(filepath)
def rule
@rule ||= begin
- md = @filepath.match(/([\w-]+)\.[^\.]+$/)
- locale = md[1]
+ locale = @filepath.match(/([\w-]+)\.[^\.]+$/)[1]
traverse_path(locale.to_sym, :i18n, :transliterate, :rule)
end
end

0 comments on commit e3fca5e

Please sign in to comment.