Possible to get random translation?

Hello,

does somebody know if it’s possible to get a random translation? I
googled it and couldn’t find anything helpful.

Example:
en:
hello:
0: “Hello!”
1: “Howdy!”
2: “G’day!”

t(“hello.#{rand(3)}”)

Any help would be appreciated! Thanks.

What if I create a translation model?

Example:
t = Translation.new
t.translation_key = 1
t.translation_string = “Hello!”
t.save
t = Translation.new
t.translation_key = 1
t.translation_string = “Howdy!”
t.save

And get to get it Translation.first(1, :order => ‘RAND()’)?

It would help to know what your larger goal is, but here’s a simple
version:

DICTIONARY = {
“hello” => [“Hello!”, “Howdy!”, “G’day!”],
“goodbye” => [“Goodbye!”, “Later!”]
}

def random_t(string)
variants = DICTIONARY[string]
variants ? variants.rand : nil
end

random_t(“hello”)
random_t(“goodbye”)

Well, the larger goal is to have hundreds if not thousands of
internationalized strings. Your version is good for a small amount of
strings but not applicable for me.

What would you guys prefer t(“hello.#{rand(3)}”) or Translation.first(1,
:order => ‘RAND()’)?

The model would be easy to internationalize with globalize for example
which is the same for the I18n version but rand() not variable and I’d
need to adjust the number whenever I add another string that wouldn’t be
the case for the translation model.

After some more research I decided to do it the model way. Any opinions?

I think a model combined with globalize is the best way to store
hundreds of strings in different languages.