Git Product home page Git Product logo

gettext_i18n_rails's Introduction

FastGettext / Rails integration.

Translate via FastGettext, use any other I18n backend as extension/fallback.

Rails does: I18n.t('syntax.with.lots.of.dots') with nested yml files We do: _('Just translate my damn text!') with simple, flat mo/po/yml files or directly from db To use I18n calls add a syntax.with.lots.of.dots translation.

See it working in the example application.

Setup

Installation

# Gemfile
gem 'gettext_i18n_rails'
Optional:

Add gettext if you want to find translations or build .mo files
Add ruby_parser if you want to find translations inside haml/slim files

# Gemfile
gem 'gettext', '>=3.0.2', :require => false
gem 'ruby_parser', :require => false, :group => :development
Add first language:

Add the first language using:

rake gettext:add_language[XX]

or

LANGUAGE=[XX] rake gettext:add_language

where XX is the ISO 639-1 2-letter code for the language you want to create.

This will also create the locale directory (where the translations are being stored) and run gettext:find to find any strings marked for translation.

You can, of course, add more languages using the same command.

Locales & initialisation

Copy default locales with dates/sentence-connectors/AR-errors you want from e.g. rails i18n into 'config/locales'

To initialize:

# config/initializers/fast_gettext.rb
FastGettext.add_text_domain 'app', :path => 'locale', :type => :po
FastGettext.default_available_locales = ['en','de'] #all you want to allow
FastGettext.default_text_domain = 'app'

And in your application:

# app/controllers/application_controller.rb
class ApplicationController < ...
  before_action :set_gettext_locale

Translating

Performance is almost the same for all backends since translations are cached after first use.

Option A: .po files

FastGettext.add_text_domain 'app', :path => 'locale', :type => :po
  • use some _('translations')
  • run rake gettext:find, to let GetText find all translations used
  • (optional) run rake gettext:store_model_attributes, to parse the database for columns that can be translated
  • if this is your first translation: cp locale/app.pot locale/de/app.po for every locale you want to use
  • translate messages in 'locale/de/app.po' (leave msgstr blank and msgstr == msgid)

New translations will be marked "fuzzy", search for this and remove it, so that they will be used. Obsolete translations are marked with ~#, they usually can be removed since they are no longer needed

Unfound translations with rake gettext:find

Dynamic translations like _("x"+"u") cannot be found. You have 4 options:

  • add N_('xu') somewhere else in the code, so the parser sees it
  • add N_('xu') in a totally separate file like locale/unfound_translations.rb, so the parser sees it
  • use the gettext_test_log rails plugin to find all translations that where used while testing
  • add a Logger to a translation Chain, so every unfound translations is logged (example)

Option B: Traditional .po/.mo files

FastGettext.add_text_domain 'app', :path => 'locale'
  • follow Option A
  • run rake gettext:pack to write binary GetText .mo files

Option C: Database

Most scalable method, all translators can work simultaneously and online.

Easiest to use with the translation database Rails engine. Translations can be edited under /translation_keys

FastGettext::TranslationRepository::Db.require_models
FastGettext.add_text_domain 'app', :type => :db, :model => TranslationKey

I18n

I18n.locale <==> FastGettext.locale.to_sym
I18n.locale = :de <==> FastGettext.locale = 'de'

Any call to I18n that matches a gettext key will be translated through FastGettext.

Namespaces

Car|Model means Model in namespace Car. You do not have to translate this into english "Model", if you use the namespace-aware translation

s_('Car|Model') == 'Model' #when no translation was found

XSS / html_safe

If you trust your translators and all your usages of % on translations:

# config/environment.rb
GettextI18nRails.translations_are_html_safe = true

String % vs html_safe is buggy
My recommended fix is: require 'gettext_i18n_rails/string_interpolate_fix'

  • safe stays safe (escape added strings)
  • unsafe stays unsafe (do not escape added strings)

ActiveRecord - error messages

ActiveRecord error messages are translated through Rails::I18n, but model names and model attributes are translated through FastGettext. Therefore a validation error on a BigCar's wheels_size needs _('big car') and _('BigCar|Wheels size') to display localized.

The model/attribute translations can be found through rake gettext:store_model_attributes, (which ignores some commonly untranslated columns like id,type,xxx_count,...).

Error messages can be translated through FastGettext, if the ':message' is a translation-id or the matching Rails I18n key is translated.

Option A:

Define a translation for "I need my rating!" and use it as message.

validates_inclusion_of :rating, :in=>1..5, :message=>N_('I need my rating!')

Option B:

validates_inclusion_of :rating, :in=>1..5

Make a translation for the I18n key: activerecord.errors.models.rating.attributes.rating.inclusion

Option C:

Add a translation to each config/locales/*.yml files

en:
  activerecord:
    errors:
      models:
        rating:
          attributes:
            rating:
              inclusion: " -- please choose!"

The rails I18n guide can help with Option B and C.

Plurals

FastGettext supports pluralization

n_('Apple','Apples',3) == 'Apples'

Abnormal plurals like e.g. Polish that has 4 different can also be addressed, see FastGettext Readme

Customizing list of translatable files

When you run

rake gettext:find

by default the following files are going to be scanned for translations: {app,lib,config,locale}/**/*.{rb,erb,haml,slim}. If you want to specify a different list, you can redefine files_to_translate in the gettext namespace in a file like lib/tasks/gettext.rake:

namespace :gettext do
  def files_to_translate
    Dir.glob("{app,lib,config,locale}/**/*.{rb,erb,haml,slim,rhtml}")
  end
end

Customizing text domains setup task

By default a single application text domain is created (named app or if you load the environment the value of FastGettext.text_domain is being used).

If you want to have multiple text domains or change the definition of the text domains in any way, you can do so by overriding the :setup task in a file like lib/tasks/gettext.rake:

# Remove the provided gettext setup task
Rake::Task["gettext:setup"].clear

namespace :gettext do
  task :setup => [:environment] do
    domains = Application.config.gettext["domains"]

    domains.each do |domain, options|
      files = Dir.glob(options["paths"])

      GetText::Tools::Task.define do |task|
        task.package_name = options["name"]
        task.package_version = "1.0.0"
        task.domain = options["name"]
        task.po_base_directory = locale_path
        task.mo_base_directory = locale_path
        task.files = files
        task.enable_description = false
        task.msgmerge_options = gettext_msgmerge_options
        task.msgcat_options = gettext_msgcat_options
        task.xgettext_options = gettext_xgettext_options
      end
    end
  end
end

Changing msgmerge, msgcat, and xgettext options

The default options for parsing and create .po files are:

--sort-by-msgid --no-location --no-wrap

These options sort the translations by the msgid (original / source string), don't add location information in the po file and don't wrap long message lines into several lines.

If you want to override them you can put the following into an initializer like config/initializers/gettext.rb:

Rails.application.config.gettext_i18n_rails.msgmerge = %w[--no-location]
Rails.application.config.gettext_i18n_rails.msgcat = %w[--no-location]
Rails.application.config.gettext_i18n_rails.xgettext = %w[--no-location]

or

Rails.application.config.gettext_i18n_rails.default_options = %w[--no-location]

to override both.

You can see the available options by running rgettext -h, rmsgcat -f and rxgettext -h.

Use I18n instead Gettext to ActiveRecord/ActiveModel translations

If you want to disable translations to model name and attributes you can put the following into an initializer like config/initializers/gettext.rb:

Rails.application.config.gettext_i18n_rails.use_for_active_record_attributes = false

And now you can use your I18n yaml files instead.

Using your translations from javascript

If want to use your .PO files on client side javascript you should have a look at the GettextI18nRailsJs extension.

Michael Grosser
[email protected]
License: MIT
Build Status

gettext_i18n_rails's People

Contributors

adam-h avatar bryant1410 avatar cameel avatar dmacvicar avatar grosser avatar ifarkas avatar jeroenknoops avatar jpleppers avatar jrafanie avatar martinpovolny avatar maximeg avatar mezis avatar nehresma avatar nikosd avatar nubis avatar petergoldstein avatar psy-q avatar pupeno avatar pwim avatar rainux avatar retoo avatar sampokuokkanen avatar sebbacon avatar splattael avatar sskirby avatar tagoh avatar tma avatar trongrg avatar vitaly avatar voxik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gettext_i18n_rails's Issues

rails not rendering correct localized views -- Roberto Romero

OK, I discovered another "trick". If you ever use localized views (where you have index.es.html.erb and index.en.html.erb and rails decides the view to use based in the locale) you will discover that the translations shows right (the _ strings) but rails chooses the view file at random. This is because rails hooks the function I18n uses to save its config and, when I18n updates its config, rails expires the cache.
Pasting from actionpack-3.0.4/lib/abstract_controller/rendering.rb (line 13, but the interesting method is in line 28)
# This is a class to fix I18n global state. Whenever you provide I18n.locale during a request,
# it will trigger the lookup_context and consequently expire the cache.
# TODO Add some deprecation warnings to remove I18n.locale from controllers

So, I recommend you to add the line:
I18n.config.locale = new_locale
at the end of the locale= method, in lib/gettext_i18n_rails/i18n_hacks.rb

haml does not seem to support string substitution

When I have a haml file with

= _("%{sub} test" % {:sub => "foo"})

The string is not picked up by rake gettext:find
however, when I have the same string in an erb file

<%= _("%{sub} test" % {:sub => "foo"}) %>

It is found.

Load plugin after rails is initialized, so that gem dependencies can be installed

This plugin requires the fastgettext gem, and it tries to load it when initialized. This is a problem, because it is not possible to configure the gem dependencies in environment.rb and run "rake gems:install". If the gettext_i18n_rails plugin is installed in the project, developers need to first install grosser-fast_gettext manually before running "rake gems:install".

The solution is to load the plugin after the initialization process, so that Rails detects that the grosser-fast_gettext gem is required before the plugin crashes while trying to load it. This is a simple change in 'gettext_i18n_rails/init.rb':

config.after_initialize do
require 'gettext_i18n_rails'
end

The text domain is not used when generating po files.

Not sure if this is a bug, but the text domain seems to be ignored when generating the po files. I configured my app to work in the "lemonfrog" text domain and everything was generated in the "app" text domain.

find_files_in_locale_folders: path locale cound not be found

Hello,

Wanted to try the gem, but get this error when I lunch "rails server"

/Users/Maxz/.rvm/gems/ruby-1.9.2-p290@rails311/gems/fast_gettext-0.6.4/lib/fast_gettext/translation_repository/base.rb:36:in `find_files_in_locale_folders': path locale cound not be found! (RuntimeError)

Thank you for your help !

textdomain in rake task is mandatory?

I tried to use in Rails 3 gettext_i18n_rails and sunspot (gem, which add solr - search engine),
but when I want to start it - rake sunspot:solr:start
I get Current textdomain (nil) was not added, use FastGettext.add_text_domain !
In trace it seems, that rake calls i18n
...
/usr/lib/ruby/gems/1.8/gems/gettext_i18n_rails-0.2.17/lib/gettext_i18n_rails/backend.rb:17:in 'translate'

/usr/lib/ruby/gems/1.8/gems/i18n-0.5.0/lib/i18n.rb:155:in 'translate'

/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/core_ext/array/conversions.rb:13:in 'to_sentence'

/usr/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/plugin.rb:50:in 'load_deprecated_tasks'
....

Is any way to circumvent it? rake sunspot:solr:start doesn't use Rails 3, it should only start instance of solr

Task for adding new translatations

gettext_i18n_rails is awesome, I'm removing and cleaning up a lot of code thanks to it. In my TODO list I have an entry for creating a Rake task to create new translations. I know it's very easy to do manually, but why not make it simpler for people getting started with gettext?

This is what I have:

mkdir #{locale_dir}/#{language_code}
msginit --locale=#{language_code} --input=#{locale_dir}/#{text_domain}.pot --output=#{locale_dir}/#{language_code}/#{text_domain}.po

Use Array.wrap instead of to_a for ruby 1.9 compatibility

Using ruby 1.9.2 to_a was removed on String
I use rails 3.0 but i think it is also the case with a lower version

c= Company.new
=> #<Company id: nil, name: "", code: "", created_at: nil, updated_at: nil>
c.save
=> false
c.errors.full_messages
NoMethodError: undefined method to_a' for "{{attribute}} {{message}}":String from /home/hery/Devel/Rails/hutbay/vendor/plugins/gettext_i18n_rails/lib/gettext_i18n_rails/backend.rb:23:intranslate'
from /home/hery/Jail/lib/ruby/gems/1.9.1/gems/i18n-0.3.6/lib/i18n.rb:235:in translate' from /home/hery/Software/rails/activemodel/lib/active_model/errors.rb:224:inblock (2 levels) in full_messages'
from /home/hery/Software/rails/activemodel/lib/active_model/errors.rb:223:in each' from /home/hery/Software/rails/activemodel/lib/active_model/errors.rb:223:inblock in full_messages'
from /home/hery/Software/rails/activemodel/lib/active_model/errors.rb:113:in block (2 levels) in each' from /home/hery/Software/rails/activemodel/lib/active_model/errors.rb:113:ineach'
from /home/hery/Software/rails/activemodel/lib/active_model/errors.rb:113:in block in each' from /home/hery/Software/rails/activemodel/lib/active_model/errors.rb:112:ineach_key'
from /home/hery/Software/rails/activemodel/lib/active_model/errors.rb:112:in each' from /home/hery/Software/rails/activemodel/lib/active_model/errors.rb:212:infull_messages'
from (irb):3
from /home/hery/Software/rails/railties/lib/rails/commands/console.rb:47:in start' from /home/hery/Software/rails/railties/lib/rails/commands/console.rb:8:instart'
from /home/hery/Software/rails/railties/lib/rails/commands.rb:34:in <top (required)>' from script/rails:9:inrequire'
from script/rails:9:in `

'>> c.errors

I made a gist here for patch : git://gist.github.com/360661.git
http://gist.github.com/360661

So Rails uses Array.wrap

I didn't write a test : it is trivial

Problems when rendering internal error

I haven't found a a way to prevent rails from throwing a 'FastGettext::Storage::NoTextDomainConfigured' when a internal/severe error occurs.

Usually this happens when I request a action with the wrong method, the usual error would be 'this method not support', but instead I get:

FastGettext::Storage::NoTextDomainConfigured (Current textdomain (nil) was not added, use FastGettext.add_text_domain !):

My only guess is that this happens ways before the before_filter can chose a sensible textdomain.

You can reproduce this problem by taking your example application and replace the following line in the routes.rb and then access a car's check method with a normal get request.

ActionController::Routing::Routes.draw do |map|
-    map.resources :cars
+    map.resources :cars, :member => {:check => :post}

I've tried setting a fixed textdomain at various points, like in env.rb or in the intializer, but somehow nothing appears to work.

Can you help me with that?

Locale Specific Templates broken

I have two locale specific templates

support/index.en.html.haml
support/index.ja.html.haml

gettext_i18n_rails breaks this in a very strange way. When I switch from en to ja, the first request displays the en template, even though I18n.locale is ja. Subsequent requests are fine. The reverse is true as well (when switching from ja to en).

will paginate gem seems to override gettext_i18n_rails activerecord method

Just an FYI really, haven't looked into it properly yet, but if I have both will_paginate and gettext_i18n_rails initialised in my environment.rb file using Rails 2.3.14, ruby 1.8.7, the rake task store_model_attributes won't work.

I think will_paginate is monkey patching the method_missing method in ActiveRecord and this gets intercepted before gettext_i18n_rails gets to it.

Have just resorted to adding :lib => false in environment.rb to will_paginate while I run this rake task:

config.gem 'will_paginate', :lib => false, :version => '2.3.16'

Otherwise here's what I get:

writing model translations to: locale/model_attributes.rb
[Error] Attribute extraction failed. Removing incomplete file (locale/model_attributes.rb)
rake aborted!
undefined method gettext_translation_for_attribute_name' for #<Class:0x8a0e760> .../vendor/rails/activerecord/lib/active_record/base.rb:1998:inmethod_missing_without_paginate'
.../vendor/gems/will_paginate-2.3.16/lib/will_paginate/finder.rb:170:in method_missing' .../vendor/gems/gettext_i18n_rails-0.4.0/lib/gettext_i18n_rails/model_attributes_finder.rb:20:instore_model_attributes'
.../vendor/gems/gettext_i18n_rails-0.4.0/lib/gettext_i18n_rails/model_attributes_finder.rb:19:in each' .../vendor/gems/gettext_i18n_rails-0.4.0/lib/gettext_i18n_rails/model_attributes_finder.rb:19:instore_model_attributes'
.../vendor/gems/gettext_i18n_rails-0.4.0/lib/gettext_i18n_rails/model_attributes_finder.rb:8:in each' .../vendor/gems/gettext_i18n_rails-0.4.0/lib/gettext_i18n_rails/model_attributes_finder.rb:8:instore_model_attributes'
.../vendor/gems/gettext_i18n_rails-0.4.0/lib/gettext_i18n_rails/model_attributes_finder.rb:6:in open' .../vendor/gems/gettext_i18n_rails-0.4.0/lib/gettext_i18n_rails/model_attributes_finder.rb:6:instore_model_attributes'
.../lib/tasks/i18n.rake:11

Interpolate method throws "NameError: uninitialized constant I18n::Backend::Base" in Rails 2.2

The Rails 2.2 version of i18n doesn't include the constant I18n::Backend::Base::RESERVED_KEYS which is called on line 52 of the in the backend. I got around the error but creating a rails initializer that defined the RESERVED_KEYS in I18n used by rails 3.

module I18n
  RESERVED_KEYS = [:scope, :default, :separator, :resolve, :object, :fallback, :format, :cascade, :raise, :rescue_format]
end

"GettextI18nRails::SlimParser#parse finds messages in slim" test fails with 0.4.3

With ruby 1.8.7 (2011-12-28 patchlevel 357) [x86_64-linux] I'm getting this failure:

  1) GettextI18nRails::SlimParser#parse finds messages in slim
     Failure/Error: ]
       expected: [["xxxx", "/var/tmp/portage/dev-ruby/gettext_i18n_rails-0.4.3/temp/gettext_i18n_rails_specs20120114-7013-1rn2cz9-0:1"]]
            got: [] (using ==)
       Diff:
       @@ -1,3 +1,2 @@
       -[["xxxx",
       -  "/var/tmp/portage/dev-ruby/gettext_i18n_rails-0.4.3/temp/gettext_i18n_rails_specs20120114-7013-1rn2cz9-0:1"]]
       +[]
     # ./spec/gettext_i18n_rails/slim_parser_spec.rb:22
     # ./spec/gettext_i18n_rails/slim_parser_spec.rb:19

Hi

I am getting
uninitialized constant I18n::Backend::Base
this error while i am using gettext_i18n_rails gem and this throws an exception while i select a language other then english and try clicking a button whose action is to show error when a specific field i.e name which is necessary is left blank. kindly help me i am badly stuck in it :(

Do not force 'ruby_parser' as runtime dependency

Hello,

In commit [1], you have added 'ruby_parser' as a runtime dependency. However, it should be development dependency IMO, since rake task is not typically required for Rails application Runtime. Could you please use "add_development_dependency" in place of "add_dependency"? According to the commit message, it was probably also the original author intention.

[1] 5cb25b0

rake gettext not listed

Hi,

I'm trying to implement gettext in my app and I'm a bit confused. First of all, there are gettext, gettext_i18n_rails and fast_gettext. The last two projects document different implementations. Which one should I follow in a Rails 3.1 app?

I tried your exemple application and rake gettext -T returns something. Though, with the same gems fast_gettext and gettext but not gettext_i18n_rails, I don't get nothing with a rake gettext -T. I tried bundle update, restarting the app... everything I can think of.

If I had the gettext_i18n_rails gem, I get the rake methods (with the same error as bug #42) and these errors appear:

    Creating scope :page. Overwriting existing method User.page.
    Creating scope :page. Overwriting existing method Internship.page.
    Creating scope :page. Overwriting existing method Globalize::ActiveRecord::Translation.page.
    Creating scope :page. Overwriting existing method .page.
    Creating scope :page. Overwriting existing method Offer.page.
    Creating scope :page. Overwriting existing method Favourite.page.

Regarding configuration, I have a fast_gettext.rb initializer:
FastGettext.add_text_domain 'app', :path => 'locale'
FastGettext.default_available_locales = ['en','fr']
FastGettext.default_text_domain = 'app'

And environment.rb has:
GettextI18nRails.translations_are_html_safe = true

Do you have any idea of what is going on? Thanks

I18n::Config doesn't exist in Rails 2.3.5

I had to modify the first line of i18n_hacks.rb to read
I18n::Config if defined? I18n::Config # autoload
in order to make this work with Rails 2.3.5. I hope that I didn't inadvertly broke something else.

Some translations are ignored

Hi,

I have a weird bug where some translations are ignored. The translations in question are surrounded by other translations that all work. There is nothing fancy about them, for instance I have Get promoted at Poly, UQàM....

Obviously, I'm sure they are translated.

Is it something you've ever experienced?

rake gettext:pack should load environment

As the title says, "rake gettext:pack" should load the rails enviroment like the other rake tasks do.

Otherwise the initializers don't get executed and configurations like a custom locale path is not loaded.

rake gettext:store_model_attributes does not work when globalize3 in Gemfile

backtrack

[Error] Attribute extraction failed. Removing incomplete file (locale/model_attributes.rb)
rake aborted!
Mysql2::Error: Incorrect table name '': SHOW FULL FIELDS FROM ``
/Users/ldb/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `query'
/Users/ldb/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `block in execute'
/Users/ldb/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.4/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/Users/ldb/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/ldb/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.4/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/Users/ldb/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in `execute'
/Users/ldb/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.4/lib/active_record/connection_adapters/mysql2_adapter.rb:211:in `execute'
/Users/ldb/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:257:in `execute_and_free'
/Users/ldb/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:424:in `columns'
/Users/ldb/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.4/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'
/Users/ldb/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.4/lib/active_record/model_schema.rb:228:in `yield'
/Users/ldb/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.4/lib/active_record/model_schema.rb:228:in `default'
/Users/ldb/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.4/lib/active_record/model_schema.rb:228:in `columns'
/Users/ldb/.rvm/gems/ruby-1.9.3-p194/gems/gettext_i18n_rails-0.5.4/lib/gettext_i18n_rails/model_attributes_finder.rb:42:in `block in find'
/Users/ldb/.rvm/gems/ruby-1.9.3-p194/gems/gettext_i18n_rails-0.5.4/lib/gettext_i18n_rails/model_attributes_finder.rb:38:in `each'
/Users/ldb/.rvm/gems/ruby-1.9.3-p194/gems/gettext_i18n_rails-0.5.4/lib/gettext_i18n_rails/model_attributes_finder.rb:38:in `find'
/Users/ldb/.rvm/gems/ruby-1.9.3-p194/gems/gettext_i18n_rails-0.5.4/lib/gettext_i18n_rails/model_attributes_finder.rb:11:in `block in store_model_attributes'
/Users/ldb/.rvm/gems/ruby-1.9.3-p194/gems/gettext_i18n_rails-0.5.4/lib/gettext_i18n_rails/model_attributes_finder.rb:9:in `open'
/Users/ldb/.rvm/gems/ruby-1.9.3-p194/gems/gettext_i18n_rails-0.5.4/lib/gettext_i18n_rails/model_attributes_finder.rb:9:in `store_model_attributes'
/Users/ldb/.rvm/gems/ruby-1.9.3-p194/gems/gettext_i18n_rails-0.5.4/lib/gettext_i18n_rails/tasks.rb:80:in `block (2 levels) in <top (required)>'
/Users/ldb/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/ldb/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/ldb/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'

then model Globalize::ActiveRecord::Translation(abstract) has not table

undefined method `force_encoding' for 0:Fixnum

I am migrating from Rails simple i18n to this gem. I already have some translations in my templates that use the Rails syntax, t(). And after I load this gem, I get the force_encoding error form them. Is there a way of using the Rails functions alongside the _() methods?

I'm using Ruby 1.9.3-p194

Underscores and hyphens confuse Rails I18n

It seems trying to set I18n.locale to e.g. "en-GB" will break in many possible ways:

Underscores in file names

Setting I18n.locale = "en_GB".to_sym is ignored unless the directories inside locale have names with underscores. So having these directories:

locale/en_GB
locale/en_US

will work, whereas having these directories:

locale/en-GB
locale/en-US

Will not allow setting I18n.locale to anything. Setting I18n.locale = "en-US".to_sym will return :"en-US" as if it had worked, but in reality nothing will be set, I18n.locale will still be set to whatever it was before. This can be seen here:

https://gist.github.com/2635349

Can't set locale for I18n and Gettext

If the locale files are renamed to e.g. locale/en_GB so they match the gettext convetion, this breaks the rest of Rails' I18n. Using the default Rails I18n files, which define en en-GB namespace (not an en_GB one) will break all date formatting and other localizations that are supposed to come from the config/locales/foo.yml files.

The error is:

translation missing: en_GB.leihs.date.formats.day_long

What's worse, even when we set I18n.locale to "en-GB" instead of "en_GB", the error will be for en_GB because FastGettext seems to do some replacement of the underscores internally (?).

So the question is, can Gettext not coexist with Rails I18n .yml files? We want to use Gettext for translations, but Rails' built-in localizations for date and time.

problems with "rake gettext:store_model_attributes"

running the rake task causes a few errors, here is a patch

[PATCH] Fix rake gettext:store_model_attributes


---
 lib/gettext_i18n_rails/model_attributes_finder.rb |    2 ++
 lib/gettext_i18n_rails/tasks.rb                   |    1 +
 2 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/lib/gettext_i18n_rails/model_attributes_finder.rb b/lib/gettext_i18n_rails/model_attributes_finder.rb
index 951770a..67b1fdf 100644
--- a/lib/gettext_i18n_rails/model_attributes_finder.rb
+++ b/lib/gettext_i18n_rails/model_attributes_finder.rb
@@ -1,4 +1,6 @@
 module GettextI18nRails
+  module_function
+  
   #write all found models/columns to a file where GetTexts ruby parser can find them
   def store_model_attributes(options)
     file = options[:to] || 'locale/model_attributes.rb'
diff --git a/lib/gettext_i18n_rails/tasks.rb b/lib/gettext_i18n_rails/tasks.rb
index 100d0ac..b41c565 100644
--- a/lib/gettext_i18n_rails/tasks.rb
+++ b/lib/gettext_i18n_rails/tasks.rb
@@ -64,6 +64,7 @@ namespace :gettext do
   task :store_model_attributes => :environment do
     FastGettext.silence_errors
     require 'gettext_i18n_rails/model_attributes_finder'
+    require 'gettext_i18n_rails/active_record'
     storage_file = 'locale/model_attributes.rb'
     puts "writing model translations to: #{storage_file}"
     ignore_tables = [/^sitemap_/, /_versions$/, 'schema_migrations', 'sessions']
-- 

:message not translated in activerecord validations

We are working on project and have adopted getttext_i18n_rails/fast_gettext for our project. In that time all worked fine. But now we have an issue with localization of rails validation. As storage engine we use gettext. We have several languages: 'en', 'ba', 'ru'... and a lot of code like this:

class User < ActiveRecord::Base
validates_presence_of :title, :message => N_('is required')
end

Some time ago if we change locale than validation was correct. But now it does not work :(. For example if current locale 'ba', and I try to save object without title the validation message is "translation missing: ba.activerecord.errors.messages.record_invalid". Because of a lot of code in our project it is not easy to change each message and than re-translate all catalogs we have. Is there any way to force previous behavior? I seem that this issue became after several updates of the plugin, didn't it?

human_attribute_name for foreign keys

Here's a code snippet using Rails 3 without gettext_i18n_rails:

pry(main)> ItemFamily.human_attribute_name("customer_id")
=> "Customer"

And here's what we get when we use gettext_i18n_rails:

pry(main)> ItemFamily.human_attribute_name("customer_id")
=> "Customer id"

We would like for the human_attribute_name to drop the "id", so we don't need to introduce an English translation for mapping "Customer id" to "Customer".

This could be as simple as using the following implementation:

module GettextI18nRails::ActiveRecord
  def gettext_translation_for_attribute_name(attribute)
    #"#{self}|#{attribute.to_s.split('.').map! {|a| a.gsub('_',' ').capitalize }.join('|')}" #OLD IMPLEMENTATION
    "#{self}|#{attribute.to_s.split('.').map! {|a| a.humanize }.join('|')}"
  end
end

Are there any problems with this? If there aren't, we can submit a pull request.

silence_errors causes change of locale_path ? -- Roberto Romero

I think I found a bug in gettext_i18n_rails. Calling
FastGettext.silence_errors in task "store_model_attributes" (file
lib/gettext_i18n_rails/tasks.rb) undefines the locale_path. This causes
the task to try to write the model_attributes.rb in the root folder of
the filesystem.

rake gettext:find aborts with "uninitialized constant FastGettext"

I am installing gettext_i18n_rails as a gem (but not with bundler). Traceback:

/home/aht/.rvm/gems/ruby-1.8.7-p249/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:443:in `load_missing_constant'
/home/aht/.rvm/gems/ruby-1.8.7-p249/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing'
/home/aht/.rvm/gems/ruby-1.8.7-p249/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:92:in `const_missing'
/home/aht/.rvm/gems/ruby-1.8.7-p249/gems/gettext_i18n_rails-0.2.0/lib/gettext_i18n_rails/tasks.rb:110:in `text_domain'
/home/aht/.rvm/gems/ruby-1.8.7-p249/gems/gettext_i18n_rails-0.2.0/lib/gettext_i18n_rails/tasks.rb:23
/home/aht/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/home/aht/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/home/aht/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/home/aht/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/home/aht/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/home/aht/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/home/aht/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/home/aht/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/home/aht/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/home/aht/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/home/aht/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/home/aht/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/home/aht/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/home/aht/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/home/aht/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/home/aht/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/home/aht/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/home/aht/.rvm/gems/ruby-1.8.7-p249/gems/rake-0.8.7/bin/rake:31
/home/aht/.rvm/gems/ruby-1.8.7-p249/bin/rake:19:in `load'
/home/aht/.rvm/gems/ruby-1.8.7-p249/bin/rake:19

It seems FastGettext is not loaded when "rake gettext:find" is called. I get it to run by adding "require 'fast_gettext'" in the file "lib/gettext_i18n_rails/tasks.rb".

Everything else works fine. Thanks for the gem!

DelayedJob (delayed_jobs table) should be ignored by the finder

--- /tmp/tasks.rb   2010-08-25 16:06:27.789991256 +0200
+++ /usr/lib/ruby/gems/1.8/gems/gettext_i18n_rails-0.2.2/lib/gettext_i18n_rails/tasks.rb    2010-08-25 16:07:11.705994900 +0200
@@ -69,7 +69,7 @@
     storage_file = 'locale/model_attributes.rb'
     puts "writing model translations to: #{storage_file}"

-    ignore_tables = [/^sitemap_/, /_versions$/, 'schema_migrations', 'sessions']
+    ignore_tables = [/^sitemap_/, /_versions$/, 'schema_migrations', 'sessions', 'delayed_jobs']
     GettextI18nRails.store_model_attributes(
       :to => storage_file,
       :ignore_columns => [/_id$/, 'id', 'type', 'created_at', 'updated_at'],

Extend the gettext parser to allow custom calls

I've written wrappers around _() that supports parameters, like so:

my_( N_("Hello %{name}, you have %{num} messages"), name, msgcount )
# shorthand for _("Hello %{name}, you have %{num} messages") % {:name => name, :num => msgcount}

myn_( Nn_("%{num} message", "%{num} messages"), msgcount )
# shorthand for n_("%{num} message", "%{num} messages", msgcount) % {:num => msgcount}

But it'd be so much nicer if I could just write this:

my_("Hello %{name}, you have %{num} messages", name, msgcount)
myn_("%{num} message", "%{num} messages", msgcount)

This would become possible if we could customize what tokens trigger a translatable string to be generated. I see it hardcoded in the ruby gettext extractor right now; any thoughts on the best way to extract this list of tokens to somewhere user-accessible?

gettext 2.3.0 breaks rake gettext:find

Hi, Im not sure if this is the right place to submit this bug, if it's wrong, i apologize.

The rake task "gettext:find" is not working on the latest gettext versions 2.3.0/2.3.1 (released 2-3 days ago)

Works fine on 2.2.1

This is the error:

$ rake gettext:find --trace
WARNING: Nokogiri was built against LibXML version 2.8.0, but has dynamically loaded 2.7.3
** Invoke gettext:find (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute gettext:find
rake aborted!
cannot load such file -- gettext/rgettext
/Users/fred/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
/Users/fred/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `block in require'
/Users/fred/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/fred/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
/Users/fred/.rvm/gems/ruby-1.9.3-p194/gems/gettext_i18n_rails-0.6.6/lib/gettext_i18n_rails/base_parser.rb:5:in `rescue in <top (required)>'
/Users/fred/.rvm/gems/ruby-1.9.3-p194/gems/gettext_i18n_rails-0.6.6/lib/gettext_i18n_rails/base_parser.rb:2:in `<top (required)>'
/Users/fred/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
/Users/fred/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `block in require'
/Users/fred/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/fred/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
/Users/fred/.rvm/gems/ruby-1.9.3-p194/gems/gettext_i18n_rails-0.6.6/lib/gettext_i18n_rails/haml_parser.rb:1:in `<top (required)>'
/Users/fred/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
/Users/fred/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `block in require'
/Users/fred/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/fred/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
/Users/fred/.rvm/gems/ruby-1.9.3-p194/gems/gettext_i18n_rails-0.6.6/lib/gettext_i18n_rails/tasks.rb:17:in `block (2 levels) in <top (required)>'
/Users/fred/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/fred/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/fred/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/fred/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/fred/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/fred/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/fred/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/fred/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/fred/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/fred/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/fred/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/fred/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/fred/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/fred/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/fred/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/fred/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/fred/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/fred/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/fred/.rvm/gems/ruby-1.9.3-p194@global/bin/rake:19:in `load'
/Users/fred/.rvm/gems/ruby-1.9.3-p194@global/bin/rake:19:in `<main>'
Tasks: TOP => gettext:find

Gemfile that works. if removing the version from gettext, it causes the issues.

    gem 'fast_gettext'
    gem 'gettext_i18n_rails'
    group :development do
      gem 'gettext', "~> 2.2.1", require: false
      gem 'ruby_parser', require: false
      gem 'locale'
    end

Regards.

Problem running `bundle console` with 'gettext_i18n_rails' in Gemfile

In an brand-new Rails app from scratch (rails new .) with a Gemfile as simple as:

source 'http://rubygems.org'
gem 'rails', '3.0.3'
gem 'gettext_i18n_rails'

I get this stack when trying to run bundle console:

/usr/lib/ruby/gems/1.8/gems/gettext_i18n_rails-0.2.11/lib/gettext_i18n_rails/action_controller.rb:1: uninitialized constant ActionController (NameError)
from /usr/lib/ruby/gems/1.8/gems/gettext_i18n_rails-0.2.11/lib/gettext_i18n_rails.rb:26:in require' from /usr/lib/ruby/gems/1.8/gems/gettext_i18n_rails-0.2.11/lib/gettext_i18n_rails.rb:26 from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:inrequire'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in require' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:ineach'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in require' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:ineach'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in require' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler.rb:112:inrequire'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/cli.rb:434:in console' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/task.rb:22:insend'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/task.rb:22:in run' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/invocation.rb:118:ininvoke_task'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor.rb:246:in dispatch' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/base.rb:389:instart'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/bin/bundle:13
from /usr/bin/bundle:19:in `load'
from /usr/bin/bundle:19

Is this a gettext_i18n_rails, rails, bundler or rubygems problem? Where do I look to find out?

Note: did a gem update after getting this problem, but nothing changed.

Splitting po file

Hello.

I would like to split my po file(app.po) into 2 files one for the admin section and other for the public view of my app. How can I do that?. I have been checking text_domain things but I am not able to find the way to do it.

The point is, is there any way to do rake gettext:find and get two different po files even if that requires me some markup work?

Thank you very much.

Best.

Miguel

undefined method `add'

Hello again :)

When I run this in terminal :
$ rake gettext:find

I get this :
rake aborted!
undefined method `add' for "/Users/Maxz/.rvm/gems/ruby-1.9.2-p290@rails311":String

Tasks: TOP => gettext:find
(See full trace by running task with --trace)

No idea where it can come from.

Formal CC0 unlicense declaration

Would you be willing to put down the CC0 unlicense in addition to your existing PD declaration? Would make life easier for jittery legal folk that aren't totally sure public domain stuffs are enforceable.

v0.4.1 and newer can't parse the Ruby 1.9 hash syntax in .slim views

I upgraded from 0.3.6 to 0.4.3, when I called "rake gettext:find" I got an error like this

parse error on value ":" (tCOLON)

rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/racc/parser.rb:351:in `on_error'
(eval):3:in `_racc_do_parse_c'
(eval):3:in `do_parse'
gems/ruby_parser-2.3.1/lib/ruby_parser_extras.rb:759:in `process'
gems/gettext_i18n_rails-0.4.3/lib/gettext_i18n_rails/ruby_gettext_extractor.rb:55:in `run'
gems/gettext_i18n_rails-0.4.3/lib/gettext_i18n_rails/ruby_gettext_extractor.rb:26:in `parse_string'
gems/gettext_i18n_rails-0.4.3/lib/gettext_i18n_rails/slim_parser.rb:20:in `parse'
...

Because in my *.slim views I used 'key: value' instead of ':key => value' syntax.

I downgraded it to v0.4.0, everything works fine.

Someone posted that error occurred because ruby_parser can't parse the ruby 1.9 syntax. But why v0.4.0 and older had no problem?

If this is not an actual issue, could you explain to me why that error raised?

Thank you very much.

Uninitialized constant FastGettext

I'm having this issue, don't know what it is, it's getting me crazy, because I think I've all properly configured. It was working some days ago, but now is broken (Using Mac OS X, Ruby 1.9.2 and Rails 3.2.1).

=> Booting WEBrick
=> Rails 3.2.1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Users/Ruben/Sites/Htdocs/html5videos/trunk/config/initializers/fast_gettext.rb:1:in `<top (required)>': uninitialized constant FastGettext (NameError)
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.2.1/lib/rails/engine.rb:588:in `block (2 levels) in <class:Engine>'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.2.1/lib/rails/engine.rb:587:in `each'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.2.1/lib/rails/engine.rb:587:in `block in <class:Engine>'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.2.1/lib/rails/initializable.rb:30:in `instance_exec'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.2.1/lib/rails/initializable.rb:30:in `run'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.2.1/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.2.1/lib/rails/initializable.rb:54:in `each'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.2.1/lib/rails/initializable.rb:54:in `run_initializers'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.2.1/lib/rails/application.rb:136:in `initialize!'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.2.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/Ruben/Sites/Htdocs/html5videos/trunk/config/environment.rb:5:in `<top (required)>'
    from /Users/Ruben/Sites/Htdocs/html5videos/trunk/config.ru:4:in `block in <main>'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
    from /Users/Ruben/Sites/Htdocs/html5videos/trunk/config.ru:1:in `new'
    from /Users/Ruben/Sites/Htdocs/html5videos/trunk/config.ru:1:in `<main>'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.2.1/lib/rails/commands/server.rb:46:in `app'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:252:in `start'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.2.1/lib/rails/commands/server.rb:70:in `start'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:55:in `block in <top (required)>'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:50:in `tap'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:50:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

My Gemfile is this:

source 'http://rubygems.org'

gem 'rails', "3.2.1"

# Bundle edge Rails instead:
# gem 'rails',     :git => 'git://github.com/rails/rails.git'

gem 'mysql2'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  #gem 'sass-rails', "3.1.4"
  gem 'sass-rails'
  gem 'coffee-rails'
  #gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
end

gem 'jquery-rails'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

group :test do
  # Pretty printed test output
  gem 'turn', :require => false
end

gem 'builder'

#gem 'haml', '3.1.4'
gem 'xml-simple'
gem 's3'
gem 'youtube_it'

gem 'httparty'

gem 'execjs'
gem 'therubyracer'

#translation gems
gem 'ruby_parser'
gem 'locale'
gem 'gettext'
#gem 'fast_gettext'
gem 'gettext_i18n_rails'
gem 'minitest'

gem "spawn", :git => 'http://github.com/rfc2822/spawn'

gem 'sendgrid'

And my fast_gettext.rb file:

FastGettext.add_text_domain 'project', :path => 'locale', :type => :po
FastGettext.default_available_locales = ['en','es','it','fr','de','pt']     #all you want to allow
FastGettext.default_text_domain = 'project'

FastGettext.default_locale = 'en'

Bogus human_attribute_name for attributes through accepts_nested_attributes

If a model declares a accepts_nested_attributes_for then translated attributes come like this "Nested model.another nested model.attribute" for errors created by forms with nested models (aka assigning values on Model#nested_model_attributes).

The following replacement on ActiveRecord::Base#human_attribute_name (or if you prefer to def gettext_translation_for_attribute_name(attribute)) seems to do the trick for both nested and non-nested attributes

def self.human_attribute_name(attribute, *args)
  ready_for_gettext = "#{self}.#{attribute}".split('.').map! {|a| a.gsub('_',' ').capitalize }.join('|')
  s_(ready_for_gettext)
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.