Skip to main content

TranslatorService

TranslatorService

The TranslatorService is used to translate entities into the current language.

Example

import { Injectable } from '@nestjs/common';
import { ID, Product, RequestContext, TransactionalConnection, TranslatorService } from '@vendure/core';

@Injectable()
export class ProductService {

constructor(private connection: TransactionalConnection,
private translator: TranslatorService){}

async findOne(ctx: RequestContext, productId: ID): Promise<Product | undefined> {
const product = await this.connection.findOneInChannel(ctx, Product, productId, ctx.channelId, {
relations: {
facetValues: {
facet: true,
}
}
});
if (!product) {
return;
}
return this.translator.translate(product, ctx, ['facetValues', ['facetValues', 'facet']]);
}
}
Signature
class TranslatorService {
constructor(configService: ConfigService)
translate(translatable: T, ctx: RequestContext, translatableRelations: DeepTranslatableRelations<T> = []) => ;
}

constructor

method
(configService: ConfigService) => TranslatorService

translate

method
(translatable: T, ctx: RequestContext, translatableRelations: DeepTranslatableRelations<T> = []) =>