mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.1 KiB
42 lines
1.1 KiB
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
|
|
*/
|
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
import { Injectable } from '@angular/core';
|
|
import { ApiUrlConfig, pretifyError } from '@app/framework';
|
|
import { Observable } from 'rxjs';
|
|
import { map } from 'rxjs/operators';
|
|
|
|
export class TranslationDto {
|
|
constructor(
|
|
public readonly result: string,
|
|
public readonly text: string,
|
|
) {
|
|
}
|
|
}
|
|
|
|
export type TranslateDto =
|
|
Readonly<{ text: string; sourceLanguage: string; targetLanguage: string }>;
|
|
|
|
@Injectable()
|
|
export class TranslationsService {
|
|
constructor(
|
|
private readonly http: HttpClient,
|
|
private readonly apiUrl: ApiUrlConfig,
|
|
) {
|
|
}
|
|
|
|
public translate(appName: string, request: TranslateDto): Observable<TranslationDto> {
|
|
const url = this.apiUrl.buildUrl(`api/apps/${appName}/translations`);
|
|
|
|
return this.http.post<any>(url, request).pipe(
|
|
map(body => {
|
|
return new TranslationDto(body.result, body.text);
|
|
}),
|
|
pretifyError('i18n:translate.translateFailed'));
|
|
}
|
|
}
|
|
|