ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
Language.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use ILIAS\Language\Language as SystemLanguage;
27use ILIAS\Refinery\Factory as Refinery;
28
30{
31 public const KEY_LANGUAGE = 'language';
32 public const KEY_BASE = 'base';
33 public const KEY_DEFAULT = 'default';
34 public const KEY_TITLE = 'title';
35 public const KEY_DESCRIPTION = 'description';
36
37 public function __construct(
38 private readonly string $language_code,
39 private string $title,
40 private string $description,
41 private bool $default = false,
42 private bool $base = false
43 ) {
44 }
45
46 public function getLanguageCode(): string
47 {
48 return $this->language_code;
49 }
50
51 public function getTitle(): string
52 {
53 return $this->title;
54 }
55
56 public function withTitle(string $title): self
57 {
58 $clone = clone $this;
59 $clone->title = $title;
60 return $clone;
61 }
62
63 public function getDescription(): string
64 {
65 return $this->description;
66 }
67
68 public function withDescription(string $description): self
69 {
70 $clone = clone $this;
71 $clone->description = $description;
72 return $clone;
73 }
74
75 public function isDefault(): bool
76 {
77 return $this->default;
78 }
79
80 public function withDefault(bool $default): self
81 {
82 $clone = clone $this;
83 $clone->default = $default;
84 return $clone;
85 }
86
87 public function isBase(): bool
88 {
89 return $this->base;
90 }
91
92 public function withBase(bool $base): self
93 {
94 $clone = clone $this;
95 $clone->base = $base;
96 return $clone;
97 }
98
99 public function toForm(
100 \ilLanguage $language,
101 FieldFactory $field_factory,
103 ): array {
104 return [
105 $field_factory->group([
106 self::KEY_LANGUAGE => $field_factory->hidden()->withValue($this->language_code),
107 self::KEY_TITLE => $field_factory->text($language->txt('title'))
108 ->withRequired(true)
109 ->withValue($this->title),
110 self::KEY_DESCRIPTION => $field_factory->textarea($language->txt('description'))
111 ->withValue($this->description),
112 self::KEY_DEFAULT => $field_factory->hidden()->withValue($this->isDefault()),
113 self::KEY_BASE => $field_factory->hidden()->withValue($this->isBase()),
115 $refinery->custom()->transformation(
116 static fn(array $vs): self => new self(
117 $vs[self::KEY_LANGUAGE],
118 $vs[self::KEY_TITLE],
119 $vs[self::KEY_DESCRIPTION],
120 $vs[self::KEY_DEFAULT] === '1',
121 $vs[self::KEY_BASE] === '1'
122 )
123 )
124 )
125 ];
126 }
127
128 public function toRow(
129 DataRowBuilder $row_builder,
130 SystemLanguage $lng
131 ): DataRow {
132 return $row_builder->buildDataRow(
133 $this->language_code,
134 [
135 self::KEY_LANGUAGE => $this->getTranslatedLanguageName($lng, $this->language_code),
136 self::KEY_BASE => $this->isBase(),
137 self::KEY_DEFAULT => $this->isDefault(),
138 self::KEY_TITLE => $this->getTitle(),
139 self::KEY_DESCRIPTION => $this->getDescription()
140 ]
141 )->withDisabledAction(TranslationsTable::ACTION_DELETE, $this->isBase() || $this->isDefault())
142 ->withDisabledAction(TranslationsTable::ACTION_MAKE_DEFAULT, $this->isDefault());
143 }
144
145 public function getDisplayValueForKey(
146 SystemLanguage $lng,
147 string $key
148 ): string|bool {
149 return match($key) {
150 self::KEY_LANGUAGE => $this->getTranslatedLanguageName(
151 $lng,
152 $this->language_code
153 ),
154 self::KEY_BASE => $this->base,
155 self::KEY_DEFAULT => $this->default,
156 self::KEY_TITLE => $this->title,
157 self::KEY_DESCRIPTION => $this->description
158 };
159 }
160
162 SystemLanguage $lng,
163 string $language_code
164 ): string {
165 return $lng->txt("meta_l_{$language_code}");
166 }
167}
Builds data types.
Definition: Factory.php:36
getTranslatedLanguageName(SystemLanguage $lng, string $language_code)
Definition: Language.php:161
toForm(\ilLanguage $language, FieldFactory $field_factory, Refinery $refinery)
Definition: Language.php:99
__construct(private readonly string $language_code, private string $title, private string $description, private bool $default=false, private bool $base=false)
Definition: Language.php:37
getDisplayValueForKey(SystemLanguage $lng, string $key)
Definition: Language.php:145
toRow(DataRowBuilder $row_builder, SystemLanguage $lng)
Definition: Language.php:128
language handling
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This is what a factory for input fields looks like.
Definition: Factory.php:31
withAdditionalTransformation(Transformation $trafo)
@inheritDoc
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61
global $lng
Definition: privfeed.php:26