Open dimitrypo opened 11 years ago
The error appearing to you /home/dvporg/.rvm/gems/ruby-2.0.0-p247/gems/i18n-0.6.5/lib/i18n/backend/transliterator.rb:23:in
get': Transliteration rule must be a proc or a hash. (I18n::ArgumentError)` is probably caused by something wrong in your yml files, it seems you are defining invalid Transliteration rules in your yml files.
I may be able to help you If you provide your original yml files.
I was getting this with an empty en.yml file. Adding:
en: i18n: transliterate: rule: ü: "u"
Resolved the issue for me. I think you just need to have at least one transliteration rule defined.
@forrestblount solution didn't work for me. (since this issue is 3 years old, things might've changed.)
I got it working by monkey patching the i18n gem:
Use bundle open i18n
and navigate to lib/i18n/backend/transliterator.rb
On line 16:25 you should see something similar to this:
# Get a transliterator instance.
def self.get(rule = nil)
if !rule || rule.kind_of?(Hash)
HashTransliterator.new(rule)
elsif rule.kind_of? Proc
ProcTransliterator.new(rule)
else
raise I18n::ArgumentError, "Transliteration rule must be a proc or a hash."
end
end
change it to this:
# Get a transliterator instance.
def self.get(rule = nil)
if !rule || rule.kind_of?(Hash)
HashTransliterator.new(rule)
elsif rule.kind_of? Proc
ProcTransliterator.new(rule)
else
HashTransliterator.new({})
end
end
Remember to revert your changes afterwards.
I'm trying to use gem translation_center with rails 3.2.14 I'm following instructions here https://github.com/BadrIT/translation_center
I've done all steps, namely:
Add gem 'translation_center' to gem file, bundle install without any issues. started generator rails generate translation_center:install en id also succesfully Changed translation_center.yaml to include 'id' locale Then run rake:db migrate, migration were success. (I have the same database for dev and production, but rails starting in dev mode anyway.)
On the step: rake translation_center:synch
I see an error:
rake aborted! Transliteration rule must be a proc or a hash. /home/dvporg/.rvm/gems/ruby-2.0.0-p247/gems/i18n-0.6.5/lib/i18n/backend/transliterator.rb:23:in `get' ....
Also the same error whenever I try to use rails (start server, generate migration and so on)
I tried to check my YML files, empty them, deleted them - nothing helps, but if I comment gem 'translation_center' In my gemfile everything start working again.
I managed to run that command succesfullly when I remove completely translations from second locale and left only 10 simple translations strings for test in main locale:
en: new_add_free: Sell for free my_account: My Account start_searching: Start searching select_province: Select province select_category: Select category start_search: Start start_sell_min: Start selling in 1 minute active_ads: Active ads minute_ago: 1 Minute ago today: Today
It seems there were a problem parsing strings that wasn't shown, But after running this command again I've got locale file containing only:
en: {}
despite of during import I've seen: rake translation_center:synch WARNING: You already have translations stored in the db, do you want to destroy them? press [Y|n] y 2 locales available: en, id 365 unique keys found. (I have only 2 files in config/locales, one empty another have only 10 lines) found new 365 key(s) missing 43 translation(s) for en missing 365 translation(s) for id Started exporting translations in en Done exporting translations of en to en.yml Started exporting translations in id Done exporting translations of id to id.yml
When I try to start rails server I got an error again:
/home/dvporg/.rvm/gems/ruby-2.0.0-p247/gems/i18n-0.6.5/lib/i18n/backend/transliterator.rb:23:in `get': Transliteration rule must be a proc or a hash. (I18n::ArgumentError)
I managed to overcome this error by changing : i18n_source: 'db' to i18n_source: 'yml'
But when I finally was able to access to frontand it's also become unusable, the only think I got is this error: http://clip2net.com/s/5AtTgb
Or empty list no matter what I choose:
http://clip2net.com/s/5AtUco
What have I done so terribly wrong that I have so bad experience with this gem and could you please advice how can I solve this situation?
my translation_center.yml: common_atts: &common_atts lang: en: name: 'English' direction: 'ltr' id: name: 'Indonesian' direction: 'ltr' yaml_translator_identifier: 'coder@tc.com' yaml2db_translations_accepted: false # default is false accept_admin_translations: true translator_type: 'AdminUser' # Uncomment and change if you want to change the translator type
development: enabled: true # default false inspector: 'missing' # default missing i18n_source: 'yml' # can be db or yaml; default is db save_default_translation: true <<: *common_atts
production: enabled: true # default false inspector: 'off' # default missing i18n_source: 'yaml' # can be db or yaml; default is yaml save_default_translation: false
<<: *common_atts
Gem file: source 'https://rubygems.org'
gem 'rails', '3.2.14' gem "friendly_id", "~> 4.0.9" gem 'activeadmin' gem "meta_search", '>= 1.1.0.pre' gem 'remotipart', '~> 1.0' gem 'devise' gem 'omniauth' gem 'omniauth-facebook' gem 'fb_graph' gem 'htmlentities' gem 'dalli' gem 'impressionist' gem 'translation_center' gem 'mysql2'
gem "twitter-bootstrap-rails" gem "paperclip", "~> 3.0" gem 'will_paginate' gem 'will_paginate-bootstrap'
Gems used only for assets and not required
in production environments by default.
group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-rails', '~> 3.2.1'
See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3' end
group :development do gem "rails-erd" end
gem "jquery-rails", "2.3.0"
source 'https://rubygems.org'
gem 'rails', '3.2.14' gem "friendly_id", "~> 4.0.9" gem 'activeadmin' gem "meta_search", '>= 1.1.0.pre' gem 'remotipart', '~> 1.0' gem 'devise' gem 'omniauth' gem 'omniauth-facebook' gem 'fb_graph' gem 'htmlentities' gem 'dalli' gem 'impressionist' gem 'translation_center' gem 'mysql2'
gem "twitter-bootstrap-rails" gem "paperclip", "~> 3.0" gem 'will_paginate' gem 'will_paginate-bootstrap'
Gems used only for assets and not required
in production environments by default.
group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-rails', '~> 3.2.1'
See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3' end
group :development do gem "rails-erd" end
gem "jquery-rails", "2.3.0"