Help:Extension:Translate/Developer guide/de
<translate> Translators</translate> (<translate> main help page</translate> )
- <translate> How to translate</translate>
- <translate> Best practices</translate>
- <translate> Statistics and reporting</translate>
- <translate> Quality assurance</translate>
- <translate> Message group states</translate>
- <translate> Offline translation</translate>
- <translate> Glossary</translate>
<translate> Translation administrators</translate>
- <translate> How to prepare a page for translation</translate>
- <translate> Page translation administration</translate>
- <translate> Unstructured element translation</translate>
- <translate> Group management</translate>
- <translate> Move translatable page</translate>
- <translate> Import translations via CSV</translate>
- <translate> Working with message bundles</translate>
<translate> Sysadmins and developers</translate>
- <translate> Installation</translate>
- <translate> Configuration</translate>
- <translate> Getting started with development</translate>
- <translate> Developer guide</translate>
- <translate> Extending Translate</translate>
- <translate> Validators</translate>
- <translate> Insertables</translate>
- <translate> Group configuration</translate>
- <translate> Group configuration example</translate>
- <translate> Translation memories</translate>
- <translate> Translation aids</translate>
- <translate> Enabling message bundles</translate>
- <translate> PHP hooks</translate>
Die Übersetzen-Erweiterung ist eine große Erweiterung mit hunderten von Klassen. This page provides guidance for developers who want to work on the code. After reading this page and linked documents you will better understand how code in Translate is organized and what special conventions are used. General MediaWiki development policies, coding conventions and how to use tools like Gerrit and Phabricator are out of scope. You are assumed to be familiar with these topics and when they apply to Translate, it will not be repeated here.
Translate extension is undergoing many large migrations simultaneously. Here we list the major migrations that are on-going, and detail which style is preferred for new code. Generally, when modifying existing code, it is better to keep to current style, and do migrations separately. Some smaller cleanups are okay to do when touching code.
Namespace migration
We are in process of migrating all Translate code under the namespace \MediaWiki\Extension\Translate
.
All namespaced code is placed under the src/
directory.
All new PHP files should be put in an appropriate namespace.
See Extension:Translate/Namespaces for guidance which namespaces are going to be available.
Namespaces are organized by domain, rather than function.
Abbreviations should be avoided in namespaces and class names.
Legacy code is in the repository root and various subdirectories.
src/
directory.Splitting tests into integration and unit tests
Previously there was no distinction of integration and unit tests.
For new code, unit tests should be the main type of tests.
Unit tests are placed under tests/phpunit/unit
directory matching the namespace layout.
There is a Makefile in that directory to easily run all or parts of unit tests while developing.
Type declarations and comments
All new code should declare both parameter and return types.
In addition strict types should be enabled using declare( strict_types = 1 );
.
Thanks to type declarations, most function and method comments are now redundant, as they would only repeat the parameter names and types.
For this reason, linter checks for missing parameter or return type declarations are disabled for code under src/
and tests/
, which roughly correlate with places using type declarations.
For this code, do not add redundant documentation unless it provides additional value.
One such example is to provide more accurate type hints for array types, for example:
class UserManager {
/** @return User[] */
public function getAllUsers(): array { ... }
}
As illustrated above, for comments having only one tag or one line description, do use the one line comment syntax as well.
:
in return type declarations. Until such standard comes, please use the illustrated style: no space before, one space after.Constructor dependency injection
New code should have all its dependencies injected via constructor. In some cases this is not yet possible, due to some services only being available in the most recent version of MediaWiki as well lack of ObjectFactory support for some type of classes like jobs and maintenance scripts. For such new code, place all dependencies on the class constructor (or main entry point to the class) to easy migration to constructor dependency injection in the future.
execute
method, not in the constructor.
File header
For new code, we have chosen the following minimalistic header:
<?php
declare( strict_types = 1 );
namespace Example;
use OtherStuff;
/**
* Class description.
* @author Your name
* @license GPL-2.0-or-later
* @since 2020.06
*/
class ExampleClass {
/** @return User[] */
public function getAllUsers(): array { ... }
}
If you wish to assert your copyright more explicitly, you can optionally add @copyright tag as well.
Deprecation and version numbers
When changing Translate code in backwards incompatible ways, do check https://codesearch.wmcloud.org/search/ for any users of the code. Known users are TwnMainPage, TranslateSVG, CentralNotice, MassMessage and bunch of stuff in the translatewiki repository.
You can use the deprecation facilities provided by MediaWiki core, including the @deprecated tag and wfDeprecated() hard deprecation. If there are no known users of the code, it is okay to change it in backwards incompatible way without deprecation, unless it is explicitly marked as stable (See Stable interface policy). Code marked as stable should be hard-deprecated at least for one MediaWiki-Sprachenerweiterungspaket (MLEB) release.
MediaWiki core version numbers are meaningless in the context of Translate, as Translate always supports multiple MediaWiki releases. Translate itself uses YYYY.MM style versioning (as part of MLEB). New classes and methods should be annotated with @since YYYY.MM tags.