Skip to content

Commit edd368d

Browse files
committed
wip
1 parent 82170ff commit edd368d

3 files changed

Lines changed: 67 additions & 3 deletions

File tree

nx/blocks/loc/connectors/trados/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ async function createProject(options, service, title, langs) {
5757
const { apiEndpoint } = service;
5858

5959
const location = langs[0]['trados location'];
60-
const templateId = langs[0]['trados project template'];
60+
const templateId = options['translation.service.custom.option.Template'] || langs[0]['trados project template'];
61+
const notes = options['translation.service.custom.textarea.Notes'];
6162

6263
const languageDirections = langs.map((lang) => ({
6364
sourceLanguage: { languageCode: sourceLanguage },
@@ -66,7 +67,7 @@ async function createProject(options, service, title, langs) {
6667

6768
const body = JSON.stringify({
6869
name: `${title} - ${Date.now()}`,
69-
description: `DA translation project: ${title}`,
70+
description: notes || `DA translation project: ${title}`,
7071
dueBy,
7172
projectTemplate: {
7273
id: templateId,

nx/blocks/loc/views/options/options.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getConfig } from '../../../../scripts/nexter.js';
33
import getStyle from '../../../../utils/styles.js';
44
import getSvg from '../../../../utils/svg.js';
55
import { fetchConfig } from '../../utils/utils.js';
6-
import { getAllActions, formatLangs, formatConfig, finalizeOptions } from './utils/utils.js';
6+
import { getAllActions, formatLangs, formatConfig, finalizeOptions, getCustomOptions } from './utils/utils.js';
77

88
const { nxBase: nx } = getConfig();
99

@@ -190,6 +190,41 @@ class NxLocOptions extends LitElement {
190190
</div>`;
191191
}
192192

193+
renderCustomOptions() {
194+
const custom = getCustomOptions(this._siteConfig);
195+
return Object.entries(custom).flatMap(([type, items]) => items.map(({ name, values }) => {
196+
const key = `translation.service.custom.${type}.${name}`;
197+
if (type === 'option') {
198+
return html`
199+
<div class="nx-loc-fieldgroup">
200+
<p>${name}</p>
201+
<sl-select name="${key}" value="${values[0].value}" @change=${this.handleChangeOption}>
202+
${values.map(({ label, value }) => html`<option value="${value}">${label}</option>`)}
203+
</sl-select>
204+
</div>`;
205+
}
206+
if (type === 'boolean') {
207+
return html`
208+
<div class="nx-loc-fieldgroup">
209+
<p>${name}</p>
210+
<sl-checkbox name="${key}" ?checked=${values[0].value === 'true'} @change=${this.handleChangeOption}></sl-checkbox>
211+
</div>`;
212+
}
213+
if (type === 'textarea') {
214+
return html`
215+
<div class="nx-loc-fieldgroup">
216+
<p>${name}</p>
217+
<sl-textarea name="${key}" value="${values[0].value}" @change=${this.handleChangeOption}></sl-textarea>
218+
</div>`;
219+
}
220+
return html`
221+
<div class="nx-loc-fieldgroup">
222+
<p>${name}</p>
223+
<sl-input name="${key}" value="${values[0].value}" @change=${this.handleChangeOption}></sl-input>
224+
</div>`;
225+
}));
226+
}
227+
193228
renderDateField(label, property) {
194229
return html`
195230
<div class="nx-loc-fieldgroup">
@@ -305,6 +340,7 @@ class NxLocOptions extends LitElement {
305340
<div class="nx-loc-options-group">
306341
${this.renderFieldgroup('Environment', 'translation.service.all.env')}
307342
${this._siteConfig['translation.service.supports.duedate'] ? this.renderDateField('Due date', 'project.due') : nothing}
343+
${this.renderCustomOptions()}
308344
</div>
309345
<p class="nx-loc-options-panel-subhead">Conflict resolution</p>
310346
<div class="nx-loc-options-group">

nx/blocks/loc/views/options/utils/utils.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ function findLanguageByName(languages, name) {
6262
return null;
6363
}
6464

65+
export function getCustomOptions(config) {
66+
const PREFIX = 'translation.service.custom.';
67+
return Object.keys(config).reduce((acc, key) => {
68+
if (!key.startsWith(PREFIX)) return acc;
69+
const remainder = key.slice(PREFIX.length);
70+
const dotIndex = remainder.indexOf('.');
71+
if (dotIndex === -1) return acc;
72+
const type = remainder.slice(0, dotIndex);
73+
const name = remainder.slice(dotIndex + 1);
74+
acc[type] ??= [];
75+
const values = config[key].split('|').map((entry) => {
76+
const [label, val] = entry.split('=').map((s) => s.trim());
77+
return { label, value: val ?? label };
78+
});
79+
acc[type].push({ name, values });
80+
return acc;
81+
}, {});
82+
}
83+
6584
export function formatConfig(sheets) {
6685
const config = sheets.config.data.reduce((acc, row) => {
6786
acc[row.key] = row.value;
@@ -76,6 +95,14 @@ export function formatConfig(sheets) {
7695
return acc;
7796
}, {});
7897

98+
// Seed custom option initial values
99+
const custom = getCustomOptions(config);
100+
Object.entries(custom).forEach(([type, items]) => {
101+
items.forEach(({ name, values }) => {
102+
options[`translation.service.custom.${type}.${name}`] = values[0].value;
103+
});
104+
});
105+
79106
// If a source lang is spec'd, set it.
80107
if (config['source.language']) {
81108
const found = findLanguageByName(sheets.languages.data, config['source.language']);

0 commit comments

Comments
 (0)