12 protected $translation =
'';
14 protected $pluralTranslation = array();
15 protected $references = array();
16 protected $comments = array();
17 protected $extractedComments = array();
18 protected $flags = array();
31 return "{$context}\004{$original}";
44 $this->original = (string) $original;
46 $this->setPlural($plural);
63 if ($original !==
null) {
64 $new->original = (string) $original;
77 return static::generateId($this->context, $this->original);
90 return (($this->context ===
$context) && ($this->original === $original)) ? true :
false;
100 return $this->original;
110 return ($this->original !==
'') ? true :
false;
120 $this->translation = (string) $translation;
130 return $this->translation;
140 return ($this->translation !==
'') ? true :
false;
150 $this->plural = (string) $plural;
152 $this->normalizeTranslationCount();
162 return $this->plural;
172 return ($this->plural !==
'') ? true :
false;
183 $this->pluralTranslation[
$key] = $plural;
184 $this->normalizeTranslationCount();
197 return $this->pluralTranslation;
200 return isset($this->pluralTranslation[
$key]) ? (string) $this->pluralTranslation[
$key] :
'';
210 return implode(
'', $this->pluralTranslation) !==
'';
218 $this->pluralTranslation = array();
220 $this->normalizeTranslationCount();
230 $this->translationCount = is_null($count) ? null : intval($count);
232 $this->normalizeTranslationCount();
243 return $this->hasPlural() ? $this->translationCount :
null;
251 if ($this->translationCount ===
null) {
255 if ($this->hasPlural()) {
256 $allowed = $this->translationCount - 1;
257 $current = count($this->pluralTranslation);
260 $this->pluralTranslation = $this->pluralTranslation + array_fill(0, $allowed,
'');
262 $this->pluralTranslation = array_slice($this->pluralTranslation, 0, $allowed);
265 $this->pluralTranslation = array();
286 return (isset($this->context) && ($this->context !==
'')) ? true :
false;
297 $key =
"{$filename}:{$line}";
308 return !empty($this->references);
318 return array_values($this->references);
326 $this->references = array();
346 return isset($this->comments[0]);
356 return $this->comments;
364 $this->comments = array();
374 $this->extractedComments[] =
$comment;
384 return isset($this->extractedComments[0]);
394 return $this->extractedComments;
402 $this->extractedComments = array();
412 $this->flags[] = $flag;
422 return isset($this->flags[0]);
440 $this->flags = array();
451 if ($method ===
null) {
452 $method = Translations::$mergeDefault;
455 if (!$this->hasTranslation() || ($translation->
hasTranslation() && ($method & Translations::MERGE_OVERRIDE))) {
459 if (($method & Translations::MERGE_PLURAL) && !$this->hasPlural()) {
460 $this->setPlural($translation->
getPlural());
463 if ($this->hasPlural() && !$this->hasPluralTranslation() && $translation->
hasPluralTranslation()) {
467 if ($method & Translations::MERGE_REFERENCES) {
469 $this->addReference($reference[0], $reference[1]);
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)));
An exception for terminatinating execution or to throw for unit testing.
Class to manage a translation string.
addExtractedComment($comment)
Adds a new extracted comment for this translation.
getPluralTranslation($key=null)
Gets one or all plural translations.
normalizeTranslationCount()
Normalizes the translation count.
deleteComments()
Removes all comments.
hasContext()
Checks if the context is empty or not.
getComments()
Returns all comments for this translation.
hasExtractedComments()
Checks if the translation has any extracted comment.
getFlags()
Returns all extracted flags for this translation.
hasReferences()
Checks if the translation has any reference.
deletePluralTranslation()
Removes all plural translations.
hasFlags()
Checks if the translation has any flag.
hasOriginal()
Checks if the original string is empty or not.
deleteFlags()
Removes all flags.
hasComments()
Checks if the translation has any comment.
getTranslationCount()
Returns the number of singular + plural translations Returns null if this Translation is not a plural...
setTranslationCount($count)
Set the number of singular + plural translations allowed.
getContext()
Gets the context of this translation.
addReference($filename, $line=null)
Adds a new reference for this translation.
getTranslation()
Gets the translation string.
addFlag($flag)
Adds a new flat for this translation.
deleteReferences()
Removes all references.
static generateId($context, $original)
Generates the id of a translation (context + glue + original).
is($context, $original='')
Checks whether the translation matches with the arguments.
getPlural()
Gets the plural translation string.
setPlural($plural)
Sets the plural translation string.
hasPlural()
Checks if the plural translation string is empty or not.
getReferences()
Return all references for this translation.
setPluralTranslation($plural, $key=0)
Set a new plural translation.
__construct($context, $original, $plural='')
Construct.
getOriginal()
Gets the original string.
mergeWith(Translation $translation, $method=null)
Merges this translation with other translation.
addComment($comment)
Adds a new comment for this translation.
deleteExtractedComments()
Removes all extracted comments.
getClone($context=null, $original=null)
Clones this translation.
hasTranslation()
Checks if the translation string is empty or not.
hasPluralTranslation()
Checks if there are any plural translation.
getExtractedComments()
Returns all extracted comments for this translation.
setTranslation($translation)
Sets the translation string.
getId()
Returns the id of this translation.