|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Translation\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
6
|
|
|
|
|
7
|
|
|
class Translation extends Model |
|
8
|
|
|
{ |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Table name in the database. |
|
12
|
|
|
* |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $table = 'translations'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* List of variables that can be mass assigned |
|
19
|
|
|
* |
|
20
|
|
|
* @var array |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $fillable = [ |
|
23
|
|
|
'locale', 'namespace', 'group', 'item', 'text', 'unstable', |
|
24
|
|
|
]; |
|
25
|
|
|
// from lararavel support |
|
26
|
|
|
// protected $fillable = ['table_name', 'column_name', 'foreign_key', 'locale', 'value']; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Each translation belongs to a language. |
|
30
|
|
|
*/ |
|
31
|
|
|
public function language() |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->belongsTo(Language::class, 'locale', 'locale'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Returns the full translation code for an entry: namespace.group.item |
|
38
|
|
|
* |
|
39
|
|
|
* @return string |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getCodeAttribute() |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->namespace === '*' ? "{$this->group}.{$this->item}" : "{$this->namespace}::{$this->group}.{$this->item}"; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Flag this entry as Reviewed |
|
48
|
|
|
* |
|
49
|
|
|
* @return void |
|
50
|
|
|
*/ |
|
51
|
|
|
public function flagAsReviewed() |
|
52
|
|
|
{ |
|
53
|
|
|
$this->unstable = 0; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Set the translation to the locked state |
|
58
|
|
|
* |
|
59
|
|
|
* @return void |
|
60
|
|
|
*/ |
|
61
|
|
|
public function lock() |
|
62
|
|
|
{ |
|
63
|
|
|
$this->locked = 1; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Check if the translation is locked |
|
68
|
|
|
* |
|
69
|
|
|
* @return boolean |
|
70
|
|
|
*/ |
|
71
|
|
|
public function isLocked() |
|
72
|
|
|
{ |
|
73
|
|
|
return (boolean) $this->locked; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* {@inheritdoc} |
|
78
|
|
|
*/ |
|
79
|
|
|
public function locale() |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->belongsTo(Locale::class, 'locale', 'code'); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* {@inheritdoc} |
|
86
|
|
|
*/ |
|
87
|
|
|
public function parent() |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->belongsTo(self::class, $this->getForeignKey()); |
|
90
|
|
|
} |
|
91
|
|
|
} |