You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When adding translations to an existing project, I'd like to write tests for them somehow. How?
I start at the translator documentation, but there are no tipps on that (yet), so I have to think about that by myself. I know I don't want to check for the translation messages, as they are prone to change. So the next best thing I currently see is using the IdentityTranslator, which is a TranslatorInterface implementation that returns the message key as it's translation. With that, I can check for the translation keys in my tests.
But this approach falls a bit short when I want
to assert that the translation actually happened (the test cannot differentiate between a message key that was rendered plainly and a translated message, because they are equal)
I need the translation to follow specific rules - e.g. to be an email address that is used as a sender or receiver email address of a contact form and hence checked with the email constraint.
So I wonder if it would be a good idead to work on something like a TestTranslator, e.g. as a generalization of the inline class above?
And if so, in which package should it be placed? As a test tool, I wouldn't place it in symfony/translation, but the names of the usually dev-required composer packages (symfony/browser-kit, /css-selector, /debug-bundle, /maker-bundle, /phpunit-bridge, /stopwatch, /web-profiler-bundle) don't sound any better to me.
WDYT?
Example
No response
The text was updated successfully, but these errors were encountered:
Thanks for the suggestion @ro0NL! After giving it some thought (not for the whole 6+ months though - it slipped through, sorry!): yes, you're right, that's an easy solution.
For reference:
use Symfony\Component\Translation\Loader\ArrayLoader;
use Symfony\Component\Translation\Translator;
$translator = new Translator(null);
$translator->addLoader('array', new ArrayLoader());
$translator->addResource(
'array',
[
'sender.emailAddress' => 'sender@example.com',
],
'de_DE'
);
This does not feature the dynamic 'translator-was-called-with-id:' . $id translations like in my suggestion above, but they weren't really necessary. I can easily add the few relevant messages and I'm fine with the rest defaulting to their message key. Checking that the relevant messages are translated is enough to ensure that the translator is actually used.
Description
When adding translations to an existing project, I'd like to write tests for them somehow. How?
I start at the translator documentation, but there are no tipps on that (yet), so I have to think about that by myself. I know I don't want to check for the translation messages, as they are prone to change. So the next best thing I currently see is using the IdentityTranslator, which is a TranslatorInterface implementation that returns the message key as it's translation. With that, I can check for the translation keys in my tests.
But this approach falls a bit short when I want
So usually come up with something like
So I wonder if it would be a good idead to work on something like a
TestTranslator
, e.g. as a generalization of the inline class above?And if so, in which package should it be placed? As a test tool, I wouldn't place it in
symfony/translation
, but the names of the usually dev-required composer packages (symfony/browser-kit
,/css-selector
,/debug-bundle
,/maker-bundle
,/phpunit-bridge
,/stopwatch
,/web-profiler-bundle
) don't sound any better to me.WDYT?
Example
No response
The text was updated successfully, but these errors were encountered: