gettext and require

P

Patrick Gundlach

Dear Rubyists,

I use ruby gettext (very nice, though!) and have split up my code in
several files, that I include with require. But in the new files, the
translation effect is lost.


--------------------------------------------------
require 'gettext'
include GetText

require 'beh'

class A
def initialize
bindtextdomain("hello","locale","fr")
end
def pr
puts _("Hello World")
end
end


class B
def pr
puts _("Hello World")
end
end

a=A.new
a.pr
b=B.new
b.pr
--------------------------------------------------
beh.rb:
#empty
--------------------------------------------------


this is OK. Both Hello World get translated. But if I move the code
"class B .... end" to the other file, only the first Hello World gets
translated. I have to put the line with bindtextdomain somewhere in
the second file to get gettext working correctly. I think that this
has something to do with ruby discarding local stuff when using
require.


I need to set the lang part in the file, because I have a web
application that should be able to switch language based on cookies.

Question: how should I set this up correctly?


Patrick
 
M

Masao Mutoh

Hi,

Dear Rubyists,

I use ruby gettext (very nice, though!) and have split up my code in
several files, that I include with require. But in the new files, the
translation effect is lost.
this is OK. Both Hello World get translated. But if I move the code
"class B .... end" to the other file, only the first Hello World gets
translated. I have to put the line with bindtextdomain somewhere in
the second file to get gettext working correctly. I think that this
has something to do with ruby discarding local stuff when using
require.

Now, Ruby-GetText-Package manages a catalog-file(mo-file) per a file,
not per a class/module.
So you have to call GetText.bindetextdomain once a file.
 
P

Patrick Gundlach

Hello,

[gettext local to files]
Now, Ruby-GetText-Package manages a catalog-file(mo-file) per a file,
not per a class/module.
So you have to call GetText.bindetextdomain once a file.

Thank you for your answer. Is this supposed to stay as stated or is
the behaviour intended to change in the future?

Patrick
 
M

Masao Mutoh

Hi,

Hello,

[gettext local to files]
Now, Ruby-GetText-Package manages a catalog-file(mo-file) per a file,
not per a class/module.
So you have to call GetText.bindetextdomain once a file.

Thank you for your answer. Is this supposed to stay as stated or is
the behaviour intended to change in the future?

Of course, if there are other good ideas, I'll change it.
But now, I don't have any good ideas(for implementation) better than
this(a mo-file/a script file).

Any ideas for implementation?
 
P

Patrick Gundlach

Hello,

[...]
Of course, if there are other good ideas, I'll change it.
But now, I don't have any good ideas(for implementation) better than
this(a mo-file/a script file).

Any ideas for implementation?

No. But I can say what I expected: once bindtextdomain is called, my
application should use it globally, regardles what the layout of the
files is.

Patrick
 
M

Masao Mutoh

Hi,

Hello,

[...]
Of course, if there are other good ideas, I'll change it.
But now, I don't have any good ideas(for implementation) better than
this(a mo-file/a script file).

Any ideas for implementation?

No. But I can say what I expected: once bindtextdomain is called, my
application should use it globally, regardles what the layout of the
files is.

If you require another libraries which supports gettext as its textdomain,
how do you judge what the textdomain is applied your application?
 
P

Patrick Gundlach

Hi,

[...]
If you require another libraries which supports gettext as its textdomain,
how do you judge what the textdomain is applied your application?

There are probably more things to concider than stated already. So I
guess the current behaviour is a good compromise between "ease of use"
and "unwanted side effects".

Thanks for the package anyway, it is very good to have!

Patrick
 

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

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,430
Latest member
7dog123

Latest Threads

Top