diff options
| author | 2022-01-08 08:00:26 -0500 | |
|---|---|---|
| committer | 2022-01-08 14:00:26 +0100 | |
| commit | 127b7f0a3aad7012055c058e8aba0d27192a8cbc (patch) | |
| tree | 8ec9a5948672e702c944c202f78294b81104582f /cli/i18n/I18nValue.php | |
| parent | ed19445f74c30854c60873cd1df1c38e15fc316b (diff) | |
Change i18n process (#4131)
Before, the ignore info were stored in a different file which was a bit cumbersome
for new comers. Now, this info is stored directly in the translation file as a
comment.
Before, there was no way of telling translators that a previously translated string
was in need of a new translation. Now, the dirty information is there to convey that
info.
Diffstat (limited to 'cli/i18n/I18nValue.php')
| -rw-r--r-- | cli/i18n/I18nValue.php | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/cli/i18n/I18nValue.php b/cli/i18n/I18nValue.php new file mode 100644 index 000000000..e691b8574 --- /dev/null +++ b/cli/i18n/I18nValue.php @@ -0,0 +1,75 @@ +<?php + +class I18nValue { + private const STATE_DIRTY = 'dirty'; + private const STATE_IGNORE = 'ignore'; + private const STATE_TODO = 'todo'; + private const STATES = [ + self::STATE_DIRTY, + self::STATE_IGNORE, + self::STATE_TODO, + ]; + + private $value; + private $state; + + public function __construct(string $data) { + $data = explode(' -> ', $data); + + $this->value = array_shift($data); + if (count($data) === 0) { + return; + } + + $state = array_shift($data); + if (in_array($state, self::STATES)) { + $this->state = $state; + } + } + + public function __clone() { + $this->markAsTodo(); + } + + public function equal(I18nValue $value) { + return $this->value === $value->getValue(); + } + + public function isIgnore() { + return $this->state === self::STATE_IGNORE; + } + + public function isTodo() { + return $this->state === self::STATE_TODO; + } + + public function markAsDirty() { + $this->state = self::STATE_DIRTY; + } + + public function markAsIgnore() { + $this->state = self::STATE_IGNORE; + } + + public function markAsTodo() { + $this->state = self::STATE_TODO; + } + + public function unmarkAsIgnore() { + if ($this->state === self::STATE_IGNORE) { + $this->state = null; + } + } + + public function __toString() { + if ($this->state === null) { + return $this->value; + } + + return "{$this->value} -> {$this->state}"; + } + + public function getValue() { + return $this->value; + } +} |
