import { handleFetch } from './helpers'; import { ItemTranslation, LanguageResponse, PageTranslation } from '../types/language'; import { Version } from '../types/api'; import { CrudStoreItemsModel } from '../stores/types/CrudStoreModel'; export default class LanguageApi { public static async getLanguages(): Promise { const response = await handleFetch('/settings/languages'); return response.json(); } public static async translatePage(sourceVersionId: string, languageKey: string, name: string): Promise { const response = await handleFetch(`/translate/page/${sourceVersionId}/${languageKey}?name=${name}`, { method: 'POST' }); return response.json(); } public static async deletePageTranslations(languageRef: string) { const response = await handleFetch(`/translations/page/delete/${languageRef}`, { method: 'POST' }); return response.json(); } public static async getPageTranslations(languageRef: string): Promise { const response = await handleFetch(`/translations/page/${languageRef}`); return response.json(); } public static async translateItem(sourceId: string, languageKey: string, itemName: string): Promise { const response = await handleFetch(`/translate/item/${sourceId}/${languageKey}?itemName=${itemName}`, { method: 'POST' }); return response.json(); } public static async deleteItemTranslations(languageRef: string) { const response = await handleFetch(`/translations/item/delete/${languageRef}`, { method: 'POST' }); return response.json(); } public static async getItemTranslations(itemName: string, languageRef?: string): Promise { const response = await handleFetch(`/translations/item/${languageRef || null}?itemName=${itemName}`); return response.json(); } }