|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* @author hashashiyyin [email protected] / [email protected] |
|
5
|
|
|
* Date: 02/08/24 |
|
6
|
|
|
* Time: 13:11 |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Matecat\XliffParser\XliffReplacer; |
|
11
|
|
|
|
|
12
|
|
|
use Matecat\XliffParser\Constants\TranslationStatus; |
|
13
|
|
|
|
|
14
|
|
|
class StatusToStateAttribute { |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @param string $status |
|
19
|
|
|
* @param int $xliffVersion |
|
20
|
|
|
* @param ?string $state_prop |
|
21
|
|
|
* @param ?string $lastMrkState |
|
22
|
|
|
* |
|
23
|
|
|
* @return array |
|
24
|
|
|
*/ |
|
25
|
|
|
public static function getState( string $status, int $xliffVersion, ?string $state_prop = '', ?string $lastMrkState = '' ): array { |
|
26
|
|
|
|
|
27
|
|
|
switch ( $status ) { |
|
28
|
|
|
|
|
29
|
|
|
case TranslationStatus::STATUS_FIXED: |
|
30
|
|
|
case TranslationStatus::STATUS_APPROVED2: |
|
31
|
|
|
if ( $lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_APPROVED2 ) { |
|
|
|
|
|
|
32
|
|
|
$state_prop = "state=\"final\""; |
|
33
|
|
|
$lastMrkState = TranslationStatus::STATUS_APPROVED2; |
|
34
|
|
|
} |
|
35
|
|
|
break; |
|
36
|
|
|
case TranslationStatus::STATUS_APPROVED: |
|
37
|
|
|
if ( $lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_APPROVED ) { |
|
|
|
|
|
|
38
|
|
|
$state_prop = ( $xliffVersion === 2 ) ? "state=\"reviewed\"" : "state=\"signed-off\""; |
|
39
|
|
|
$lastMrkState = TranslationStatus::STATUS_APPROVED; |
|
40
|
|
|
} |
|
41
|
|
|
break; |
|
42
|
|
|
|
|
43
|
|
|
case TranslationStatus::STATUS_TRANSLATED: |
|
44
|
|
|
if ( $lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_TRANSLATED || $lastMrkState == TranslationStatus::STATUS_APPROVED ) { |
|
|
|
|
|
|
45
|
|
|
$state_prop = "state=\"translated\""; |
|
46
|
|
|
$lastMrkState = TranslationStatus::STATUS_TRANSLATED; |
|
47
|
|
|
} |
|
48
|
|
|
break; |
|
49
|
|
|
|
|
50
|
|
|
case TranslationStatus::STATUS_REJECTED: // if there is a mark REJECTED and there is not a DRAFT, all the trans-unit is REJECTED. In V2 there is no way to mark |
|
51
|
|
|
case TranslationStatus::STATUS_REBUTTED: |
|
52
|
|
|
if ( ( $lastMrkState == null ) || ( $lastMrkState != TranslationStatus::STATUS_NEW || $lastMrkState != TranslationStatus::STATUS_DRAFT ) ) { |
|
|
|
|
|
|
53
|
|
|
$state_prop = ( $xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"needs-review-translation\""; |
|
54
|
|
|
$lastMrkState = TranslationStatus::STATUS_REJECTED; |
|
55
|
|
|
} |
|
56
|
|
|
break; |
|
57
|
|
|
|
|
58
|
|
|
case TranslationStatus::STATUS_NEW: |
|
59
|
|
|
if ( ( $lastMrkState == null ) || $lastMrkState != TranslationStatus::STATUS_NEW ) { |
|
|
|
|
|
|
60
|
|
|
$state_prop = ( $xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"new\""; |
|
61
|
|
|
$lastMrkState = TranslationStatus::STATUS_NEW; |
|
62
|
|
|
} |
|
63
|
|
|
break; |
|
64
|
|
|
|
|
65
|
|
|
case TranslationStatus::STATUS_DRAFT: |
|
66
|
|
|
if ( ( $lastMrkState == null ) || $lastMrkState != TranslationStatus::STATUS_DRAFT ) { |
|
|
|
|
|
|
67
|
|
|
$state_prop = ( $xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"new\""; |
|
68
|
|
|
$lastMrkState = TranslationStatus::STATUS_DRAFT; |
|
69
|
|
|
} |
|
70
|
|
|
break; |
|
71
|
|
|
|
|
72
|
|
|
default: |
|
73
|
|
|
// this is the case when a segment is not showed in cattool, so the row in |
|
74
|
|
|
// segment_translations does not exists and |
|
75
|
|
|
// ---> $seg[ 'status' ] is NULL |
|
76
|
|
|
if ( $lastMrkState == null ) { //this is the first MRK ID |
|
|
|
|
|
|
77
|
|
|
$state_prop = "state=\"translated\""; |
|
78
|
|
|
$lastMrkState = TranslationStatus::STATUS_TRANSLATED; |
|
79
|
|
|
} else { |
|
|
|
|
|
|
80
|
|
|
/* Do nothing and preserve the last state */ |
|
81
|
|
|
} |
|
82
|
|
|
break; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return [ $state_prop, $lastMrkState ]; |
|
86
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
} |