-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from abbadon1334/add-plural-interval
Add plural interval
- Loading branch information
Showing
5 changed files
with
176 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace I18Next\Exception; | ||
|
||
use atk4\core\Exception; | ||
|
||
class TranslationSyntaxError extends Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
namespace I18Next\Tests; | ||
|
||
use I18Next\Exception\TranslationSyntaxError; | ||
use I18Next\Translator; | ||
|
||
class Translator_CasePluralInterval_Test extends TranslatorBaseCase | ||
{ | ||
/** | ||
* Testing this : | ||
* "key4_interval": "(1){one item};(2-7){a few items};(7-inf){a lot of items};". | ||
* | ||
* "key4_interval": "(1){one item};(2-7){a few items};(7-inf){a lot of items};" | ||
*/ | ||
public function testNoCount() | ||
{ | ||
$this->setupTranslatorLanguages('en'); | ||
|
||
$result = $this->translator->_('key4'); | ||
$this->assertEquals('one item', $result); | ||
} | ||
|
||
public function testCount0() | ||
{ | ||
$this->setupTranslatorLanguages('en'); | ||
|
||
$result = $this->translator->_('key4', ['count' => 0]); | ||
$this->assertEquals('key4', $result); | ||
} | ||
|
||
public function testCount1() | ||
{ | ||
$this->setupTranslatorLanguages('en'); | ||
|
||
$result = $this->translator->_('key4', ['count' => 1]); | ||
$this->assertEquals('one item', $result); | ||
} | ||
|
||
public function testCount3() | ||
{ | ||
$this->setupTranslatorLanguages('en'); | ||
|
||
$result = $this->translator->_('key4', ['count' => 3]); | ||
$this->assertEquals('a few items', $result); | ||
} | ||
|
||
public function testCount8() | ||
{ | ||
$this->setupTranslatorLanguages('en'); | ||
|
||
$result = $this->translator->_('key4', ['count' => 8]); | ||
$this->assertEquals('a lot of items', $result); | ||
} | ||
|
||
public function testException1() | ||
{ | ||
$this->expectException(TranslationSyntaxError::class); | ||
|
||
$path = '/tmp/locale_exception'; | ||
@mkdir($path.'/en', 0777, true); | ||
|
||
file_put_contents( | ||
$path.'/en/exception.json', | ||
json_encode(['key4_interval' => '(1){one item};2-7){a few items};(7-inf){a lot of items};']) | ||
); | ||
|
||
$this->translator = new Translator(); | ||
$this->translator->setTranslationsPath($path); | ||
$this->translator->setLanguagePrimary('en'); | ||
} | ||
|
||
public function testException2() | ||
{ | ||
$this->expectException(TranslationSyntaxError::class); | ||
|
||
$path = '/tmp/locale_exception'; | ||
@mkdir($path.'/en', 0777, true); | ||
|
||
file_put_contents( | ||
$path.'/en/exception.json', | ||
json_encode(['key4_interval' => '(1){one item};(2-7){a few items};(7-inf){a lot of items}']) | ||
); | ||
|
||
$this->translator = new Translator(); | ||
$this->translator->setTranslationsPath($path); | ||
$this->translator->setLanguagePrimary('en'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters