mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-12-02 13:32:43 -05:00
* Add English references to DIRTY translation comments Translators currently have to find the English source separately for each `// DIRTY` entry. The translation formatter now appends it on the same line, including English plural fallback for languages with additional plural forms. It keeps hints on one safe PHP comment line and refreshes them when English changes. Only comments change in the locale files; translation values and plural rules are unchanged. Single-form translations show both English forms as `Singular: … | Plural: …`. Generated README contribution links match bare and annotated TODO/DIRTY markers and retain the end-of-line anchor. Closes #9463. * Show both English forms for single-form translations
86 lines
1.7 KiB
PHP
86 lines
1.7 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
class I18nValue implements \Stringable {
|
|
private const STATE_DIRTY = 'dirty';
|
|
public const STATE_IGNORE = 'ignore';
|
|
private const STATE_TODO = 'todo';
|
|
private const STATES = [
|
|
self::STATE_DIRTY,
|
|
self::STATE_IGNORE,
|
|
self::STATE_TODO,
|
|
];
|
|
|
|
private readonly string $value;
|
|
private ?string $state = null;
|
|
|
|
/** @param I18nValue|string $data */
|
|
public function __construct(I18nValue|string $data) {
|
|
if ($data instanceof I18nValue) {
|
|
$data = $data->__toString();
|
|
}
|
|
$data = explode(' -> ', $data);
|
|
|
|
$this->value = (string)(array_shift($data) ?? '');
|
|
if (count($data) === 0) {
|
|
return;
|
|
}
|
|
|
|
$state = array_shift($data);
|
|
if (in_array($state, self::STATES, true)) {
|
|
$this->state = $state;
|
|
}
|
|
}
|
|
|
|
public function __clone(): void {
|
|
$this->markAsTodo();
|
|
}
|
|
|
|
public function equal(I18nValue $value): bool {
|
|
return $this->value === $value->getValue();
|
|
}
|
|
|
|
public function isIgnore(): bool {
|
|
return $this->state === self::STATE_IGNORE;
|
|
}
|
|
|
|
public function isDirty(): bool {
|
|
return $this->state === self::STATE_DIRTY;
|
|
}
|
|
|
|
public function isTodo(): bool {
|
|
return $this->state === self::STATE_TODO;
|
|
}
|
|
|
|
public function markAsDirty(): void {
|
|
$this->state = self::STATE_DIRTY;
|
|
}
|
|
|
|
public function markAsIgnore(): void {
|
|
$this->state = self::STATE_IGNORE;
|
|
}
|
|
|
|
public function markAsTodo(): void {
|
|
$this->state = self::STATE_TODO;
|
|
}
|
|
|
|
public function unmarkAsIgnore(): void {
|
|
if ($this->state === self::STATE_IGNORE) {
|
|
$this->state = null;
|
|
}
|
|
}
|
|
|
|
#[\Override]
|
|
public function __toString(): string {
|
|
if ($this->state === null) {
|
|
return $this->value;
|
|
}
|
|
|
|
return "{$this->value} -> {$this->state}";
|
|
}
|
|
|
|
public function getValue(): string {
|
|
return $this->value;
|
|
}
|
|
}
|