Extension:SubTranslate

MediaWiki extensions manual
SubTranslate
Release status: stable
Implementation Locale , User interface
Description provide machine translation by DeepL API into subpages
Author(s) Kimagurenote (Corytalk)
Latest version 1.0.2
MediaWiki 1.35+
PHP 7.2.0+
Database changes No
License BSD 3-clause "Modified" License
Download https://kimagurenote.net/kn/SubTranslate#Download
https://kimagurenote.net/kn/SubTranslate#History
Example #Usage

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

Installation

edit

At first, you must create DeepL API account (paid) to get your Auth-Key. You can use DeepL API Free plan or DeepL API Pro (paid) plan.

  • Download zip file from author's website, unzip it and place the file(s) in a directory called SubTranslate in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php file:
    /* Extension:SubTranslate */
    wfLoadExtension( 'SubTranslate' );
    /* if you use DeepL API Free plan */
    $wgSubTranslateAPIKey['api-free.deepl.com'] = "<your auth-key here>";
    /* if you use DeepL API Pro plan */
    $wgSubTranslateAPIKey['api.deepl.com'] = "<your auth-key here>";
    /* Enabled subpages in NS_MAIN */
    $wgNamespacesWithSubpages[NS_MAIN] = true;
    
  •   Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

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

Usage

edit
 
example: base page (author's site written in Japanese) and machine translated of English, French and Chinese pages

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:

These language codes not case-sensitive on this extension.

Additional configuration

edit

Timeout

edit

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.

$wgSubTranslateTimeout = 7.5;

Caching

edit

You can use object cache to save results temporally.

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

$wgSubTranslateCaching = true;
$wgSubTranslateCachingTime = 604800;	/* 60(s) * 60(m) * 24(h) * 7 days */

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.

$wgSubTranslateCaching = true;
$wgSubTranslateCachingTime = false;

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.

Robot policy

edit

(v1.0.2+) You can set robot policy on translated pages as follows if you want to opt out of robot e.g. search engine.

$wgSubTranslateRobotPolicy = "noindex,nofollow";

Note: This variable available only for translated pages by this extension. If you want to set robot policies for other normal pages, see Manual:Noindex, Manual:$wgExemptFromUserRobotsControl and Manual:$wgDefaultRobotPolicy.

FAQs

edit
edit

You can use magic word. e.g. [{{fullurl:Page name}}/en English]

Styles for language caption

edit

(v1.0.1-) This extension rewrite the title ‎<H1>...‎</H1> to append translated language name. e.g. "Base Article Title (language)"

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

H1 SPAN.targetlang {
	font-size: smaller;
}

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

$wgSubTranslateSuppressLanguageCaption = true;

Show warning message

edit

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.

error_reporting( E_ALL );

e.g. Warning: file_get_contents(https://api-free.deepl.com/v2/translate): failed to open stream: HTTP request failed! in /path/to/your/mediawiki/extensions/SubTranslate/includes/SubTranslate.php on line 145

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

Notes

edit

This extension uses MediaWiki subpage mechanism. You must turn on it in main namespace by $wgNamespacesWithSubpages.

This extension will not work if subpage as same title already exist.

If you want to use {{PAGENAME}}, use {{BASEPAGENAME}} instead.

It supports only DeepL API at this time.

It not work with large size article over 128KiB (includes overhead).

If you may use it frequently, pay attention to charge from DeepL:)

See also

edit