backdrop / backdrop-issues

Issue tracker for Backdrop core.
144 stars 40 forks source link

Allow translation of errors with EntityMalformedException #5435

Open laryn opened 2 years ago

laryn commented 2 years ago

Description of the bug

I was looking at something else in Entity Plus and came across the fact that there are some untranslated strings used by EntityMalformedException calls (and a few that do include the t() wrapper). I suppose we should make it consistent and use it on all of them to allow translation of those lines.

klonos commented 2 years ago

There is also a mix of using t() and not using it in the messages thrown by test assertions. I think not using it is by design/intention (although I don't know why). I'm mentioning this because it might be the same reason it shouldn't be used in exception messages either.

klonos commented 2 years ago

...although I just checked, and the default values for the assertion methods in BackdropTestCase do use t() for example:

protected function assertIdentical($first, $second, $message = '', $group = 'Other') {
  return $this->assert($first === $second, $message ? $message : t('Value @first is identical to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE))), $group);
}

If the default message is allowed to use t(), then I don't see why any custom message passed shouldn't as well 🤷🏼

indigoxela commented 2 years ago

Interesting... This reminds me of #5252 and #5394.

Simpletest assert messages should use format_string() instead of t() - at least according to Drupal docs (didn't find the Backdrop docs regarding that). But that's unrelated here.

There are situations, when t() (locale, the whole translation system) is not available at all, which means that there are situations, when using t() makes no sense.

I couldn't tell when exactly that is and if an Exception or more specifically an EntityMalformedException falls in that category.