Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat Class Reference

A very basic FileFormatSupport module that implements some basic functionality and a simple binary based file format. More...

Inheritance diagram for MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat:
MediaWiki\Extension\Translate\FileFormatSupport\FileFormatSupport MediaWiki\Extension\Translate\FileFormatSupport\AmdFormat MediaWiki\Extension\Translate\FileFormatSupport\AndroidXmlFormat MediaWiki\Extension\Translate\FileFormatSupport\AppleFormat MediaWiki\Extension\Translate\FileFormatSupport\DtdFormat MediaWiki\Extension\Translate\FileFormatSupport\GettextFormat MediaWiki\Extension\Translate\FileFormatSupport\IniFormat MediaWiki\Extension\Translate\FileFormatSupport\JavaFormat MediaWiki\Extension\Translate\FileFormatSupport\JsonFormat MediaWiki\Extension\Translate\FileFormatSupport\YamlFormat

Public Member Functions

 supportsFuzzy ()
 Query the capabilities of this FFS.
 
 getFileExtensions ()
 Return the commonly used file extensions for these formats.
 
 __construct (FileBasedMessageGroup $group)
 
 setGroup (FileBasedMessageGroup $group)
 
 getGroup ()
 
 setWritePath (string $target)
 Set the file's location in the system.
 
 getWritePath ()
 Get the file's location in the system.
 
 exists ( $code=false)
 Returns true if the file for this message group in a given language exists.
 
 read (string $languageCode)
 Reads messages from the file in a given language and returns an array of AUTHORS, MESSAGES and possibly other properties.
 
 readFromVariable (string $data)
 Parse the message data given as a string in the SimpleFormat format and return it as an array of AUTHORS and MESSAGES.
 
 write (MessageCollection $collection)
 Write the collection to file.
 
 writeIntoVariable (MessageCollection $collection)
 Read a collection and return it as a SimpleFormat formatted string.
 
 filterAuthors (array $authors, string $code)
 Remove excluded authors.
 
 isContentEqual (?string $a, ?string $b)
 Checks whether two strings are equal.
 
 shouldOverwrite (string $a, string $b)
 Allows to skip writing the export output into a file.
 
 isGroupFfsReadable ()
 Check if the file format of the current group is readable by the file format system.
 

Protected Member Functions

 writeReal (MessageCollection $collection)
 
 tryReadSource (string $filename, MessageCollection $collection)
 This tries to pick up external authors in the source files so that they are not lost if those authors are not among those who have translated in the wiki.
 
 tryReadFile (string $filename)
 Read the contents of $filename and return it as a string.
 

Protected Attributes

FileBasedMessageGroup $group
 
string $writePath = null
 
 $extra
 

Detailed Description

A very basic FileFormatSupport module that implements some basic functionality and a simple binary based file format.

Other FFS classes can extend SimpleFormat and override suitable methods.

Author
Niklas Laxström

Definition at line 24 of file SimpleFormat.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat::__construct ( FileBasedMessageGroup $group)

Member Function Documentation

◆ exists()

MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat::exists ( $code = false)

Returns true if the file for this message group in a given language exists.

If no $code is given, the groups source language is assumed. NB: Some formats store all languages in the same file, and then this function will return true even if there are no translations to that language.

Parameters
string | bool$code

Definition at line 77 of file SimpleFormat.php.

◆ filterAuthors()

MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat::filterAuthors ( array $authors,
string $code )

Remove excluded authors.

Definition at line 294 of file SimpleFormat.php.

◆ getFileExtensions()

◆ getGroup()

MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat::getGroup ( )

Definition at line 56 of file SimpleFormat.php.

◆ getWritePath()

MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat::getWritePath ( )

Get the file's location in the system.

Implements MediaWiki\Extension\Translate\FileFormatSupport\FileFormatSupport.

Definition at line 64 of file SimpleFormat.php.

◆ isContentEqual()

MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat::isContentEqual ( ?string $a,
?string $b )

Checks whether two strings are equal.

Sometimes same content might have multiple representations. The main case are inline plurals, which in some formats require expansion at export time.

Implements MediaWiki\Extension\Translate\FileFormatSupport\FileFormatSupport.

Reimplemented in MediaWiki\Extension\Translate\FileFormatSupport\AndroidXmlFormat, MediaWiki\Extension\Translate\FileFormatSupport\JsonFormat, and MediaWiki\Extension\Translate\FileFormatSupport\YamlFormat.

Definition at line 306 of file SimpleFormat.php.

◆ isGroupFfsReadable()

MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat::isGroupFfsReadable ( )

Check if the file format of the current group is readable by the file format system.

This might happen if we are trying to export a JsonFormat or WikiPageMessage group to a GettextFormat.

Definition at line 319 of file SimpleFormat.php.

◆ read()

MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat::read ( string $languageCode)

Reads messages from the file in a given language and returns an array of AUTHORS, MESSAGES and possibly other properties.

Returns
array|bool False if the file does not exist
Exceptions
RuntimeExceptionif the file is not readable or has bad encoding

Implements MediaWiki\Extension\Translate\FileFormatSupport\FileFormatSupport.

Definition at line 97 of file SimpleFormat.php.

◆ readFromVariable()

◆ setGroup()

MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat::setGroup ( FileBasedMessageGroup $group)

Definition at line 52 of file SimpleFormat.php.

◆ setWritePath()

MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat::setWritePath ( string $target)

Set the file's location in the system.

Parameters
string$targetFilesystem path for exported files.

Implements MediaWiki\Extension\Translate\FileFormatSupport\FileFormatSupport.

Definition at line 60 of file SimpleFormat.php.

◆ shouldOverwrite()

MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat::shouldOverwrite ( string $a,
string $b )

Allows to skip writing the export output into a file.

This is useful to skip updates that would only update irrelevant parts, such as the timestamp of the export.

Parameters
string$aThe existing content.
string$bThe new export content.

Implements MediaWiki\Extension\Translate\FileFormatSupport\FileFormatSupport.

Definition at line 310 of file SimpleFormat.php.

◆ supportsFuzzy()

MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat::supportsFuzzy ( )

◆ tryReadFile()

MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat::tryReadFile ( string $filename)
protected

Read the contents of $filename and return it as a string.

Return null if the file doesn't exist. Throw an exception if the file isn't readable or if the reading fails strangely.

Exceptions
InvalidArgumentException

Definition at line 276 of file SimpleFormat.php.

◆ tryReadSource()

MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat::tryReadSource ( string $filename,
MessageCollection $collection )
protected

This tries to pick up external authors in the source files so that they are not lost if those authors are not among those who have translated in the wiki.

Todo
Get rid of this

Definition at line 251 of file SimpleFormat.php.

◆ write()

MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat::write ( MessageCollection $collection)

Write the collection to file.

Implements MediaWiki\Extension\Translate\FileFormatSupport\FileFormatSupport.

Definition at line 170 of file SimpleFormat.php.

◆ writeIntoVariable()

MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat::writeIntoVariable ( MessageCollection $collection)

Read a collection and return it as a SimpleFormat formatted string.

Implements MediaWiki\Extension\Translate\FileFormatSupport\FileFormatSupport.

Definition at line 216 of file SimpleFormat.php.

◆ writeReal()

MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat::writeReal ( MessageCollection $collection)
protected

Definition at line 223 of file SimpleFormat.php.

Member Data Documentation

◆ $extra

MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat::$extra
protected

Definition at line 41 of file SimpleFormat.php.

◆ $group

FileBasedMessageGroup MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat::$group
protected

Definition at line 34 of file SimpleFormat.php.

◆ $writePath

string MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat::$writePath = null
protected

Definition at line 35 of file SimpleFormat.php.


The documentation for this class was generated from the following file: