Skip to content

Commit

Permalink
Min Support Plurals
Browse files Browse the repository at this point in the history
  • Loading branch information
MrEssex committed Jan 24, 2024
1 parent 7647fd5 commit f653980
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Cli/GenerateTPL.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected function _processMatches(array $matches, $file)
$this->_writeCatalog($catalog);
}

protected function _writeCatalog($catalog)
protected function _writeCatalog(DynamicArrayCatalog $catalog)
{
$root = rtrim($this->getContext()->getProjectRoot(), DIRECTORY_SEPARATOR);
$transDir = $root . DIRECTORY_SEPARATOR . 'translations' . DIRECTORY_SEPARATOR;
Expand Down
18 changes: 15 additions & 3 deletions src/Cli/Potoar.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,24 @@ protected function _processLanguage($source, $output): void
{
foreach($translation->getReferences() as $ref)
{
$out[] = "'" . $ref . "' => [";

if($translation->getSingularTranslation())
{
$out[] = "'" . $ref . "' => ['_' => '"
. addcslashes(stripslashes($this->_toTranslation($translation->getSingularTranslation())), "'")
. "'],";
$out[] = "'_' => '" . addcslashes(
stripslashes($this->_toTranslation($translation->getSingularTranslation())),
"'"
) . "',";
}

if($translation->getPluralTranslation())
{
$out[] = "'2..n' => '" . addcslashes(
stripslashes($this->_toTranslation($translation->getPluralTranslation())),
"'"
) . "',";
}
$out[] = "],";
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/Cli/Translate.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,16 @@ protected function _createTranslations($mid, $options, $lang, PoFile $poEdit): v
unset($options['n']);
}

$tran->setAdditionalPluralTranslations($options);
if(isset($options['n..0,2..n']))
{
$tran->setSingularSource($options[1]);
$tran->setPluralSource($options['n..0,2..n']);

$tran->setSingularTranslation($this->_getTranslation($options[1], $lang));
$tran->setPluralTranslation($this->_getTranslation($options['n..0,2..n'], $lang));
unset($options['n..0,2..n']);
}

$poEdit->addTranslation($tran);
}

Expand Down

0 comments on commit f653980

Please sign in to comment.