RED-2208: Smartcat WIP
This commit is contained in:
parent
29e72a6fc9
commit
c1d18cf2ae
File diff suppressed because it is too large
Load Diff
18
tools/smartcat/files/export.xliff
Normal file
18
tools/smartcat/files/export.xliff
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?><xliff xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 http://docs.oasis-open.org/xliff/v1.2/os/xliff-core-1.2-strict.xsd" xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
|
||||||
|
<file original="redaction" datatype="plaintext" source-language="en-US" target-language="de">
|
||||||
|
<body>
|
||||||
|
<trans-unit id="yesterday">
|
||||||
|
<source>Yesterday</source>
|
||||||
|
<target>Gestern2 {time}</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="today">
|
||||||
|
<source>Today {time}</source>
|
||||||
|
<target>Today DE {time}</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="title">
|
||||||
|
<source>{type, select, edit{Edit} create{Add New} other{}} User</source>
|
||||||
|
<target>DE {type, select, edit{Edit} create{Add New} other{}} User</target>
|
||||||
|
</trans-unit>
|
||||||
|
</body>
|
||||||
|
</file>
|
||||||
|
</xliff>
|
||||||
@ -1,25 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<xliff xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 http://docs.oasis-open.org/xliff/v1.2/os/xliff-core-1.2-strict.xsd"
|
|
||||||
xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
|
|
||||||
<file original="redaction" datatype="plaintext" source-language="en-US" target-language="de">
|
|
||||||
<body>
|
|
||||||
<trans-unit id="account-settings" approved="no">
|
|
||||||
<source>Account Settingss</source>
|
|
||||||
<target state="needs-review-translation">Account Einstellungen1</target>
|
|
||||||
</trans-unit>
|
|
||||||
<trans-unit id="something.else" approved="no">
|
|
||||||
<source>Something1</source>
|
|
||||||
<target state="needs-review-translation">Something2</target>
|
|
||||||
</trans-unit>
|
|
||||||
<trans-unit id="something.new" approved="no">
|
|
||||||
<source>Something3</source>
|
|
||||||
<target state="needs-review-translation">11233</target>
|
|
||||||
</trans-unit>
|
|
||||||
<trans-unit id="abc" approved="yes">
|
|
||||||
<source>aa</source>
|
|
||||||
<target state="translated">i win at this</target>
|
|
||||||
</trans-unit>
|
|
||||||
</body>
|
|
||||||
</file>
|
|
||||||
</xliff>
|
|
||||||
18
tools/smartcat/files/updated-variables.xliff
Normal file
18
tools/smartcat/files/updated-variables.xliff
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<xliff xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 http://docs.oasis-open.org/xliff/v1.2/os/xliff-core-1.2-strict.xsd" xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
|
||||||
|
<file original="redaction" datatype="plaintext" source-language="en-US" target-language="de-DE">
|
||||||
|
<body>
|
||||||
|
<trans-unit id="yesterday">
|
||||||
|
<source>Yesterday</source>
|
||||||
|
<target>Gestern2 {time}</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="today">
|
||||||
|
<source>Today {time}</source>
|
||||||
|
<target>Today DE {time}</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="title">
|
||||||
|
<source>{type, select, edit{Edit} create{Add New} other{}} User</source>
|
||||||
|
<target>DE {type, select, edit{Edit} create{Add New} other{}} User</target>
|
||||||
|
</trans-unit>
|
||||||
|
</body>
|
||||||
|
</file>
|
||||||
|
</xliff>
|
||||||
File diff suppressed because it is too large
Load Diff
@ -6,11 +6,12 @@ export const languages: Language[] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
export const UPDATED_XLIFF_PATH = './tools/smartcat/files/updated.xliff';
|
export const UPDATED_XLIFF_PATH = './tools/smartcat/files/updated.xliff';
|
||||||
|
export const EXPORTED_XLIFF_PATH = './tools/smartcat/files/export.xliff';
|
||||||
|
|
||||||
/** Test account credentials */
|
/** Test account credentials */
|
||||||
export const ACCOUNT_ID = '13d238b1-87df-4918-b47d-06dbff048a9d';
|
export const ACCOUNT_ID = '13d238b1-87df-4918-b47d-06dbff048a9d';
|
||||||
export const API_KEY = '1_Knm1wlSb0377yUMF6k3apKJEa';
|
export const API_KEY = '1_Knm1wlSb0377yUMF6k3apKJEa';
|
||||||
export const DOCUMENT_ID = 'f32a7d3ef55663b72e7fbe9b_7';
|
export const DOCUMENT_ID = 'f047df1be133e3612d67760e_7';
|
||||||
|
|
||||||
/** IQser credentials */
|
/** IQser credentials */
|
||||||
// export const ACCOUNT_ID="73a11e51-ef77-4c5b-bd55-9b9b5c610988"
|
// export const ACCOUNT_ID="73a11e51-ef77-4c5b-bd55-9b9b5c610988"
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
/* Personal */
|
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import FormData from 'form-data';
|
import FormData from 'form-data';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { ACCOUNT_ID, API_KEY, DOCUMENT_ID, UPDATED_XLIFF_PATH } from './constants';
|
import { ACCOUNT_ID, API_KEY, DOCUMENT_ID, EXPORTED_XLIFF_PATH, UPDATED_XLIFF_PATH } from './constants';
|
||||||
|
|
||||||
const BASE_URL = 'https://smartcat.ai/api/integration/v1';
|
const BASE_URL = 'https://smartcat.ai/api/integration/v1';
|
||||||
|
|
||||||
@ -29,18 +28,21 @@ export const smartcatApi = {
|
|||||||
const url = `${BASE_URL}/document/export/${taskId}`;
|
const url = `${BASE_URL}/document/export/${taskId}`;
|
||||||
const response = await axios.get(url, { headers: Headers });
|
const response = await axios.get(url, { headers: Headers });
|
||||||
console.log('Downloaded translation');
|
console.log('Downloaded translation');
|
||||||
|
console.log(response.data);
|
||||||
|
fs.writeFileSync(EXPORTED_XLIFF_PATH, response.data);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
|
|
||||||
async upload() {
|
async upload() {
|
||||||
try {
|
try {
|
||||||
const url = `${BASE_URL}/document/update?documentId=${DOCUMENT_ID}`;
|
const url = `${BASE_URL}/document/update?documentId=${DOCUMENT_ID}`;
|
||||||
|
// const url = `${BASE_URL}/document/translateWithXliff?documentId=${DOCUMENT_ID}`;
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('file', fs.createReadStream(UPDATED_XLIFF_PATH));
|
formData.append('file', fs.createReadStream(UPDATED_XLIFF_PATH));
|
||||||
const response = await axios.putForm(url, formData, {
|
const response = await axios.putForm(url, formData, {
|
||||||
headers: Headers,
|
headers: Headers,
|
||||||
});
|
});
|
||||||
console.log(response.data);
|
console.log(response.data, response.status, response.statusText);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
console.error(`${e.response?.status} - ${e.response?.statusText}`);
|
console.error(`${e.response?.status} - ${e.response?.statusText}`);
|
||||||
|
|||||||
@ -3,9 +3,9 @@ import { ParsedXliff, Translation } from './types';
|
|||||||
import { languages, UPDATED_XLIFF_PATH } from './constants';
|
import { languages, UPDATED_XLIFF_PATH } from './constants';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
export async function updateLocalFiles(downloadedXliff: ParsedXliff): Promise<Translation[]> {
|
export async function updateLocalFiles(downloadedXliff: ParsedXliff, app = 'redact'): Promise<Translation[]> {
|
||||||
const translations: Translation[] = languages.map(lang => ({
|
const translations: Translation[] = languages.map(lang => ({
|
||||||
content: flattenJson(JSON.parse(fs.readFileSync(`./apps/red-ui/src/assets/i18n/${lang.code}.json`, 'utf8'))),
|
content: flattenJson(JSON.parse(fs.readFileSync(`./apps/red-ui/src/assets/i18n/${app}/${lang.code}.json`, 'utf8'))),
|
||||||
lang,
|
lang,
|
||||||
}));
|
}));
|
||||||
const source = translations[0]; // flat English
|
const source = translations[0]; // flat English
|
||||||
@ -36,12 +36,14 @@ export async function updateLocalFiles(downloadedXliff: ParsedXliff): Promise<Tr
|
|||||||
console.log('Updating translation files...');
|
console.log('Updating translation files...');
|
||||||
unflattenedTranslations.forEach(translation => {
|
unflattenedTranslations.forEach(translation => {
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
`./apps/red-ui/src/assets/i18n/${translation.lang.code}.json`,
|
`./apps/red-ui/src/assets/i18n/${app}/${translation.lang.code}.json`,
|
||||||
JSON.stringify(translation.content, null, 2) + '\n',
|
JSON.stringify(translation.content, null, 2) + '\n',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
console.log('Updated translation files!');
|
console.log('Updated translation files!');
|
||||||
|
|
||||||
|
console.log(translations);
|
||||||
|
|
||||||
return translations;
|
return translations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user