Hassan Kashif
Hassan Kashif

Reputation: 445

Replace double quotes with single using angular-translate?

I am using angular-translate for translating English to French but the issue is it converts single quote to double quote. I want to replace translated double quotes with single quote. I have a filter but its not applying on translated text.

Code snippet:

<div class="no-text" ng-if="question.length == 0" translate="msg.site_is_not_applicable" translate-default="This site is not applicable"></div>

e.g. msg.site_is_not_applicable(EN) = This site is not applicable

After translated in French = le site n''est pas applicable

Want to replace double quoted with single quote. Can someone help how I can do this using angular-translate.js.

<div class="no-text" ng-if="question.length == 0" translate="msg.site_is_not_applicable | quoteSingle" translate-default="This site is not applicable"></div>

filter.js

app.module('app.filters', []).filter('quoteSingle', function() {
   return function(text) {
    return text.replace(/"/g, "'");
   };
});

Upvotes: 0

Views: 1243

Answers (1)

Shantanu
Shantanu

Reputation: 3513

Instead of translate directive make use of translate filter. And then you can chain multiple filters on same binding property. So you can add your custom filter after translate filter. Your template code can be:

<div class="no-text" ng-if="question.length == 0"> 
 {{msg.site_is_not_applicable | translate | quoteSingle}}
</div>

Plunker Example

Upvotes: 2

Related Questions