Tobias Stangl Tobias Stangl - 2 years ago 95
AngularJS Question

How to translate the content of an attribute with angular-translate

in my mongo schema i have an enum with predefined types:

let MeterSchema = new Schema({
type: {
type: String,
enum: ['Prepayment', 'TimeOfDay', 'PowerExport']

What i want is to display this value internationalized with i18n files on my angular view.
I looked at the Variale replacement of angular translate (, but could not figure it out how do it properly with this.

At the moment i translate it that way:


<div class="md-summary">{{vm.getMeterType(meter) | translate}}</div>


public getMeterType(meter): String {
return 'app.masterData.meters.type.' + meter.type;

But i think there has to be a better way to this.

Answer Source

The answer is actually pretty simple:

<div class="md-summary">{{'app.masterData.meters.type.' + meter.type | translate}}</div>

I don't know why i didn't use string concatenation in the first place.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download