Extension:SubTranslate

The  extension provides automatic machine translation by DeepL for any pages in NS_MAIN via subpage mechanism.

Installation
If you use other namespaces by $wgContentNamespaces, set $wgNamespacesWithSubpages for these namespaces also.

Usage
Just open an URL of article with language code you want to translate.

e.g. If you want to read https://yourwiki.example.com/wiki/Article in french, open the url https://yourwiki.example.com/wiki/Article /fr.

Accepted language codes on DeepL API as follows:
 * BG - Bulgarian
 * CS - Czech
 * DA - Danish
 * DE - German
 * EL - Greek
 * EN - English /* unspecified variant for backward compatibility; please select EN-GB or EN-US instead */
 * EN-GB - English (British)
 * EN-US - English (American)
 * ES - Spanish
 * ET - Estonian
 * FI - Finnish
 * FR - French
 * HU - Hungarian
 * ID - Indonesian
 * IT - Italian
 * JA - Japanese
 * KO - Korean
 * LT - Lithuanian
 * LV - Latvian
 * NB - Norwegian (Bokmål)
 * NL - Dutch
 * PL - Polish
 * PT - Portuguese /* unspecified variant for backward compatibility; please select PT-BR or PT-PT instead */
 * PT-BR - Portuguese (Brazilian)
 * PT-PT - Portuguese (all Portuguese varieties excluding Brazilian Portuguese)
 * RO - Romanian
 * RU - Russian
 * SK - Slovak
 * SL - Slovenian
 * SV - Swedish
 * TR - Turkish
 * UK - Ukrainian
 * ZH - Chinese (simplified)

These language codes not case-sensitive on this extension.

Timeout
This extension will timed out 5 seconds by default to call DeepL API.

Normally DeepL API return within 5 seconds but sometimes not enough such as long pages.

If you want to set other times, you can set $wgSubTranslateTimeout on LocalSettings.php as follows.

Caching
You can use object cache to save results temporally.

If you want to use cache, set variables on LocalSettings.php as follows.

Caching lifetime as 86400 seconds (1 day) by default. You can change by $wgSubTranslateCachingTime as seconds.

Purge not affect this extension. If you want to clear the cache, set variables on LocalSettings.php as follows and reload the page.

Also null edit the base page effective in re-translate but not clear old cache.

Note: Normally it is unnecessary because re-translate automatically after edit the base article.

Make links into wikipage
You can use magic word. e.g.

Styles for language caption
(v1.0.1-) This extension rewrite the title  to append translated language name. e.g. &quot;Base Article Title (language)&quot;

And you can style language caption by MediaWiki:Common.css if you want. for example:

Or you can suppress this function by following settings in case of conflict other extensions.

Show warning message
This extension show no errors. It terminate quietly if meet some error.

If it not work well, try to set error_reporting( E_ALL ) on LocalSettings.php as follows.

e.g.

It often be caused by timed out. If you meet this error, try to change $wgSubTranslateTimeout longer.