52 if ( $this->messages !== null ) {
53 return $this->messages;
56 $data = $this->getRawData();
58 unset( $data[
'@metadata'] );
60 foreach ( $data as $key => $value ) {
65 if ( strlen( $key ) > 100 ) {
66 throw new MalformedBundle(
67 'translate-messagebundle-error-key-too-long',
72 if ( !preg_match(
'/^[a-zA-Z0-9-_.]+$/', $key ) ) {
73 throw new MalformedBundle(
74 'translate-messagebundle-error-key-invalid-characters',
79 if ( !is_string( $value ) ) {
80 throw new MalformedBundle(
81 'translate-messagebundle-error-invalid-value',
86 if ( trim( $value ) ===
'' ) {
87 throw new MalformedBundle(
88 'translate-messagebundle-error-empty-value',
94 $this->messages = $data;
95 return $this->messages;
100 if ( $this->metadata !== null ) {
101 return $this->metadata;
104 $data = $this->getRawData();
105 $metadata = $data[
'@metadata'] ?? [];
107 if ( !is_array( $metadata ) ) {
108 throw new MalformedBundle(
'translate-messagebundle-error-metadata-type' );
111 foreach ( $metadata as $key => $value ) {
112 if ( !in_array( $key, self::METADATA_KEYS ) ) {
113 throw new MalformedBundle(
114 'translate-messagebundle-error-invalid-metadata',
115 [ $key, Message::listParam( self::METADATA_KEYS ) ]
120 $sourceLanguage = $metadata[
'sourceLanguage'] ??
null;
121 if ( $sourceLanguage && !is_string( $sourceLanguage ) ) {
122 throw new MalformedBundle(
123 'translate-messagebundle-error-invalid-sourcelanguage', [ $sourceLanguage ]
127 $priorityLanguageCodes = $metadata[
'priorityLanguages'] ??
null;
128 if ( $priorityLanguageCodes ) {
129 if ( !is_array( $priorityLanguageCodes ) ) {
130 throw new MalformedBundle(
'translate-messagebundle-error-invalid-prioritylanguage-format' );
133 $priorityLanguageCodes = array_unique( $priorityLanguageCodes );
136 $description = $metadata[
'description'] ??
null;
137 if ( $description !==
null ) {
138 if ( !is_string( $description ) ) {
139 throw new MalformedBundle(
140 'translate-messagebundle-error-invalid-description'
144 $description = trim( $description ) ===
'' ? null : trim( $description );
147 $label = $metadata[
'label'] ??
null;
148 if ( $label !==
null ) {
149 if ( !is_string( $label ) ) {
150 throw new MalformedBundle(
151 'translate-messagebundle-error-invalid-label'
155 $label = trim( $label ) ===
'' ? null : trim( $label );
158 $this->metadata =
new MessageBundleMetadata(
160 $priorityLanguageCodes,
161 (
bool)( $metadata[
'allowOnlyPriorityLanguages'] ??
false ),
165 return $this->metadata;