# Is it possible to duplicate a key? --new

**URL:** <https://www.ruby-forum.com/t/is-it-possible-to-duplicate-a-key-new/101025>\
**Category:** Rails\
**Created:** [August 2, 2006, 10:53pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-duplicate-a-key-new/101025 "2006-08-02T22:53:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ricardo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a6a055/32.png) [@ricardo](https://www.ruby-forum.com/u/ricardo)\
**Post date:** [August 2, 2006, 10:53pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-duplicate-a-key-new/101025/1 "2006-08-02T22:53:22Z")

</div>

Im not very familiar with RoR so this question might be kind of silly.  
I want to store strings from different lenguages in a database. I want  
to have the key for the string in english be the ‘key’ for all the  
corresponding traslations of that string. For example:  
(database columns)  
lenguage-------------key-----------------value-----  
english hello “hello worl”  
spanish hello “hola mundo”  
french hello “Bon jour xxxxx”

the point here is that all strings from diff. lenguages share the same  
key. I was thinking of creating three different tables and link them  
(if possible) and then somehow override the key of the other lenguges  
with the english string key…is this possible? Or is it better to  
store all strings from diff. lenguges in the same table and override the  
keys from the other lenguages with the one in english?

I hope someone can help me out!

thanks much

---

<div class="post-metadata">

**Author:** ![ricardo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a6a055/32.png) [@ricardo](https://www.ruby-forum.com/u/ricardo)\
**Post date:** [August 3, 2006, 11:09am UTC](https://www.ruby-forum.com/t/is-it-possible-to-duplicate-a-key-new/101025/2 "2006-08-03T11:09:01Z")

</div>

Hi Rob,

Just have a look at globalize plugin, it is very similar to your  
question (and perhaps you can even use it):

You can see that unicity is on the pair [`tr_key`,`language_id`]:

CREATE TABLE `globalize_translations` (  
`id` int(11) NOT NULL auto\_increment,  
`type` varchar(255) default NULL,  
`tr_key` varchar(255) default NULL,  
`table_name` varchar(255) default NULL,  
`item_id` int(11) default NULL,  
`facet` varchar(255) default NULL,  
`language_id` int(11) default NULL,  
`pluralization_index` int(11) default ‘1’,  
`text` text,  
PRIMARY KEY (`id`),  
KEY `globalize_translations_tr_key_index` (`tr_key`,`language_id`),  
KEY `globalize_translations_table_name_index`  
(`table_name`,`item_id`,`language_id`)  
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

GlobalizePlugin: [http://www.globalize-rails.org/wiki/](http://www.globalize-rails.org/wiki/)

Jean-Etienne

---

<div class="post-metadata">

**Author:** ![ricardo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a6a055/32.png) [@ricardo](https://www.ruby-forum.com/u/ricardo)\
**Post date:** [August 3, 2006, 1:22pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-duplicate-a-key-new/101025/3 "2006-08-03T13:22:38Z")

</div>

i think the relationship is

key has many values/translations  
language belongs to key  
language has one values/translations

I don’t know how the underlying table structure will look like but you  
can  
have similar table structure

Language table PK language\_id i.e. ‘English’  
Key table PK key\_id i.e. ‘Hello’  
Translation table PK value\_id i.e. “hola mundo”, this table will have  
foreign keys from Language and Key table

I hope this helps get you started I may be missing a thing or 2 about  
key  
and language relationship

-daya

---

<div class="post-metadata">

**Author:** ![ricardo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a6a055/32.png) [@ricardo](https://www.ruby-forum.com/u/ricardo)\
**Post date:** [August 3, 2006, 5:47pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-duplicate-a-key-new/101025/4 "2006-08-03T17:47:08Z")

</div>

Hi Jean-Etienne thanks for your help.

I read about globalize plugin (the link you sent me) and I got the  
feeling that this service would be more translating actual strings…is  
that right?

thanks

---

<div class="post-metadata">

**Author:** ![ricardo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a6a055/32.png) [@ricardo](https://www.ruby-forum.com/u/ricardo)\
**Post date:** [August 3, 2006, 11:07pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-duplicate-a-key-new/101025/5 "2006-08-03T23:07:55Z")

</div>

Rob,

I gave you this link just because you want to achieve something similar,  
not for the purpose itself 🙂

This plugin allows you to do internalization in a very simple manner.  
For example, just write “foo”.t in your views. According to the current  
language, it will convert this value (key) to the language specific  
form.  
Just have a look, it does a lot more than this (date, currency …)

Jean-Etienne
