mirror of
https://github.com/flarum/core.git
synced 2025-08-07 17:07:19 +02:00
Switch to ICU MessageFormat (#2759)
This commit is contained in:
committed by
GitHub
parent
9461df8803
commit
b5ee8a034b
105
framework/core/tests/integration/extenders/LocalesTest.php
Normal file
105
framework/core/tests/integration/extenders/LocalesTest.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Tests\integration\extenders;
|
||||
|
||||
use Flarum\Extend;
|
||||
use Flarum\Locale\Translator;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
|
||||
class LocalesTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
array_map('unlink', glob($this->tmpDir().'/storage/locale/*'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function custom_translation_does_not_exist_by_default()
|
||||
{
|
||||
$this->app()->getContainer()->make('flarum.locales');
|
||||
$translator = $this->app()->getContainer()->make(Translator::class);
|
||||
|
||||
$this->assertEquals('test.hello', $translator->trans('test.hello', ['name' => 'ACME']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function custom_translation_exists_if_added()
|
||||
{
|
||||
$this->extend(
|
||||
(new Extend\Locales(dirname(__FILE__, 3).'/fixtures/locales'))
|
||||
);
|
||||
|
||||
$this->app()->getContainer()->make('flarum.locales');
|
||||
$translator = $this->app()->getContainer()->make(Translator::class);
|
||||
|
||||
$this->assertEquals('World ACME', $translator->trans('test.hello', ['name' => 'ACME']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function custom_translation_exists_if_added_with_intl_suffix()
|
||||
{
|
||||
$this->extend(
|
||||
(new Extend\Locales(dirname(__FILE__, 3).'/fixtures/locales'))
|
||||
);
|
||||
|
||||
$this->app()->getContainer()->make('flarum.locales');
|
||||
$translator = $this->app()->getContainer()->make(Translator::class);
|
||||
|
||||
$this->assertEquals('World-intl ACME', $translator->trans('test.hello-intl', ['name' => 'ACME']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function messageformat_works_in_translations()
|
||||
{
|
||||
$this->extend(
|
||||
(new Extend\Locales(dirname(__FILE__, 3).'/fixtures/locales'))
|
||||
);
|
||||
|
||||
$this->app()->getContainer()->make('flarum.locales');
|
||||
$translator = $this->app()->getContainer()->make(Translator::class);
|
||||
|
||||
$this->assertEquals('ACME invites ACME2 and one other person to her party.', $translator->trans('test.party-invitation', ['gender_of_host' => 'female', 'host' => 'ACME', 'num_guests' => 2, 'guest' => 'ACME2']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function laravel_interface_methods_work()
|
||||
{
|
||||
$this->extend(
|
||||
(new Extend\Locales(dirname(__FILE__, 3).'/fixtures/locales'))
|
||||
);
|
||||
|
||||
$this->app()->getContainer()->make('flarum.locales');
|
||||
$translator = $this->app()->getContainer()->make(Translator::class);
|
||||
|
||||
$args = ['gender_of_host' => 'female', 'host' => 'ACME', 'num_guests' => 2, 'guest' => 'ACME2'];
|
||||
|
||||
$this->assertEquals('ACME invites ACME2 and one other person to her party.', $translator->get('test.party-invitation', $args));
|
||||
// Number doesn't matter
|
||||
$this->assertEquals('ACME invites ACME2 and one other person to her party.', $translator->choice('test.party-invitation', 2, $args));
|
||||
$this->assertEquals('ACME invites ACME2 and one other person to her party.', $translator->choice('test.party-invitation', 50, $args));
|
||||
$this->assertEquals('ACME invites ACME2 and one other person to her party.', $translator->choice('test.party-invitation', -1000, $args));
|
||||
$this->assertEquals('ACME invites ACME2 and one other person to her party.', $translator->choice('test.party-invitation', null, $args));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user