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

Support for the AMD i18n message file format (used by require.js and Dojo). More...

Inheritance diagram for MediaWiki\Extension\Translate\FileFormatSupport\AmdFormat:
MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat MediaWiki\Extension\Translate\FileFormatSupport\FileFormatSupport

Public Member Functions

 getFileExtensions ()
 Return the commonly used file extensions for these formats.
 
 readFromVariable (string $data)
 @inheritDoc
 
- Public Member Functions inherited from MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat
 supportsFuzzy ()
 Query the capabilities of this FFS.
 
 __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.
 
 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)
 
- Protected Member Functions inherited from MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat
 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.
 

Additional Inherited Members

- Protected Attributes inherited from MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat
FileBasedMessageGroup $group
 
string $writePath = null
 
 $extra
 

Detailed Description

Support for the AMD i18n message file format (used by require.js and Dojo).

See: http://requirejs.org/docs/api.html#i18n

A limitation is that it only accepts json compatible structures inside the define wrapper function. For example the following example is not ok since there are no quotation marks around the keys: define({ key1: "somevalue", key2: "anothervalue" });

Instead it should look like: define({ "key1": "somevalue", "key2": "anothervalue" });

It also supports the top-level bundle with a root construction and language indicators. The following example will give the same messages as above: define({ "root": { "key1": "somevalue", "key2": "anothervalue" }, "sv": true });

Note that it does not support exporting with the root construction, there is only support for reading it. However, this is not a serious limitation as Translatewiki doesn't export the base language.

AmdFormat implements a message format where messages are encoded as key-value pairs in JSON objects wrapped in a define call.

Author
Matthias Palmér

Definition at line 51 of file AmdFormat.php.

Member Function Documentation

◆ getFileExtensions()

MediaWiki\Extension\Translate\FileFormatSupport\AmdFormat::getFileExtensions ( )

Return the commonly used file extensions for these formats.

Include the dot.

Returns
string[]

Reimplemented from MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat.

Definition at line 53 of file AmdFormat.php.

◆ readFromVariable()

MediaWiki\Extension\Translate\FileFormatSupport\AmdFormat::readFromVariable ( string $data)

@inheritDoc

Reimplemented from MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat.

Definition at line 58 of file AmdFormat.php.

◆ writeReal()

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

Reimplemented from MediaWiki\Extension\Translate\FileFormatSupport\SimpleFormat.

Definition at line 78 of file AmdFormat.php.


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