@formatjs/cli-lib
Version:
Lib for CLI for formatjs.
45 lines (44 loc) • 1.19 kB
JavaScript
export const format = msgs => {
const results = {
smartling: {
translate_paths: [
{
path: '*/message',
key: '{*}/message',
instruction: '*/description',
},
],
variants_enabled: true,
string_format: 'icu',
},
};
for (const [id, msg] of Object.entries(msgs)) {
results[id] = {
message: msg.defaultMessage,
description: typeof msg.description === 'string'
? msg.description
: JSON.stringify(msg.description),
};
}
return results;
};
export const compareMessages = (el1, el2) => {
// `smartling` has to be the 1st key
if (el1.key === 'smartling') {
return -1;
}
if (el2.key === 'smartling') {
return 1;
}
return el1.key < el2.key ? -1 : el1.key === el2.key ? 0 : 1;
};
export const compile = msgs => {
const results = {};
for (const [id, msg] of Object.entries(msgs)) {
if (id === 'smartling') {
continue;
}
results[id] = msg.message;
}
return results;
};