mirror of
https://github.com/flarum/framework.git
synced 2025-04-25 14:14:03 +08:00
fix: slug transliteration assuming the language is always en
(#3387)
* fix: transliteration assuming the language is always `en` * test: transliteration works with forum locale
This commit is contained in:
parent
cca97f32c6
commit
fb717db57c
@ -18,6 +18,7 @@ use Flarum\Discussion\Event\Renamed;
|
||||
use Flarum\Discussion\Event\Restored;
|
||||
use Flarum\Discussion\Event\Started;
|
||||
use Flarum\Foundation\EventGeneratorTrait;
|
||||
use Flarum\Locale\LocaleManager;
|
||||
use Flarum\Notification\Notification;
|
||||
use Flarum\Post\MergeableInterface;
|
||||
use Flarum\Post\Post;
|
||||
@ -445,6 +446,6 @@ class Discussion extends AbstractModel
|
||||
protected function setTitleAttribute($title)
|
||||
{
|
||||
$this->attributes['title'] = $title;
|
||||
$this->slug = Str::slug($title);
|
||||
$this->slug = Str::slug($title, '-', resolve(LocaleManager::class)->getLocale());
|
||||
}
|
||||
}
|
||||
|
@ -133,6 +133,35 @@ class CreateTest extends TestCase
|
||||
$this->assertEquals('test - too-obscure', Arr::get($data, 'data.attributes.title'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function can_create_discussion_with_current_lang_slug_transliteration()
|
||||
{
|
||||
$this->app()->getContainer()->make('flarum.locales')->setLocale('zh');
|
||||
|
||||
$response = $this->send(
|
||||
$this->request('POST', '/api/discussions', [
|
||||
'authenticatedAs' => 1,
|
||||
'json' => [
|
||||
'data' => [
|
||||
'attributes' => [
|
||||
'title' => '我是一个土豆',
|
||||
'content' => 'predetermined content for automated testing',
|
||||
],
|
||||
]
|
||||
],
|
||||
])
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $response->getStatusCode());
|
||||
|
||||
/** @var Discussion $discussion */
|
||||
$discussion = Discussion::firstOrFail();
|
||||
|
||||
$this->assertEquals('wo-shi-yi-ge-tu-dou', $discussion->slug);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user