tflori / angular-translator

translation module for angular
https://tflori.github.io/angular-translator/
MIT License
21 stars 6 forks source link

Allow pipes in translations #28

Closed tflori closed 7 years ago

tflori commented 7 years ago

Currently it is not possible to use any pipe - it would be very helpful when it will work.

{
  "LOGIN": "Hello {{ name }}, your last login was on {{ lastLogin | date:'medium' }}"
}
tflori commented 7 years ago

The main problem is to get a pipe instance by it's name (not the class name). I have an open question regarding this problem on stackoverflow.

When I don't get an answer I see only one solution: you will have to configure allowed pipes in the configuration. Maybe even with the name (depends if we can get the name from the pipe decorator).

tflori commented 7 years ago

It seems it is currently not possible to get the pipes from compiler. Maybe a feature request will be successful.

Anyway I created a prototype it could work: https://github.com/tflori/angular-translator/commit/558b9b17ad7404afa5237a73a25e14c635273357

There are two drawbacks:

  1. you have to give TranslatorModule.forRoot() the pipes you want to use in translations (except the pipes from common module)
  2. only pure pipes will work
tflori commented 7 years ago

If you want to try there is a dev release for this prototype:

npm install angular-translator@2.1.0-dev-pipes