User Tools

Site Tools


google_translate

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

google_translate [2014/03/31 16:04] – created admingoogle_translate [2026/03/21 10:11] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Google translate ====== ====== Google translate ======
  
-You can translate your descriptions using Google translate API. Note, that this service is not free, and it's Google who takes money for the service, not the script.+The script includes built-in Google Translate API integration for automatic text translation. Note that this is a paid service (Google charges for usage). To use it, visit https://developers.google.com/translate/v2/faq and obtain your **Server API Key** (not the Browser key).
  
-To do it you have to go to  https://developers.google.com/translate/v2/faq and get **Server API Key**. You need Server, not a Browser key.+===== Translation of Existing Database =====
  
-===== Translation of Existing DB =====+To translate your existing gallery database, connect to your server via SSH and run:
  
-If you already have a ready DB with descriptions you want to translate you have to use ssh and go to scj/bin, after that run+  php rotation.php action=translate
  
-  php rot.php action=translate+(from the scj/bin directory)
  
-This this point script will ask you what you want to translate, and, if you want to translate both descriptions and titles (alt) you'll have to run this command twice.+If you run this on a slave site, the results are saved there as well. This is useful if you have a master with English descriptions and want to add a German-language slave.
  
 +The script will prompt you to:
  
-**Then script asks what method you want to use - stops, log, fast** stops - means we we'll make a stop after each phrase and you'll be able to edit a result. Log - means no stops but output texts and translations, fast - no output, just translates as fast is it can..+1. Select which field to translate (if you have both description and alt text, you'll need to run this twice) 
 +2. Choose where to save the translated text 
 +3. Enter your Google Translate API key
  
 +Then you'll choose a translation mode:
  
-===== Translation of New Entries =====+- **stops:** The script pauses after each phrase so you can manually review and correct the translation before saving to the database 
 +- **log:** Translates without pausing, but shows the output for review 
 +- **fast:** Translates as quickly as possible with no pauses or output
  
-It takes some time to setup and understand how it works but it worth it because it gives you flexibility to do much more.+For best results, use UTF-8 encoding when connecting to the shell.
  
-You have to setup [[Import Replacements]] for necessary fields , let's say for description+===== Translation of New Entries =====
  
 +To automatically translate new galleries as they're imported, configure translation rules in [[Import Replacements]]. Here's how:
  
 <code> <code>
  
 If this field = URL If this field = URL
-Contains this value = http (ie we want to translate descriptions for all galleries actually) +Contains this value = http (matching all galleries) 
-Then Search For - * (* means 'whole field') +Then Search For - * (the entire field) 
-in This Field  - Custom Vars 1 ( if you use version 50 or language field if you use 51) +in This Field - Custom Vars 1 (we'll store translation here) 
-And Replace it With - external::http://YOURDOMAIN/scj/bin/rot.php?action=translate_text&text={DESCRIPTION}&source_lng=en&target_lng=de&api_key=YOUR_API_KEY (and field content will be replaced by text returned by this url) +And Replace it With - external::http://YOURDOMAIN/scj/bin/rotation.php?action=translate_text&text={DESCRIPTION}&source_lng=en&target_lng=de&api_key=YOUR_API_KEY
- +
-As you can see this way all new content will be processed using that URL  +
- +
-What you have to notice here: +
- +
-  * external:: at the beginning - prefix means what script has to request an external url +
-  * YOURDOMAIN - .... +
-  * {DESCRIPTION} - tag that will be replaced with an actual gallery's description  +
-  * source_lng=en&target_lng=de - edit languages here +
-  * YOUR_API_KEY - should be replaced with your key you got from google+
  
 </code> </code>
  
 +When a gallery is imported, the script makes a request to the URL above. The Custom Vars 1 field receives the translation result returned by the URL. For example, Custom Vars 1 will contain the German translation of the description.
  
-Why do we do it this way:  that's a way for you to optimize this, for example you can user it as external::http://YOURDOMAIN/my_script.phptext={DESCRIPTION}  and translate using your script that will be more flexible, use another, may be free, translation service and so on.+Key features of this approach:
  
-Moreover, this is a way for you not to save a key in the DB just in case if someone gets an access to your admin area.+- **external::** prefix tells the script to fetch the result from an external URL (not just replace text) 
 +- **{DESCRIPTION}** is replaced with the actual gallery description 
 +- **source_lng=en&target_lng=de** specifies the source and target languages 
 +- **api_key** should be your Google API key
  
 +You can save the translation to a slave field. For example, if you have an English master site and a German slave, set up this rule once on the master and save results to the slave's description field.
  
 +This approach (using Import Replacements) is more flexible than a single button. You can point to your own translation script (external::http://YOURDOMAIN/my_script.php?text={DESCRIPTION}) with custom logic or caching. Plus, you can store the API key on a separate server rather than in the main database, which is safer if you share the database with others.
  
 +This flexibility lets you customize how imported text is processed.
  
google_translate.1396281875.txt.gz · Last modified: (external edit)