ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Gettext\Translation Class Reference

Class to manage a translation string. More...

+ Collaboration diagram for Gettext\Translation:

Public Member Functions

 __construct ($context, $original, $plural='')
 Construct. More...
 
 getClone ($context=null, $original=null)
 Clones this translation. More...
 
 getId ()
 Returns the id of this translation. More...
 
 is ($context, $original='')
 Checks whether the translation matches with the arguments. More...
 
 getOriginal ()
 Gets the original string. More...
 
 hasOriginal ()
 Checks if the original string is empty or not. More...
 
 setTranslation ($translation)
 Sets the translation string. More...
 
 getTranslation ()
 Gets the translation string. More...
 
 hasTranslation ()
 Checks if the translation string is empty or not. More...
 
 setPlural ($plural)
 Sets the plural translation string. More...
 
 getPlural ()
 Gets the plural translation string. More...
 
 hasPlural ()
 Checks if the plural translation string is empty or not. More...
 
 setPluralTranslation ($plural, $key=0)
 Set a new plural translation. More...
 
 getPluralTranslation ($key=null)
 Gets one or all plural translations. More...
 
 hasPluralTranslation ()
 Checks if there are any plural translation. More...
 
 deletePluralTranslation ()
 Removes all plural translations. More...
 
 setTranslationCount ($count)
 Set the number of singular + plural translations allowed. More...
 
 getTranslationCount ()
 Returns the number of singular + plural translations Returns null if this Translation is not a plural one. More...
 
 getContext ()
 Gets the context of this translation. More...
 
 hasContext ()
 Checks if the context is empty or not. More...
 
 addReference ($filename, $line=null)
 Adds a new reference for this translation. More...
 
 hasReferences ()
 Checks if the translation has any reference. More...
 
 getReferences ()
 Return all references for this translation. More...
 
 deleteReferences ()
 Removes all references. More...
 
 addComment ($comment)
 Adds a new comment for this translation. More...
 
 hasComments ()
 Checks if the translation has any comment. More...
 
 getComments ()
 Returns all comments for this translation. More...
 
 deleteComments ()
 Removes all comments. More...
 
 addExtractedComment ($comment)
 Adds a new extracted comment for this translation. More...
 
 hasExtractedComments ()
 Checks if the translation has any extracted comment. More...
 
 getExtractedComments ()
 Returns all extracted comments for this translation. More...
 
 deleteExtractedComments ()
 Removes all extracted comments. More...
 
 addFlag ($flag)
 Adds a new flat for this translation. More...
 
 hasFlags ()
 Checks if the translation has any flag. More...
 
 getFlags ()
 Returns all extracted flags for this translation. More...
 
 deleteFlags ()
 Removes all flags. More...
 
 mergeWith (Translation $translation, $method=null)
 Merges this translation with other translation. More...
 

Static Public Member Functions

static generateId ($context, $original)
 Generates the id of a translation (context + glue + original). More...
 

Protected Member Functions

 normalizeTranslationCount ()
 Normalizes the translation count. More...
 

Protected Attributes

 $context
 
 $original
 
 $translation = ''
 
 $plural
 
 $pluralTranslation = array()
 
 $references = array()
 
 $comments = array()
 
 $extractedComments = array()
 
 $flags = array()
 
 $translationCount
 

Detailed Description

Class to manage a translation string.

Definition at line 8 of file Translation.php.

Constructor & Destructor Documentation

◆ __construct()

Gettext\Translation::__construct (   $context,
  $original,
  $plural = '' 
)

Construct.

Parameters
string$contextThe context of the translation
string$originalThe original string
string$pluralThe original plural string

Definition at line 41 of file Translation.php.

References string.

42  {
43  $this->context = (string) $context;
44  $this->original = (string) $original;
45 
46  $this->setPlural($plural);
47  }
Add rich text string
setPlural($plural)
Sets the plural translation string.

Member Function Documentation

◆ addComment()

Gettext\Translation::addComment (   $comment)

Adds a new comment for this translation.

Parameters
string$comment

Definition at line 334 of file Translation.php.

References $comment, and comments.

335  {
336  $this->comments[] = $comment;
337  }
$comment
Definition: buildRTE.php:83
Add comments

◆ addExtractedComment()

Gettext\Translation::addExtractedComment (   $comment)

Adds a new extracted comment for this translation.

Parameters
string$comment

Definition at line 372 of file Translation.php.

References $comment.

373  {
374  $this->extractedComments[] = $comment;
375  }
$comment
Definition: buildRTE.php:83

◆ addFlag()

Gettext\Translation::addFlag (   $flag)

Adds a new flat for this translation.

Parameters
string$flag

Definition at line 410 of file Translation.php.

411  {
412  $this->flags[] = $flag;
413  }

◆ addReference()

Gettext\Translation::addReference (   $filename,
  $line = null 
)

Adds a new reference for this translation.

Parameters
string$filenameThe file path where the translation has been found
null | int$lineThe line number where the translation has been found

Definition at line 295 of file Translation.php.

References $filename, $key, and array.

296  {
297  $key = "{$filename}:{$line}";
298  $this->references[$key] = array($filename, $line);
299  }
Create styles array
The data for the language used.
$key
Definition: croninfo.php:18

◆ deleteComments()

Gettext\Translation::deleteComments ( )

Removes all comments.

Definition at line 362 of file Translation.php.

References array, and comments.

363  {
364  $this->comments = array();
365  }
Create styles array
The data for the language used.
Add comments

◆ deleteExtractedComments()

Gettext\Translation::deleteExtractedComments ( )

Removes all extracted comments.

Definition at line 400 of file Translation.php.

References array.

401  {
402  $this->extractedComments = array();
403  }
Create styles array
The data for the language used.

◆ deleteFlags()

Gettext\Translation::deleteFlags ( )

Removes all flags.

Definition at line 438 of file Translation.php.

References array.

439  {
440  $this->flags = array();
441  }
Create styles array
The data for the language used.

◆ deletePluralTranslation()

Gettext\Translation::deletePluralTranslation ( )

Removes all plural translations.

Definition at line 216 of file Translation.php.

References array.

217  {
218  $this->pluralTranslation = array();
219 
220  $this->normalizeTranslationCount();
221  }
normalizeTranslationCount()
Normalizes the translation count.
Create styles array
The data for the language used.

◆ deleteReferences()

Gettext\Translation::deleteReferences ( )

Removes all references.

Definition at line 324 of file Translation.php.

References array.

325  {
326  $this->references = array();
327  }
Create styles array
The data for the language used.

◆ generateId()

static Gettext\Translation::generateId (   $context,
  $original 
)
static

Generates the id of a translation (context + glue + original).

Parameters
string$context
string$original
Returns
string

Definition at line 29 of file Translation.php.

30  {
31  return "{$context}\004{$original}";
32  }

◆ getClone()

Gettext\Translation::getClone (   $context = null,
  $original = null 
)

Clones this translation.

Parameters
null | string$contextOptional new context
null | string$originalOptional new original

Definition at line 55 of file Translation.php.

References $new, and string.

56  {
57  $new = clone $this;
58 
59  if ($context !== null) {
60  $new->context = (string) $context;
61  }
62 
63  if ($original !== null) {
64  $new->original = (string) $original;
65  }
66 
67  return $new;
68  }
Add rich text string

◆ getComments()

Gettext\Translation::getComments ( )

Returns all comments for this translation.

Returns
array

Definition at line 354 of file Translation.php.

Referenced by Gettext\Translation\mergeWith().

355  {
356  return $this->comments;
357  }
+ Here is the caller graph for this function:

◆ getContext()

Gettext\Translation::getContext ( )

Gets the context of this translation.

Returns
string

Definition at line 274 of file Translation.php.

275  {
276  return $this->context;
277  }

◆ getExtractedComments()

Gettext\Translation::getExtractedComments ( )

Returns all extracted comments for this translation.

Returns
array

Definition at line 392 of file Translation.php.

Referenced by Gettext\Translation\mergeWith().

393  {
395  }
+ Here is the caller graph for this function:

◆ getFlags()

Gettext\Translation::getFlags ( )

Returns all extracted flags for this translation.

Returns
array

Definition at line 430 of file Translation.php.

Referenced by Gettext\Translation\mergeWith().

431  {
432  return $this->flags;
433  }
+ Here is the caller graph for this function:

◆ getId()

Gettext\Translation::getId ( )

Returns the id of this translation.

Returns
string

Definition at line 75 of file Translation.php.

76  {
77  return static::generateId($this->context, $this->original);
78  }

◆ getOriginal()

Gettext\Translation::getOriginal ( )

Gets the original string.

Returns
string

Definition at line 98 of file Translation.php.

99  {
100  return $this->original;
101  }

◆ getPlural()

Gettext\Translation::getPlural ( )

Gets the plural translation string.

Returns
string

Definition at line 160 of file Translation.php.

Referenced by Gettext\Translation\mergeWith().

161  {
162  return $this->plural;
163  }
+ Here is the caller graph for this function:

◆ getPluralTranslation()

Gettext\Translation::getPluralTranslation (   $key = null)

Gets one or all plural translations.

Parameters
int | null$keyThe key to return. If is null, return all translations
Returns
string|array

Definition at line 194 of file Translation.php.

References $key, and string.

Referenced by Gettext\Translation\mergeWith().

195  {
196  if ($key === null) {
198  }
199 
200  return isset($this->pluralTranslation[$key]) ? (string) $this->pluralTranslation[$key] : '';
201  }
Add rich text string
$key
Definition: croninfo.php:18
+ Here is the caller graph for this function:

◆ getReferences()

Gettext\Translation::getReferences ( )

Return all references for this translation.

Returns
array

Definition at line 316 of file Translation.php.

Referenced by Gettext\Translation\mergeWith().

317  {
318  return array_values($this->references);
319  }
+ Here is the caller graph for this function:

◆ getTranslation()

Gettext\Translation::getTranslation ( )

Gets the translation string.

Returns
string

Definition at line 128 of file Translation.php.

Referenced by Gettext\Translation\mergeWith().

129  {
130  return $this->translation;
131  }
+ Here is the caller graph for this function:

◆ getTranslationCount()

Gettext\Translation::getTranslationCount ( )

Returns the number of singular + plural translations Returns null if this Translation is not a plural one.

Returns
int|null

Definition at line 241 of file Translation.php.

242  {
243  return $this->hasPlural() ? $this->translationCount : null;
244  }
hasPlural()
Checks if the plural translation string is empty or not.

◆ hasComments()

Gettext\Translation::hasComments ( )

Checks if the translation has any comment.

Returns
bool

Definition at line 344 of file Translation.php.

References comments.

345  {
346  return isset($this->comments[0]);
347  }
Add comments

◆ hasContext()

Gettext\Translation::hasContext ( )

Checks if the context is empty or not.

Returns
bool

Definition at line 284 of file Translation.php.

285  {
286  return (isset($this->context) && ($this->context !== '')) ? true : false;
287  }

◆ hasExtractedComments()

Gettext\Translation::hasExtractedComments ( )

Checks if the translation has any extracted comment.

Returns
bool

Definition at line 382 of file Translation.php.

383  {
384  return isset($this->extractedComments[0]);
385  }

◆ hasFlags()

Gettext\Translation::hasFlags ( )

Checks if the translation has any flag.

Returns
bool

Definition at line 420 of file Translation.php.

421  {
422  return isset($this->flags[0]);
423  }

◆ hasOriginal()

Gettext\Translation::hasOriginal ( )

Checks if the original string is empty or not.

Returns
bool

Definition at line 108 of file Translation.php.

109  {
110  return ($this->original !== '') ? true : false;
111  }

◆ hasPlural()

Gettext\Translation::hasPlural ( )

Checks if the plural translation string is empty or not.

Returns
bool

Definition at line 170 of file Translation.php.

171  {
172  return ($this->plural !== '') ? true : false;
173  }

◆ hasPluralTranslation()

Gettext\Translation::hasPluralTranslation ( )

Checks if there are any plural translation.

Returns
bool

Definition at line 208 of file Translation.php.

Referenced by Gettext\Translation\mergeWith().

209  {
210  return implode('', $this->pluralTranslation) !== '';
211  }
+ Here is the caller graph for this function:

◆ hasReferences()

Gettext\Translation::hasReferences ( )

Checks if the translation has any reference.

Returns
bool

Definition at line 306 of file Translation.php.

307  {
308  return !empty($this->references);
309  }

◆ hasTranslation()

Gettext\Translation::hasTranslation ( )

Checks if the translation string is empty or not.

Returns
bool

Definition at line 138 of file Translation.php.

Referenced by Gettext\Translation\mergeWith().

139  {
140  return ($this->translation !== '') ? true : false;
141  }
+ Here is the caller graph for this function:

◆ is()

Gettext\Translation::is (   $context,
  $original = '' 
)

Checks whether the translation matches with the arguments.

Parameters
string$context
string$original
Returns
bool

Definition at line 88 of file Translation.php.

89  {
90  return (($this->context === $context) && ($this->original === $original)) ? true : false;
91  }

◆ mergeWith()

Gettext\Translation::mergeWith ( Translation  $translation,
  $method = null 
)

Merges this translation with other translation.

Parameters
Translation$translationThe translation to merge with
int | null$methodOne or various Translations::MERGE_* constants to define how to merge the translations

Definition at line 449 of file Translation.php.

References comments, Gettext\Translation\getComments(), Gettext\Translation\getExtractedComments(), Gettext\Translation\getFlags(), Gettext\Translation\getPlural(), Gettext\Translation\getPluralTranslation(), Gettext\Translation\getReferences(), Gettext\Translation\getTranslation(), Gettext\Translation\hasPluralTranslation(), and Gettext\Translation\hasTranslation().

450  {
451  if ($method === null) {
452  $method = Translations::$mergeDefault;
453  }
454 
455  if (!$this->hasTranslation() || ($translation->hasTranslation() && ($method & Translations::MERGE_OVERRIDE))) {
456  $this->setTranslation($translation->getTranslation());
457  }
458 
459  if (($method & Translations::MERGE_PLURAL) && !$this->hasPlural()) {
460  $this->setPlural($translation->getPlural());
461  }
462 
463  if ($this->hasPlural() && !$this->hasPluralTranslation() && $translation->hasPluralTranslation()) {
464  $this->pluralTranslation = $translation->getPluralTranslation();
465  }
466 
467  if ($method & Translations::MERGE_REFERENCES) {
468  foreach ($translation->getReferences() as $reference) {
469  $this->addReference($reference[0], $reference[1]);
470  }
471  }
472 
473  if ($method & Translations::MERGE_COMMENTS) {
474  $this->comments = array_values(array_unique(array_merge($translation->getComments(), $this->comments)));
475  $this->extractedComments = array_values(array_unique(array_merge($translation->getExtractedComments(), $this->extractedComments)));
476  $this->flags = array_values(array_unique(array_merge($translation->getFlags(), $this->flags)));
477  }
478  }
setTranslation($translation)
Sets the translation string.
hasTranslation()
Checks if the translation string is empty or not.
addReference($filename, $line=null)
Adds a new reference for this translation.
hasPlural()
Checks if the plural translation string is empty or not.
hasPluralTranslation()
Checks if there are any plural translation.
setPlural($plural)
Sets the plural translation string.
Add comments
+ Here is the call graph for this function:

◆ normalizeTranslationCount()

Gettext\Translation::normalizeTranslationCount ( )
protected

Normalizes the translation count.

Definition at line 249 of file Translation.php.

References $current, and array.

250  {
251  if ($this->translationCount === null) {
252  return;
253  }
254 
255  if ($this->hasPlural()) {
256  $allowed = $this->translationCount - 1;
257  $current = count($this->pluralTranslation);
258 
259  if ($allowed > $current) {
260  $this->pluralTranslation = $this->pluralTranslation + array_fill(0, $allowed, '');
261  } elseif ($current > $allowed) {
262  $this->pluralTranslation = array_slice($this->pluralTranslation, 0, $allowed);
263  }
264  } else {
265  $this->pluralTranslation = array();
266  }
267  }
hasPlural()
Checks if the plural translation string is empty or not.
Create styles array
The data for the language used.

◆ setPlural()

Gettext\Translation::setPlural (   $plural)

Sets the plural translation string.

Parameters
string$plural

Definition at line 148 of file Translation.php.

References string.

149  {
150  $this->plural = (string) $plural;
151 
152  $this->normalizeTranslationCount();
153  }
Add rich text string
normalizeTranslationCount()
Normalizes the translation count.

◆ setPluralTranslation()

Gettext\Translation::setPluralTranslation (   $plural,
  $key = 0 
)

Set a new plural translation.

Parameters
string$pluralThe plural string to add
int$keyThe key of the plural translation.

Definition at line 181 of file Translation.php.

References $key.

182  {
183  $this->pluralTranslation[$key] = $plural;
184  $this->normalizeTranslationCount();
185  }
normalizeTranslationCount()
Normalizes the translation count.
$key
Definition: croninfo.php:18

◆ setTranslation()

Gettext\Translation::setTranslation (   $translation)

Sets the translation string.

Parameters
string$translation

Definition at line 118 of file Translation.php.

References string.

119  {
120  $this->translation = (string) $translation;
121  }
Add rich text string

◆ setTranslationCount()

Gettext\Translation::setTranslationCount (   $count)

Set the number of singular + plural translations allowed.

Parameters
int$count

Definition at line 228 of file Translation.php.

229  {
230  $this->translationCount = is_null($count) ? null : intval($count);
231 
232  $this->normalizeTranslationCount();
233  }
normalizeTranslationCount()
Normalizes the translation count.

Field Documentation

◆ $comments

Gettext\Translation::$comments = array()
protected

Definition at line 16 of file Translation.php.

◆ $context

Gettext\Translation::$context
protected

Definition at line 10 of file Translation.php.

◆ $extractedComments

Gettext\Translation::$extractedComments = array()
protected

Definition at line 17 of file Translation.php.

◆ $flags

Gettext\Translation::$flags = array()
protected

Definition at line 18 of file Translation.php.

◆ $original

Gettext\Translation::$original
protected

Definition at line 11 of file Translation.php.

◆ $plural

Gettext\Translation::$plural
protected

Definition at line 13 of file Translation.php.

◆ $pluralTranslation

Gettext\Translation::$pluralTranslation = array()
protected

Definition at line 14 of file Translation.php.

◆ $references

Gettext\Translation::$references = array()
protected

Definition at line 15 of file Translation.php.

◆ $translation

Gettext\Translation::$translation = ''
protected

Definition at line 12 of file Translation.php.

◆ $translationCount

Gettext\Translation::$translationCount
protected

Definition at line 19 of file Translation.php.


The documentation for this class was generated from the following file: