[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

gettext and require

Patrick Gundlach

11/21/2004 10:28:00 AM

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
6 Answers

Masao Mutoh

11/21/2004 3:07:00 PM

0

Hi,

On Sun, 21 Nov 2004 20:13:08 +0900
Patrick Gundlach <clr3.10.randomuser@spamgourmet.com> wrote:

> 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.
<snip>
> 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.

--
:% Masao Mutoh<mutoh@highway.ne.jp>


Patrick Gundlach

11/21/2004 4:07:00 PM

0

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

Masao Mutoh

11/21/2004 5:39:00 PM

0

Hi,

On Mon, 22 Nov 2004 02:08:06 +0900
Patrick Gundlach <clr4.10.randomuser@spamgourmet.com> wrote:

> 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?

--
:% Masao Mutoh<mutoh@highway.ne.jp>


Patrick Gundlach

11/21/2004 6:52:00 PM

0

Hello,

[...]

>> 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?

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

Masao Mutoh

11/22/2004 1:52:00 PM

0

Hi,

On Mon, 22 Nov 2004 04:13:06 +0900
Patrick Gundlach <clr4.10.randomuser@spamgourmet.com> wrote:

> Hello,
>
> [...]
>
> >> 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?
>
> 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?

--
:% Masao Mutoh<mutoh@highway.ne.jp>


Patrick Gundlach

11/22/2004 2:48:00 PM

0

Hi,

[...]

>> 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?

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