Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> tłumaczenie kodu strony - google translate
Norbit_24
post
Post #1





Grupa: Zarejestrowani
Postów: 163
Pomógł: 2
Dołączył: 7.03.2009

Ostrzeżenie: (0%)
-----


Witam

Potrzebuję zrobić takie tłumaczenie strony jest jest tutaj:
http://www.vbenterprisetranslator.com/

Tzn klikam w odpowiednią flage i tłumaczy mi cały kod źródłowy...

Prosze o jakieś przykłady.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Norbit_24
post
Post #2





Grupa: Zarejestrowani
Postów: 163
Pomógł: 2
Dołączył: 7.03.2009

Ostrzeżenie: (0%)
-----


Znalazłem działający kod, jednak nie chcę tłumaczyć słów z polskimi znakami;/ A to jest tutaj ważne.

Proszę o inne przykłady

  1. <?php
  2.  
  3. /**
  4.  * Translating language with Google API
  5.  * @author gabe@fijiwebdesign.com
  6.  * @version $id$
  7.  * @license - Share-Alike 3.0 (http://creativecommons.org/licenses/by-sa/3.0/)
  8.  *
  9.  * Google requires attribution for their Language API, please see: <a href="http://code.google.com/apis/ajaxlanguage/documentation/#Branding" target="_blank">http://code.google.com/apis/ajaxlanguage/d...ation/#Branding</a>
  10.  *
  11.  */
  12. class Google_Translate_API {
  13.  
  14. /**
  15. * Translate a piece of text with the Google Translate API
  16. * @return String
  17. * @param $text String
  18. * @param $from String[optional] Original language of $text. An empty String will let google decide the language of origin
  19. * @param $to String[optional] Language to translate $text to
  20. */
  21. function translate($text, $from = '', $to = 'en') {
  22. $url = 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q='.rawurlencode($text).'&langpair='.rawurlencode($from.'|'.$to);
  23. $response = file_get_contents(
  24. $url,
  25. null,
  26. 'http'=>array(
  27. 'method'=>"GET",
  28. 'header'=>"Referer: http://".$_SERVER['HTTP_HOST']."/\r\n"
  29. )
  30. )
  31. )
  32. );
  33. if (preg_match("/{\"translatedText\":\"([^\"]+)\"/i", $response, $matches)) {
  34. return self::_unescapeUTF8EscapeSeq($matches[1]);
  35. }
  36. return false;
  37. }
  38.  
  39. /**
  40. * Convert UTF-8 Escape sequences in a string to UTF-8 Bytes
  41. * @return UTF-8 String
  42. * @param $str String
  43. */
  44. function _unescapeUTF8EscapeSeq($str) {
  45. return preg_replace_callback("/\\\u([0-9a-f]{4})/i", create_function('$matches', 'return html_entity_decode(\'&#x\'.$matches[1].\';\', ENT_NOQUOTES, \'UTF-8\');'), $str);
  46. }
  47. }
  48.  
  49. // example usage
  50. $text = 'Czesc to ja.';
  51. $trans_text = Google_Translate_API::translate($text, 'pl', 'en');
  52. if ($trans_text !== false) {
  53. echo $trans_text;
  54. }
  55.  
  56.  
  57. ?>


Dobra, wykorzystam jednak to:

http://translate.google.com/translate_tools?hl=pl

Dzięki, Pozdr
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 6.10.2025 - 10:46