Translate content

Hi guys

I get contents from a website and store to table of database.

Every word of this content need translate, my translates is in another table.

i need a solution for better translate for contents

and i need a query for this.

my tables:


CREATE TABLE IF NOT EXISTS `webstrore` (
	`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
	`content` text NOT NULL DEFAULT '',
	`datetime` datetime NOT NULL,

	PRIMARY KEY (`id`)
) ENGINE=MyISAM;

CREATE TABLE IF NOT EXISTS `weblanguage` (
	`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
	`webstrore_id` bigint(20) unsigned NOT NULL DEFAULT '0',
	`word` varchar(255) NOT NULL DEFAULT '',
	`translateword` varchar(255) NOT NULL DEFAULT '',
	`datetime` datetime NOT NULL,

	PRIMARY KEY (`id`)
) ENGINE=MyISAM;

thank you

Are you saying you have some keywords that you translate to language A from the scrape of a website in language B?

Or, are you saying you maintain two entire dictionaries?

Are you saying you have some keywords that you translate to language A from the scrape of a website in language B?
Yes

some keywords for translate

I doubt you will be able to replace some words from a string in one table, with words from another table, though a table is a good place to store the replacements.

To do this in PHP you would construct an array of translation terms…

“select word, translateword from weblanguage”;

giving you something like:

$translations = array(
“hard”=>“dur”,
“email”=>“courriel”,

… and so on

);

You then need to run that array over your text and replace the key words.


$translations = array(
"hard"=>"dur",
"email"=>"courriel",

//... and so on


);

$text = "I find it really hard to write email in French.";

var_dump($translations);

foreach( $translations as $k=>$v){

$text = str_ireplace(" " . $k ." ", " ". $v ." ",$text);

}

echo $text;
// I find it really dur to write courriel in French.

This is incredibly oversimplified.

It could be improved e.g. by checking to see if the $k exists in the string before calling replace and so on - but should serve as an example.

There are many edge cases this does not cope with, say a sentence ends in hard. or is followed by a comma hard, [ EDIT use str_ireplace instead discount this-> ] or starts a sentence Hard times await…

There are probably other better ways of doing translations… does this answer your question?

thank so much Cups

solved