Skip to content

Instantly share code, notes, and snippets.

@sampaiodiego
Created March 21, 2019 12:12
Show Gist options
  • Save sampaiodiego/c72b0018dcd5f309b7b96442b484576c to your computer and use it in GitHub Desktop.
Save sampaiodiego/c72b0018dcd5f309b7b96442b484576c to your computer and use it in GitHub Desktop.
const fs = require('fs');
const replace = [
// fix spaces after @, # and ()
[/@ %s/g, '@%s'],
[/@% s/g, '@%s'],
[/`@ %s '/g, '`%s`'],
[/"@ %s/g, '"@%s'],
[/`@ %s`/g, '`@%s`'],
[/'@ %s`/g, '`@%s`'],
[/`@% s`/g, '`@%s`'],
// [/# %s/g, '#%s'],
[/#% s/g, '#%s'],
// fix space between chars
[/\( %s\)/g, '(%s)'],
[/\(% s\)/g, '(%s)'],
[/`% s`/g, '`%s`'],
[/` %s`/g, '`%s`'],
// fix spaces whitin tags
[/<em> %s<\/em>/g, '<em>%s</em>'],
[/<em>% s<\/em>/g, '<em>%s</em>'],
[/<strong> %s<\/strong>/g, '<strong>%s</strong>'],
[/<strong>% s<\/strong>/g, '<strong>%s</strong>'],
[/<strong>%s <\/strong>/g, '<strong>%s</strong>'],
[/<b> %s<\/b>/g, '<b>%s</b>'],
[/<b>% s<\/b>/g, '<b>%s</b>'],
[/<code class = \"inline\" > %s<\/code>/g, '<code class=\"inline\">%s</code>'],
[/<code class = \"inline\" >% s<\/code>/g, '<code class=\"inline\">%s</code>'],
[/<code class = \"inline\" > %s<\/code>/g, '<code class=\"inline\">%s</code>'],
[/\\"% s\\"/g, '\\"%s\\"'],
[/: "% s/g, ': "%s'],
[/: " %s/g, ': "%s'],
[/"\(% s/g, '"(%s'],
[/__(from|userId|length|room_name|user_removed|user_by|user_added|total_showing|token) __/g, '__$1__'],
[/%s% s/g, '%s %s'],
[/% s",/g, ' %s",'],
[/% S/g, '%s'],
[/([ảиувəтжя\,ëьхадіоеăบนง])%s/g, '$1 %s'],
[/([ảиувəтжя\,ëьхадіоеă@บนง])% s/g, '$1 %s'],
[/([ảиувəтжя\,ëьхадіоеă@บนง])% c/g, '$1 %s'],
[/([ảиувəтжя\,ëьхадіоеă@บนง])% с/g, '$1 %s'],
[/ %s([l])/g, ' %s $1'],
[/([a-z])% s/g, '$1 %s'],
[/([a-z])% c/g, '$1 %s'],
// fix spaces after tags
[/<\/strong>([a-zđத])/g, '</strong> $1'],
[/<\/b>([a-zđத])/g, '</b> $1'],
[/__from البيانات __/g, '__from__ البيانات'],
[/__фром __/g, '__from__'],
[/ __from data __ \'s/g, ' __from__ data\'s'],
[/__from datos __ \'s/g, '__from__ datos \'s'],
[/__from dhënat __/g, '__from__ dhënat'],
[/__from δεδομένων __/g, '__from__ δεδομένων'],
[/__ \'கள் தரவு __from/g, '\'கள் தரவு __from__'],
[/__ \'in verileri __from./g, '\'in verileri __from__.'],
[/__second วินาที __/g, '__second__ วินาที'],
[/__nombre de usuario__/g, '__username__'],
[/__nom_utilisateur__/g, '__username__'],
['Total: __ total total', 'Total: __total__ total'],
['%sleri', '%s leri'],
[/д%s/g, 'д %s'],
[/\'% s``/g, '`%s`'],
[/\'% s`/g, '`%s`'],
['`/ __ цомманд__`', '`/__command__`'],
['`/ __ команда__ \'', '`/__command__`'],
['`/ __ príkaz__ \'', '`/__command__`'],
['`/ __ கட்டளை__`', '`/__command__`'],
// ['ə% s', 'ə %s'],
// ['т% s', 'т %s'],
// ['и% s', 'и %s'],
// ['у% s', 'у %s'],
// ['в% s', 'в %s'],
[/([^ ])% s(.)/g, '$1 %s$2'],
[/100 %/g, '100%'],
[/100%([^ ])/g, '100% $1'],
];
const replaceAll = (content) => {
// console.log('antes', content);
return replace.reduce((content, [regex, str]) => content.replace(regex, str), content);
}
const mergeJson = (file, source) => {
Object.keys(source).forEach((key) => {
file[key] = source[key];
});
return file;
};
const source = '/tmp/lingohub/packages/rocketchat-i18n/i18n';
const folder = '~/dev/Rocket.Chat/packages/rocketchat-i18n/i18n';
// const source = '/tmp/lingohub/packages/rocketchat-livechat/.app/i18n';
// const folder = '~/dev/Rocket.Chat/packages/rocketchat-livechat/.app/i18n';
const app = fs.readdirSync(folder);
app.forEach((packageName) => {
if (packageName.indexOf('livechat.') === 0) {
return;
}
if (!fs.existsSync(`${ source }/${ packageName }`)) {
return;
}
const sourceFile = fs.readFileSync(`${ source }/${ packageName }`).toString();
const sourceJson = JSON.parse(sourceFile);
const file = fs.readFileSync(`${ folder }/${ packageName }`).toString();
const fileJson = JSON.parse(file);
// console.log(sourceJson);
const merged = mergeJson(fileJson, sourceJson);
// console.log(merged);
fs.writeFileSync(`${ folder }/${ packageName }`, replaceAll(JSON.stringify(merged, null, 2)));
// fs.writeFileSync(`${ folder }/${ packageName }`, replaceAll(JSON.stringify(merged, Object.keys(merged).sort(), 2)));
// fs.writeFileSync(`${ folder }/${ packageName }`, replaceAll(JSON.stringify(merged, Object.keys(merged).sort((a, b) => a.localeCompare(b)), 2)));
// fs.writeFileSync(`${ folder }/${ packageName }`, replaceAll(JSON.stringify(merged, Object.keys(merged).sort((a, b) => a.localeCompare(b, 'en', { ignorePunctuation: true })), 2)));
// console.log(packageName);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment