Skip to content

[Translation] Introduce NonTranslatableMessage #60935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: 7.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Symfony/Component/Translation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

7.4
---

* Introduce `Symfony\Component\Translation\NonTranslatableMessage`

7.3
---

Expand Down
38 changes: 38 additions & 0 deletions src/Symfony/Component/Translation/NonTranslatableMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Translation;

use Symfony\Contracts\Translation\TranslatableInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class NonTranslatableMessage implements TranslatableInterface
{
public function __construct(
private string $message,
) {
}

public function __toString(): string
{
return $this->getMessage();
}

public function getMessage(): string
{
return $this->message;
}

public function trans(TranslatorInterface $translator, ?string $locale = null): string
{
return $this->getMessage();
}
}
38 changes: 38 additions & 0 deletions src/Symfony/Component/Translation/Tests/NonTranslatableTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Translation\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Translation\Loader\ArrayLoader;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\NonTranslatableMessage;

class NonTranslatableTest extends TestCase
{
public function testTrans()
{
$translator = new Translator('en');
$translator->addLoader('array', new ArrayLoader());
$translator->addResource('array', [
'Symfony is great!' => 'Symfony est super !',
], 'fr', '');

$translatable = new NonTranslatableMessage('Symfony is great!');

$this->assertSame('Symfony is great!', $translatable->trans($translator, 'fr'));
}

public function testToString()
{
$this->assertSame('Symfony is great!', (string) new NonTranslatableMessage('Symfony is great!'));
}
}
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy