SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:
    Code:
    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

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    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?

  3. #3
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    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.
    PHP Code:
    $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?
    Last edited by Cups; Oct 14, 2011 at 07:12. Reason: added spaces back to replace $v

  5. #5
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank so much Cups

    solved


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •