Globalizing Typo 4.0.0 - S.O.S. Help needed!

Hello friendly rubyists! This is my first post, so bare with me :slight_smile:

I managed to globalize Typo 4.0.0 - the static content. I made a
Translations editor menu in the admin, and it works fine for all static
content.

Now I am trying to globalize Article/Content.

I have done this:

class Article < Content
include TypoGuid

content_fields :body, :extended

translates :body, :extended

…

Now I get this error:

=> Booting WEBrick…
./script/…/config/…/vendor/rails/activerecord/lib/active_record/base.rb:1129:in
method_missing': undefined methodtranslates’ for Article:Class
(NoMethodError)
from script/…/config/…/app/models/article.rb:8
from
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:140:in
load' from ./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:56:inrequire_or_load’
from
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:30:in
depend_on' from ./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:85:inrequire_dependency’
from
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:98:in
const_missing' from ./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:131:inconst_missing’
from
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:133:in
const_missing' ... 20 levels... from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:inrequire’
from
./script/…/config/…/vendor/rails/activesupport/lib/active_support/dependencies.rb:147:in
`require’
from
./script/…/config/…/vendor/rails/railties/lib/commands/server.rb:30
from script/server:3

I have very little knowledge about meta programming in ruby, but I think
it has got something to do with the way the Article ActiveRecord object
is extending the base Content class.

I tried putting the translates method in the Categories class which does
not extend the Content class and it works fine!

Can anyone help me solve this issue, it is very important!? Please help
me, I am almost cluless about this problem.

Regards,
Zarni

Hi Zarni,

I’m not sure, but is Content a model based on ActiveRecord::Base?
If not, than Article is not a model (any more) and does not define
translates.

The content_fields seems to a method from TypoGuid. You include the
module
an therefore this method exists.

Am 05.08.2006 um 13:47 schrieb Zarni Worgl:

`load’
dependencies.rb:85:in
./script/…/config/…/vendor/rails/activesupport/lib/active_support/
from

–
Posted via http://www.ruby-forum.com/.


Railsi18n-discussion mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/railsi18n-discussion


Thomas B. - Freiberuflicher Softwarecoach
fon: +49(40)411 622 35 mobil: +49(173)23 911 43
fax: +49(40)411 622 36
thomas.baustert(at)b-simple.de

Hey Thomas!

Content is based on ActiveRecord:Base… bellow is the head of the
Content class and the content_fields method is defined in it. TypoGuid
is just a library mixin, generates unique ids. So There must be
something clashing the Globalize mixin, which i put/included in
environment.rb. The translates method is defined in
Globalize::DbTranslate. I can not see why the translates method is not
being mixed into the Content class, couse it works fine for other
classes, that don’t have the content_fields method.

:slight_smile: Thanks for help

require ā€˜observer’
require ā€˜set’

class Content < ActiveRecord::Base
include Observable

@@content_fields = Hash.new
@@html_map = Hash.new

def initialize(*args)
super(*args)
set_default_blog
end

def set_default_blog
if self.blog_id == nil or self.blog_id == 0
self.blog = Blog.default
end
end

class << self
def content_fields(*attribs)
@@content_fields[self] = ((@@content_fields[self]||[]) +
attribs).uniq
@@html_map[self] = nil
attribs.each do | field |
define_method(ā€œ#{field}=ā€) do | newval |
if self[field] != newval
changed
self[field] = newval
if html_map(field)
self[html_map(field)] = nil
end
notify_observers(self, field.to_sym)
end
self[field]
end
unless self.method_defined?(ā€œ#{field}_htmlā€)
define_method(ā€œ#{field}_htmlā€) do
if blog.controller
html(blog.controller, field.to_sym)
else
self[ā€œ#{field}_htmlā€]
end
end
end
end
end

…

end

Thomas B. wrote:

Hi Zarni,

I’m not sure, but is Content a model based on ActiveRecord::Base?
If not, than Article is not a model (any more) and does not define
translates.

The content_fields seems to a method from TypoGuid. You include the
module
an therefore this method exists.

Am 05.08.2006 um 13:47 schrieb Zarni Worgl:

`load’
dependencies.rb:85:in
./script/…/config/…/vendor/rails/activesupport/lib/active_support/
from

–
Posted via http://www.ruby-forum.com/.


Railsi18n-discussion mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/railsi18n-discussion


Thomas B. - Freiberuflicher Softwarecoach
fon: +49(40)411 622 35 mobil: +49(173)23 911 43
fax: +49(40)411 622 36
thomas.baustert(at)b-simple.de

Hi Zarni,

sorry, but then I have no idea.

If you are sure it is a problem with classes that include TypoGuid
you may uncomment all methods of TypoGuid an activate parts of the code
one by one (maybe with some pseudo code) until you get the exception.
Some work, but you know where the problem is.

You may switch the statements

class Article < Content
translates :body, :extended

include TypoGuid
content_fields :body, :extended

and see what happend.

You can further print out all included methods using included_modules()
or public_class_methods() für class method to see what in your class.

May that helps :slight_smile:

Am 08.08.2006 um 02:23 schrieb Zarni Worgl:

@@html_map = Hash.new
end
self[field] = newval
html(blog.controller, field.to_sym)
end

The content_fields seems to a method from TypoGuid. You include the

`load’
[email protected]
–
Posted via http://www.ruby-forum.com/.


Railsi18n-discussion mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/railsi18n-discussion


Thomas B. - Freiberuflicher Softwarecoach
fon: +49(40)411 622 35 mobil: +49(173)23 911 43
fax: +49(40)411 622 36
thomas.baustert(at)b-simple.de