Skip to content
Snippets Groups Projects
Commit 0657faef authored by Shibin Das's avatar Shibin Das
Browse files

Issue #3496370 by d34dman: Implement Rule for "Five Forms Breton"

parent 2052b26c
No related branches found
No related tags found
No related merge requests found
<?php
namespace Drupal\string_plural_form\Plugin\StringPluralForm;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\string_plural_form\Attribute\StringPluralForm;
use Drupal\string_plural_form\StringPluralFormBase;
/**
* Provides a Plural Form for "Breton" language.
*/
#[StringPluralForm(
id: "five_forms_breton",
admin_label: new TranslatableMarkup("Five Forms Breton"),
description: new TranslatableMarkup("Case in the Breton language."),
)]
class FiveFormsBreton extends StringPluralFormBase {
/**
* {@inheritdoc}
*/
public function getGettextNplurals(): int {
return 5;
}
/**
* {@inheritdoc}
*/
public function getGettextPlural(): string {
return "(n % 10 == 1 && n % 100 != 11 && n % 100 != 71 && n % 100 != 91) ? 0 : ((n % 10 == 2 && n % 100 != 12 && n % 100 != 72 && n % 100 != 92) ? 1 : ((((n % 10 == 3 || n % 10 == 4) || n % 10 == 9) && (n % 100 < 10 || n % 100 > 19) && (n % 100 < 70 || n % 100 > 79) && (n % 100 < 90 || n % 100 > 99)) ? 2 : ((n != 0 && n % 1000000 == 0) ? 3 : 4)))";
}
/**
* {@inheritdoc}
*/
public function getAssociatedLanguageCodes(): array {
return [
"br",
];
}
/**
* {@inheritdoc}
*/
public function getIndex(int $n): int {
return ($n % 10 == 1 && $n % 100 != 11 && $n % 100 != 71 && $n % 100 != 91) ? 0 : (($n % 10 == 2 && $n % 100 != 12 && $n % 100 != 72 && $n % 100 != 92) ? 1 : (((($n % 10 == 3 || $n % 10 == 4) || $n % 10 == 9) && ($n % 100 < 10 || $n % 100 > 19) && ($n % 100 < 70 || $n % 100 > 79) && ($n % 100 < 90 || $n % 100 > 99)) ? 2 : (($n != 0 && $n % 1000000 == 0) ? 3 : 4)));
}
/**
* {@inheritdoc}
*/
public function getIndexLabel(int $index): TranslatableMarkup {
return match($index) {
0 => new TranslatableMarkup("1, 21, 31, 41..."),
1 => new TranslatableMarkup("2, 22, 32, 42, ..."),
2 => new TranslatableMarkup("3, 4, 9, 23, 24, 29, ..."),
3 => new TranslatableMarkup("1000000, 2000000, ..."),
4 => new TranslatableMarkup("0, 5~8, 10~20, 100, 1000, 10000, ..."),
};
}
}
<?php
namespace Drupal\Tests\string_plural_form\Unit\StringPluralForm;
use Drupal\string_plural_form\Plugin\StringPluralForm\FiveFormsBreton;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\string_plural_form\Plugin\StringPluralForm\FiveFormsBreton
* @group StringPluralFormPlugins
*/
class FiveFormsBretonTest extends UnitTestCase {
/**
* Tests \Drupal\string_plural_form\Plugin\StringPluralForm\FiveFormsBreton::getGettextNplurals()
*/
public function testGetGettextNplurals() {
$plugin = new FiveFormsBreton();
$this->assertEquals(5, $plugin->getGettextNplurals());
}
/**
* Tests \Drupal\string_plural_form\Plugin\StringPluralForm\FiveFormsBreton::getGettextNplurals()
*/
public function testGetGettextPlural() {
$plugin = new FiveFormsBreton();
$this->assertEquals("(n % 10 == 1 && n % 100 != 11 && n % 100 != 71 && n % 100 != 91) ? 0 : ((n % 10 == 2 && n % 100 != 12 && n % 100 != 72 && n % 100 != 92) ? 1 : ((((n % 10 == 3 || n % 10 == 4) || n % 10 == 9) && (n % 100 < 10 || n % 100 > 19) && (n % 100 < 70 || n % 100 > 79) && (n % 100 < 90 || n % 100 > 99)) ? 2 : ((n != 0 && n % 1000000 == 0) ? 3 : 4)))", $plugin->getGettextPlural());
}
/**
* Tests \Drupal\string_plural_form\Plugin\StringPluralForm\FiveFormsBreton::getIndex()
*/
public function testGetIndex() {
$plugin = new FiveFormsBreton();
$expected_forms = [
0 => [1, 21, 31, 41, 51, 61, 81, 101, 121, 131, 141, 151, 161, 181],
1 => [2, 22, 32, 42, 52, 62, 82, 102, 122, 132, 142, 152, 162, 182],
2 => [
3, 4, 9,
23, 24, 29,
33, 34, 39,
43, 44, 49,
53, 54, 59,
63, 64, 69,
83, 84, 89,
103, 104, 109,
123, 124, 129,
133, 134, 139,
143, 144, 149,
153, 154, 159,
163, 164, 169,
183, 184, 189,
],
3 => [
1000000, 2000000, 3000000,
10000000, 20000000, 30000000,
],
4 => [
0,
5, 6, 7, 8,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 25, 26, 27, 28,
30, 35, 36, 37, 38,
40, 45, 46, 47, 48,
50, 55, 56, 57, 58,
60, 65, 66, 67, 68,
70, 71, 72, 73, 74,
75, 76, 77, 78, 79,
80, 85, 86, 87, 88,
90, 91, 92, 93, 94,
95, 96, 97, 98, 99,
100, 105, 106, 107, 108,
110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
120, 125, 126, 127, 128,
130, 135, 136, 137, 138,
140, 145, 146, 147, 148,
150, 155, 156, 157, 158,
160, 165, 166, 167, 168,
170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
180, 185, 186, 187, 188,
190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
1000,
10000,
100000,
],
];
foreach ($expected_forms as $index => $numbers) {
foreach ($numbers as $n) {
$this->assertEquals($index, $plugin->getIndex($n));
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment