====== Google translate ====== 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). ===== Translation of Existing Database ===== To translate your existing gallery database, connect to your server via SSH and run: php rotation.php action=translate (from the scj/bin directory) 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: 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: - **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 For best results, use UTF-8 encoding when connecting to the shell. ===== Translation of New Entries ===== To automatically translate new galleries as they're imported, configure translation rules in [[Import Replacements]]. Here's how: If this field = URL Contains this value = http (matching all galleries) Then Search For - * (the entire field) in This Field - Custom Vars 1 (we'll store translation here) 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 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. Key features of this approach: - **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.