Commit | Line | Data |
---|---|---|
89ab2f67 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | Copyright CiviCRM LLC. All rights reserved. | | |
5 | | | | |
6 | | This work is published under the GNU AGPLv3 license with some | | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
9 | +--------------------------------------------------------------------+ | |
10 | */ | |
11 | ||
12 | namespace Civi\WorkflowMessage\Traits; | |
13 | ||
14 | trait LocalizationTrait { | |
15 | ||
16 | /** | |
17 | * @var string|null | |
18 | * @scope tokenContext | |
19 | */ | |
20 | protected $locale; | |
21 | ||
22 | /** | |
23 | * @return string | |
24 | */ | |
25 | public function getLocale(): ?string { | |
26 | return $this->locale; | |
27 | } | |
28 | ||
29 | /** | |
30 | * @param string|null $locale | |
31 | * @return $this | |
32 | */ | |
33 | public function setLocale(?string $locale) { | |
34 | $this->locale = $locale; | |
35 | return $this; | |
36 | } | |
37 | ||
38 | protected function validateExtra_localization(&$errors) { | |
39 | $allLangs = \CRM_Core_I18n::languages(); | |
40 | if ($this->locale !== NULL && !isset($allLangs[$this->locale])) { | |
41 | $errors[] = [ | |
42 | 'severity' => 'error', | |
43 | 'fields' => ['locale'], | |
44 | 'name' => 'badLocale', | |
45 | 'message' => ts('The given locale is not valid (%1)', [json_encode($this->locale)]), | |
46 | ]; | |
47 | } | |
48 | } | |
49 | ||
50 | } |