Extension:SubTranslate
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
editAt 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 yourextensions/
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
editJust 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 (čeština)
- DA - Danish (dansk)
- DE - German (Deutsch)
- EL - Greek (Ελληνικά)
- EN - English (English) /* unspecified variant for backward compatibility; please select EN-GB or EN-US instead */
- EN-GB - English (British)
- EN-US - English (American)
- ES - Spanish (español)
- ET - Estonian (eesti)
- FI - Finnish (suomi)
- FR - French (français)
- HU - Hungarian (magyar)
- ID - Indonesian (Bahasa Indonesia)
- IT - Italian (italiano)
- JA - Japanese (日本語)
- KO - Korean (한국어)
- LT - Lithuanian (lietuvių)
- LV - Latvian (latviešu)
- NB - Norwegian (Bokmål) (norsk bokmål)
- NL - Dutch (Nederlands)
- PL - Polish (polski)
- PT - Portuguese (português) /* 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 (română)
- RU - Russian (русский)
- SK - Slovak (slovenčina)
- SL - Slovenian (slovenščina)
- SV - Swedish (svenska)
- TR - Turkish (Türkçe)
- UK - Ukrainian (українська)
- ZH - Chinese (中文) (simplified)
These language codes not case-sensitive on this extension.
Additional configuration
editTimeout
editThis 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
editYou 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
editMake links into wikipage
editYou 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
editThis 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
editThis 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- SubTranslate (author site, written in Japanese)
- DeepL API Translate Text
- DeepL Extension available for Firefox, Chrome and Edge web browers
- Google translate
- Firefox translations
- Extension:Google Translator
- Extension:LanguageSelector
- Extension:Polyglot