mysql one翻译表与多个翻译表

时间:2015-06-10 22:04:39

标签: php mysql database-design

我正在尝试为所有系统设计结构翻译(en - > fr)。

我的数据库:

平移(ID,表,key_for_search,column_to_translate,朗,翻译)

id |表| key_for_search | column_to_translate |郎|翻译

1 |帖子| 2 |标题| en |喂

2 |帖子| 2 |标题| sp | HOLA

将翻译添加到新表或可能存在。

这种方式好吗?

2 个答案:

答案 0 :(得分:0)

也许是一个更简单的表:

xid -- code that is in the other table
lang -- language of 'xlation' column
xlation -- the translation in `lang` (use utf8 for this column)

xid可能是INT,您只需要另一个条目。或者它可能是一个短串。或者它可能是英文版。

你需要

PRIMARY KEY(xid, lang)

您可能需要这样做以避免重复:

UNIQUE(lang, xlation)

现在......仔细考虑数据流以及您需要的INSERTsSELECTs。你可能会有更多问题。

(更新):

xid | lang | xlation
Hello | en | Hello
Hello | sp | hola
hello how are you ? | en | Hello.  How are you?
hello how are you ? | sp | Hola. ¿Coma estas?

答案 1 :(得分:0)

感谢您的回复。

抱歉我的英语不好。

我想我说得不清楚。

我的表格例如:

--
-- Table structure for table `posts`
--

CREATE TABLE IF NOT EXISTS `posts` (
`id` int(11) NOT NULL,
  `title` varchar(100) NOT NULL,
  `content` mediumtext
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `posts`
--

INSERT INTO `posts` (`id`, `title`, `content`) VALUES
(1, 'hello', 'hello how are you ?');

-- --------------------------------------------------------

--
-- Table structure for table `translates`
--

CREATE TABLE IF NOT EXISTS `translates` (
`id` int(11) NOT NULL,
  `table` varchar(255) NOT NULL,
  `key` int(11) NOT NULL,
  `column` varchar(255) NOT NULL,
  `lang` varchar(3) NOT NULL,
  `translate` text NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `translates`
--

INSERT INTO `translates` (`id`, `table`, `key`, `column`, `lang`, `translate`) VALUES
(1, 'posts', 1, 'title', 'es', 'Hola'),
(2, 'posts', 1, 'content', 'es', 'Hola, cómo estás?');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `posts`
--
ALTER TABLE `posts`
 ADD PRIMARY KEY (`id`);

--
-- Indexes for table `translates`
--
ALTER TABLE `translates`
 ADD PRIMARY KEY (`id`), ADD KEY `table` (`table`,`key`,`column`,`lang`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `posts`
--
ALTER TABLE `posts`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=2;
--
-- AUTO_INCREMENT for table `translates`
--
ALTER TABLE `translates`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=3;

和我的获取翻译的查询

select `column`,`translate` from `translates` where `table` = 'posts' && (`column` = 'title' || `column` = 'content') && `key` = 1 && `lang` = 'es' #Spanish translate

为什么我用这种方式?

因为我将来可以添加新表,我不需要新的设计表或新编程

这是一个好主意?

相关问题