Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

$translate.instant do interpolation event when translation id is not found #1846

Open
mariocerrato opened this issue May 10, 2018 · 7 comments
Assignees
Labels

Comments

@mariocerrato
Copy link

mariocerrato commented May 10, 2018

Subject of the issue

Using $translate.instant('Hello<br>world') I receive the string "Hello&lt;br&gt;Hello2" instead of the original string.
If I use $translate('Hello<br>world').then(...) in the callback function I receive the original string.

Debugging code I've found that in the instant function call defaultInterpolator.interpolate that transform and sanitize the string from html chars.
Using the promise interpolation isn't called if translationId isn't found.

Your environment

  • version of angular-translate: v.2.8.1
  • version of angular: v1.4.14
  • which browser and its version: Chrome v.66

Steps to reproduce

var title = 'Hello';
var message = 'Hello<br>world!';
$q.all({
translateTitle: $translate(title),
translateMessage: $translate(message)
}).then(function successCallback(translations) {
var instantMessage = $translate.instant(message);
title = translations.translateTitle;
message = translations.translateMessage;
toastr['info'](message, title);
toastr['info'](instantMessage, title);
});

@knalli
Copy link
Member

knalli commented Jul 27, 2018

This is partly issued by #1101

Short story: You have to choose a strategy wisely depending on your need. You can use #1101 (comment) as a help.

@knalli
Copy link
Member

knalli commented Jul 27, 2018

Note/reminder:

It looks like your environment is using an old or older release of AngularJS and/or angular-translate. After updating your dependencies, please check and verify your issue again.

@knalli knalli added the waiting label Jul 27, 2018
@RostVY
Copy link

RostVY commented Aug 6, 2018

I confirm that there's an issue. I'm using the latest AngularJS version 1.7.2 and the latest angular-translate version 2.18.1.
I have debugged the sources and on the screenshot below you can see that the
defaultInterpolator.interpolate() is used when the result is not found in the translation table.
And you can see on screenshot that there's interpolationId, which has been passed to the method. So the defaultInterpolator should not be used, but the interpolator, whose interpolationId has been passed.

incorrectinterpolatorused

@knalli knalli removed the waiting label Aug 19, 2018
@knalli knalli self-assigned this Aug 19, 2018
@knalli knalli added the bug label Aug 19, 2018
@knalli
Copy link
Member

knalli commented Aug 19, 2018

@RostVY Thank you digging for some info :)

Maybe you want to make a contribution fixing this issue?

@RostVY
Copy link

RostVY commented Aug 19, 2018

@knalli I wish I could, but I really don't want to - I'm on vacation without access to computer and without any wish to see computers, source codes and so on. If noone fixes during next month, I may rethink my decision.

@ericnewton76
Copy link

@RostVY lol, I can relate to "without any wish to see computers, sources codes and so on."

Did you ever solve your issue with angular-translate?

@RostVY
Copy link

RostVY commented Dec 12, 2018

@ericnewton76 nope :(. I have not tried and I am unsure how it is supposed to work. Using
result = translationId;
in the line, which is highlighted on my screenshot could resolve some of issues. But I'm not sure if that's correct solution which will have no side effects.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants