summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Translate/ffs/FFS.php
blob: 2c89f736ca28de70c02fd3addde5b7599d296321 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
 * File format support classes.
 *
 * These classes handle parsing and generating various different
 * file formats where translation messages are stored.
 *
 * @file
 * @defgroup FFS File format support
 * @author Niklas Laxström
 * @copyright Copyright © 2008-2013, Niklas Laxström
 * @license GPL-2.0-or-later
 */

/**
 * Interface for file system support classes.
 * @ingroup FFS
 */
interface FFS {
	public function __construct( FileBasedMessageGroup $group );

	/**
	 * Set the file's location in the system
	 * @param string $target Filesystem path for exported files.
	 */
	public function setWritePath( $target );

	/**
	 * Get the file's location in the system
	 * @return string
	 */
	public function getWritePath();

	/**
	 * Will parse messages, authors, and any custom data from the file
	 * and return it in associative array with keys like \c AUTHORS and
	 * \c MESSAGES.
	 * @param string $code Language code.
	 * @return array|bool Parsed data or false on failure.
	 */
	public function read( $code );

	/**
	 * Same as read(), but takes the data as a parameter. The caller
	 * is supposed to know in what language the translations are.
	 * @param string $data Formatted messages.
	 * @return array Parsed data.
	 */
	public function readFromVariable( $data );

	/**
	 * Writes to the location provided with setWritePath and group specific
	 * directory structure. Exports translations included in the given
	 * collection with any special handling needed.
	 * @param MessageCollection $collection
	 */
	public function write( MessageCollection $collection );

	/**
	 * Quick shortcut for getting the plain exported data.
	 * Same as write(), but returns the output instead of writing it into
	 * a file.
	 * @param MessageCollection $collection
	 * @return string
	 */
	public function writeIntoVariable( MessageCollection $collection );

	/**
	 * Query the capabilities of this FFS. Allowed values are:
	 *  - yes
	 *  - write (ignored on read)
	 *  - no (stripped on write)
	 * @return string
	 * @since 2013-03-05
	 */
	public function supportsFuzzy();

	/**
	 * 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.
	 *
	 * @param string $a
	 * @param string $b
	 * @return bool
	 * @since 2016.11
	 */
	public function isContentEqual( $a, $b );

	/**
	 * Return the commonly used file extensions for these formats.
	 * Include the dot.
	 * @return string[]
	 * @since 2013-04
	 */
	public function getFileExtensions();

	/**
	 * 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.
	 *
	 * @param string $a The existing content.
	 * @param string $b The new export content.
	 * @return bool
	 * @since 2017.04
	 */
	public function shouldOverwrite( $a, $b );
}