How to actually use it?

1 view
Skip to first unread message

Erik Terpstra

unread,
Jul 1, 2008, 10:47:23 AM7/1/08
to merb_global
Hi,

I installed and configured merb_global using the instructions over
here:

http://github.com/myabc/merb_global/tree/master

Now, how do I actually use it?
The installation and configuration went fine, but when I do something
like this in a view:

<%=_ 'Hello world!' %>

I get:

Internal Server Error 500
undefined method `_' for #<Foo:0xb793c0bc>

Did I forget to require or include something in init.rb?
How do I use it?

Thanks in advance,

Erik.

Alexander Coles

unread,
Jul 1, 2008, 10:52:40 AM7/1/08
to merb_...@googlegroups.com

Hi Erik,

Did you install the latest Gem, or the 'edge' version from Git?

Alex

Erik Terpstra

unread,
Jul 1, 2008, 11:00:37 AM7/1/08
to merb_global
The latest gem, merb_global (0.0.4.2).

Alexander Coles

unread,
Jul 1, 2008, 11:10:57 AM7/1/08
to merb_...@googlegroups.com

On Jul 1, 2008, at 5:00 PM, Erik Terpstra wrote:

>
> The latest gem, merb_global (0.0.4.2).
>

Did you add dependency 'merb_global' to your Merb init.rb file?

I am presuming you setup the rest of the configuration for the
merb_global configuration as shown in the README - either with a Hash,
or in a plugins.yaml file.

Then the syntax is:
_('Hi! Hello world!')


Alex

Erik Terpstra

unread,
Jul 1, 2008, 11:26:33 AM7/1/08
to merb_global
Yes, adding: dependency 'merb_global' to init.rb solves the problem.
Thanks a lot.
I have just started using merb, so I have still a lot to learn.

Cheers,

Erik.

Alexander Coles

unread,
Jul 1, 2008, 11:30:21 AM7/1/08
to merb_...@googlegroups.com

On Jul 1, 2008, at 5:26 PM, Erik Terpstra wrote:

>
> Yes, adding: dependency 'merb_global' to init.rb solves the problem.
> Thanks a lot.
> I have just started using merb, so I have still a lot to learn.
>
> Cheers,
>
> Erik.
>

Great! Pleased to hear that helped.

Let us know how it goes!

Erik Terpstra

unread,
Jul 2, 2008, 4:52:30 AM7/2/08
to merb_global
> Great! Pleased to hear that helped.
>
> Let us know how it goes!

Still can't translate anything yet, I have posted my test application
below.
Can you see what I am doing wrong?

TIA,

Erik.

========== ./config/framework.rb =========

Merb::Config[:framework] = {
:application => "application.rb",
:view => "views",
:config => "config"
}

========== ./config/init.rb =========

Merb::Config.use { |c|
c[:environment] = 'production',
c[:framework] = {},
c[:log_level] = 'debug',
c[:use_mutex] = false,
c[:session_store] = 'cookie',
c[:session_id_key] = '_session_id',
c[:session_secret_key] = '3bc0cf9fdc2b52ca89ca14c63199a2cb15528c7c',
c[:exception_details] = true,
c[:reload_classes] = true,
c[:reload_time] = 0.5
}

dependency 'merb_global'
Merb::Plugins.config[:merb_global] = {
:flat => true,
:domain => 'messages'
}

========== ./application.rb =========

Merb::Router.prepare do |r|
r.match('/').to(:controller => 'foo', :action =>'index')
r.default_routes
end

class Foo < Merb::Controller
language{'nl'}

def _template_location(action, type = nil, controller =
controller_name)
controller == "layout" ? "layout.#{action}.#{type}" :
"#{action}.#{type}"
end

def index
render
end
end

========== ./views/index.html.erb =========

<!DOCTYPE HTML>
<html>
<body>
<h1>Test page</h1>
<p>Parameters: <%= params.inspect %></p>
<p>language = <%= lang %></p>
<p>translated: <%= _('Hello world!') %></p>
</body>
</html>

========== ./locale/nl/messages.po =========

msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

msgid "Hello world!"
msgstr "Hallo wereld!"

========== ./locale/nl/messages.mo =========

# Contains .mo data for messages.po

Maciej Piechotka

unread,
Jul 2, 2008, 5:03:12 AM7/2/08
to merb_...@googlegroups.com
On Wed, 2008-07-02 at 01:52 -0700, Erik Terpstra wrote:
> > Great! Pleased to hear that helped.
> >
> > Let us know how it goes!
>
> Still can't translate anything yet, I have posted my test application
> below.
> Can you see what I am doing wrong?
>
> TIA,
>
> Erik.

> (...)


> ========== ./locale/nl/messages.po =========
>
> msgid ""
> msgstr ""
> "Project-Id-Version: PACKAGE VERSION\n"
> "Last-Translator: Automatically generated\n"
> "Language-Team: none\n"
> "MIME-Version: 1.0\n"
> "Content-Type: text/plain; charset=UTF-8\n"
> "Content-Transfer-Encoding: 8bit\n"
> "Plural-Forms: nplurals=2; plural=(n != 1);\n"
>
> msgid "Hello world!"
> msgstr "Hallo wereld!"
>

All scripts (for example to generate mo) will search it
in ./locale/nl.po. However if you don't use them it can be anywhere.

> ========== ./locale/nl/messages.mo =========
>
> # Contains .mo data for messages.po


This file should be in ./locale/nl/LC_MESSAGES. In the same way as in
gettext example.

Regards

signature.asc

Erik Terpstra

unread,
Jul 2, 2008, 5:35:02 AM7/2/08
to merb_global
>
> > ========== ./locale/nl/messages.mo =========
>
> > # Contains .mo data for messages.po
>
> This file should be in ./locale/nl/LC_MESSAGES. In the same way as in
> gettext example.

Hmm, I got it working after renaming messages.po to merbapp.mo, so it
seems that:

Merb::Plugins.config[:merb_global] = {:domain => 'messages'}

does not work.

Thanks for helping out.

Erik.

Maciej Piechotka

unread,
Jul 2, 2008, 5:39:28 AM7/2/08
to merb_...@googlegroups.com

Yes. Since it should be:
Merb::Plugins.config[:merb_global] = {
:gettext => {:domain => 'messages'}
}

> Thanks for helping out.
>
> Erik.

Regards

signature.asc
Reply all
Reply to author
Forward
0 new messages