@craftercms/studio-ui
Version:
Services, components, models & utils to build CrafterCMS authoring extensions.
95 lines (93 loc) • 2.9 kB
JavaScript
/*
* Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { forkJoin, Observable } from 'rxjs';
import { get, postJSON } from '../utils/ajax';
import { map } from 'rxjs/operators';
import { fetchSandboxItem } from './content';
export function fetchItemLocales(site, path) {
return forkJoin({
item: fetchSandboxItem(site, path),
locales: fetchTargetLocales(site, path)
}).pipe(
map(({ item, locales }) => ({
item,
locales: locales.items
}))
);
}
export function fetchTargetLocales(site, path) {
// /studio/api/2/translation/list_target_locales
const response = {
response: {},
items: [
{
id: '1',
status: 'Edited by me',
localeCode: 'en',
path: 'path'
},
{
id: '2',
status: 'Machine translations complete',
localeCode: 'es',
path: 'path'
},
{
id: '3',
status: 'Published',
localeCode: 'en',
path: 'path'
},
{
id: '4',
status: 'Not translated',
localeCode: 'es',
path: 'path'
}
]
};
return new Observable((observer) => {
observer.next(response);
observer.complete();
});
}
export function markForTranslation(site, path, locale) {
return postJSON('/studio/api/2/translation/mark_for_translation_by_path', {
siteId: site,
path: [path],
locales: [locale]
});
}
export function fetchSiteLocales(site) {
return get(`/studio/api/2/configuration/translation?siteId=${site}`).pipe(
map((response) => response?.response?.config)
);
}