Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for links and shortcuts #147

Open
Bouzmine opened this issue Jun 15, 2016 · 9 comments
Open

Support for links and shortcuts #147

Bouzmine opened this issue Jun 15, 2016 · 9 comments

Comments

@Bouzmine
Copy link

I am currently porting an app from Angular 1 to 2. This app uses the links and shortcuts feature of Angular-Translate. It seems like it's not supported, could this be in the plans ?

@ocombe
Copy link
Member

ocombe commented Jun 30, 2016

That would be a nice feature, it's not really on my todo list but I'd like a PR with this

@davidTurczi
Copy link

Definite +1 (especially if {{'HELLO'|translate:{value:'@WORLD'} }} would indeed do Hola Mundo in spanish per #141)...

@cronosxfiles
Copy link

I guess there's nobody working on this. I've just found myself in the same need as for #141. Have anyone found a workaround for having the key value translated outside the translation pipe so the translated result can be provided as a parameter's key value?

@eplefreeweb
Copy link

hey
I temporarily solved this problem. ^^;;
as problem : {{ 'Forms.Validation.Required' | translate : { field: 'Users.Reference' | translate } }}
to solved : <p translate="Forms.Validation.Required" translate-value-field='{{'Users.Reference' | translate}}'>

Was it helpful? :)

@cronosxfiles
Copy link

I've tried this and got the error: "Can't bind to 'translate-value-field' since it isn't a known property of..."

@alyssa-laveck
Copy link

@cronosxfiles binding to translateParams accomplishes what #141 asked for.

Example:

<div translate="FIELD_REQUIRED" [translateParams]="{field: 'FIRST_NAME' | translate}"></div>
"FIELD_REQUIRED": "{{field}} is required"
"FIRST_NAME": "First Name"

results in

First Name is required

@ibenjelloun
Copy link

ibenjelloun commented Mar 7, 2018

I made a pipe that can be used like this :

{{ 'KEY_TO_TRANSLATE' | translate: (values | ParamsTranslate) }}

Here is the pipe code :

import { Pipe, PipeTransform } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { first } from 'rxjs/operators/first';
import { map } from 'rxjs/operators/map';

@Pipe({
    name: 'ParamsTranslate'
})
export class ParamsTranslatePipe implements PipeTransform {
    constructor(private _translate: TranslateService) {}

    transform(obj: Object): Object {
        const newObject = Object.assign({}, obj);
        Object.keys(obj).forEach(
            key =>
                obj[key].length
                    ? this._translate
                          .get(obj[key])
                          .pipe(first(), map(value => value))
                          .subscribe(value => (newObject[key] = value))
                    : undefined
        );
        return newObject;
    }
}

Here is a stackblitz demo : https://stackblitz.com/edit/ngx-translate-params-translate

@JackPapa0156
Copy link

I'm struggling with the same problem as @Bouzmine. Have anyone has found any solution, except modifying the translation file?

@amirensit
Copy link

I want to comment for others facing this problem.
If you want to use translation as attributes, then look at @ACantrell answer.
If not, then @ibenjelloun answer is the right one.

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

No branches or pull requests

9 participants