Using (x)gettext with Ruby files

S

Sascha Ebach

Hi,

I want to localize some Ruby files and was trying to use xgettext. It
doesn't support Ruby as a language. All I want to do though is extract
everything within _("") and _(''). Are there any recommendations on how
to use gettext / xgettext with Ruby files? When I run xgettext through
my files I get messages like these:

xgettext: warning: file `helpers/application_helper.rb' extension `rb'
is unknown; will try C

and

controllers/page_controller.rb:39: warning: unterminated character constant

The second message comes from a comment which includes a '

# ... don't ...

Obviously it nows nothing about Ruby.

I also found rgettext, but it's functionality is very limited.

How do you extract your strings from your Ruby files?

Sascha
 
S

Sascha Ebach

Christian said:
How about definining _() to log all occurring strings?

I don't understand exactly what you mean by that. I want to be able to
use poedit on indexed files. So I will have to use a a harvester to
create the po files. poedit can then take care of versioning issues.
There is the MLL library[1], but it saves it's strings in YAML format. I
have nothing against YAML, but the problem is that you cannot use the
tools that already exist for working with po files.

I also tried to find a gettext mailing list where I could report this
issue, but there doesn't seem to be one. Or did I just not find it?

Sascha

[1] http://dev.digitpaint.nl/projects/mll
 
L

Laurent Sansonetti

Hi,

Hi,

I want to localize some Ruby files and was trying to use xgettext. It
doesn't support Ruby as a language. All I want to do though is extract
everything within _("") and _(''). Are there any recommendations on how
to use gettext / xgettext with Ruby files? When I run xgettext through
my files I get messages like these:

xgettext: warning: file `helpers/application_helper.rb' extension `rb'
is unknown; will try C

and

controllers/page_controller.rb:39: warning: unterminated character constant

The second message comes from a comment which includes a '

# ... don't ...

Obviously it nows nothing about Ruby.

I also found rgettext, but it's functionality is very limited.

How do you extract your strings from your Ruby files?

In Alexandria (alexandria.rubyforge.org) I use rgettext from
Ruby-GetText package, as follow:

rgettext <ruby_files> -o <pot_file>

And it works perfectly, since the beginning. It supports splitted
strings with + or \.

HTH,

Laurent
 
G

gabriele renzi

gabriele renzi ha scritto:
Christian Neukirchen ha scritto:


this is exxactly how ruby-gettext does, IIRC

ignore this message, I somewhat skipped "to log" while reading :/
 
S

Sascha Ebach

Laurent said:
In Alexandria (alexandria.rubyforge.org) I use rgettext from
Ruby-GetText package, as follow:

rgettext <ruby_files> -o <pot_file>

And it works perfectly, since the beginning. It supports splitted
strings with + or \.

I will have a look at that, but what if you have lots of <ruby_files>?
there is a limit on how many files you can pass as arguments. I suspect
I will probably have to modify rgettext. Maybe it could accept a glob.

Thanks for the tip
Sascha
 
L

Laurent Sansonetti

Hi,

I will have a look at that, but what if you have lots of <ruby_files>?
there is a limit on how many files you can pass as arguments. I suspect
I will probably have to modify rgettext. Maybe it could accept a glob.

I do not think there is a limit (except your shell's, or maybe Ruby
itself). Actually I ran it with 38 files at once, without any problem
:)

Cheers

Laurent
 
S

Sascha Ebach

Laurent said:
Hi,




I do not think there is a limit (except your shell's, or maybe Ruby
itself). Actually I ran it with 38 files at once, without any problem
:)

The shell has the limit I think. That is the reaons for programs like
xargs. Try it with 300 or 1000 files to see what I mean.

Now that I have thought about it, it shouldn't be that hard to patch up
rgettext.

Did you try to use rgettext on eruby files? If yes, did it work? You
could have something like this:

<html>
<body>
Use gettext for l18n. It has the ability to extract strings via a
function like this _("This text will be translated").
<%= link_to _("Documentation") %>
...

_("This text will be translated") should not be translated. But
everything in between <% .. %> should.

Sascha
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,459
Latest member
Vida00R129

Latest Threads

Top