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