mirror of
https://github.com/processwire/processwire.git
synced 2025-08-12 01:34:31 +02:00
Add feature request processwire/processwire-issues#1757 which adds support for non-plural translations of 0 quantities in the _n('%d item', %d items', 0);
translation function. To use, translate the file wire/modules/LanguageSupport/LanguageTranslator.php and edi the "Is zero (0) plural or singular?" setting at the top.
This commit is contained in:
@@ -284,7 +284,15 @@ function _x($text, $context, $textdomain = null) {
|
||||
*
|
||||
*/
|
||||
function _n($textSingular, $textPlural, $count, $textdomain = null) {
|
||||
return $count == 1 ? __($textSingular, $textdomain) : __($textPlural, $textdomain);
|
||||
$count = (int) $count;
|
||||
$value = $count === 1 ? __($textSingular, $textdomain) : __($textPlural, $textdomain);
|
||||
if($count === 0 && $value !== $textPlural && wire()->languages) {
|
||||
$plural = __('0-plural', 'common');
|
||||
if(strtolower($plural) === '0-singular') {
|
||||
$value = __($textSingular, $textdomain);
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -423,5 +431,3 @@ function wireLangTranslations(array $values = array()) {
|
||||
function wireLangReplacements(array $values) {
|
||||
return __(true, 'replacements', $values);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -644,6 +644,7 @@ class LanguageTranslator extends Wire {
|
||||
$v = '';
|
||||
|
||||
switch(strtolower($str)) {
|
||||
case '0-plural': $v = $this->_('0-plural'); break; // Is zero (0) plural or singular? type=radios options=[0-plural:Plural,0-singular:Singular] // i.e. would language use "0 items" (plural) or "0 item" (singular)?
|
||||
case 'edit': $v = $this->_('Edit'); break;
|
||||
case 'delete': $v = $this->_('Delete'); break;
|
||||
case 'save': $v = $this->_('Save'); break;
|
||||
|
Reference in New Issue
Block a user