Skip to content

Commit 6cb23be

Browse files
committed
Translatable forms.
1 parent 89acac3 commit 6cb23be

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/Traits/HasTranslation.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,25 @@ public function setTranslation($key, $locale, $value)
9999
$this->translatedAttributes[$locale][$key] = $value;
100100
}
101101

102+
103+
/**
104+
* @param $key
105+
* @param $locale
106+
* @return string|null
107+
*/
108+
public function getTranslation($key, $locale = null)
109+
{
110+
if (is_null($locale)) {
111+
$locale = $this->getCurrentLocale();
112+
}
113+
// We need to load translations.
114+
$this->loadTranslations();
115+
116+
if ($this->isTranslatable($key)) {
117+
return $this->translatedAttributes[$locale][$key] ?? null;
118+
}
119+
}
120+
102121
/**
103122
* @param $locale
104123
* @param null $key
@@ -136,23 +155,6 @@ public function setAttribute($key, $value)
136155
return parent::setAttribute($key, $value);
137156
}
138157

139-
/**
140-
* @param $key
141-
* @param $locale
142-
* @return string|null
143-
*/
144-
public function getTranslation($key, $locale = null)
145-
{
146-
if (is_null($locale)) {
147-
$locale = $this->getCurrentLocale();
148-
}
149-
// We need to load translations.
150-
$this->loadTranslations();
151-
152-
if ($this->isTranslatable($key)) {
153-
return $this->translatedAttributes[$locale][$key] ?? null;
154-
}
155-
}
156158

157159
/**
158160
* Load transaltions from database.

0 commit comments

Comments
 (0)