Skip to content

Commit

Permalink
feat: use current locale language (only ru/en, default en)
Browse files Browse the repository at this point in the history
  • Loading branch information
popstas committed Aug 22, 2020
1 parent d4243eb commit a2461a0
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const fs = require('fs');
const process = require('process');
const { program } = require('commander');
const packageJson = require('../package.json');
const systemLocale = getDefaultLocale(); // should be before scrap-site (before lighthouse require)
const scrapSite = require('./scrap-site');
const saveAsXlsx = require('./save-as-xlsx');
const saveAsJson = require('./save-as-json');
Expand Down Expand Up @@ -59,7 +60,7 @@ program
.option('--json', `Output results in JSON`)
.option('--upload', `Upload JSON to public web`)
.option('--no-color', `No console colors`)
.option('--lang <lang>', `Language (en, ru)`, 'ru')
.option('--lang <lang>', `Language (en, ru, default: system language)`)
.option('--open-file', `Open file after scan (default: yes on Windows and MacOS)`)
.option('--no-open-file', `Don't open file after scan`)
.option('--no-console-validate', `Don't output validate messages in console`)
Expand All @@ -73,7 +74,10 @@ async function start() {
program.openFile = ['darwin', 'win32'].includes(os.platform()); // only for win and mac
}

if(!['en', 'ru'].includes(program.lang)) program.lang = 'ru';
// lang
if(!['en', 'ru'].includes(program.lang)) program.lang = systemLocale;

// --json when --upload
if(program.upload) program.json = true;

if(program.csv) {
Expand Down Expand Up @@ -172,12 +176,12 @@ async function start() {
{
name: 'Upload JSON',
value: (program.upload ? 'yes' : 'no'),
comment: (!program.json ? '--json --upload' : '')
comment: (!program.upload ? '--upload' : '')
},
{
name: 'Language',
value: program.lang,
comment: (program.lang == 'ru' ? '--lang [en]' : '')
comment: '--lang ' + (program.lang == 'ru' ? 'en' : 'ru')
},
{
name: 'Docs extensions',
Expand Down Expand Up @@ -225,6 +229,20 @@ async function start() {
}
}

// only ru and en, default en
function getDefaultLocale() {
const locale = new Intl.DateTimeFormat().resolvedOptions().locale;
// console.log('locale:', new Intl.DateTimeFormat().resolvedOptions())
const map = {
'en-US': 'en',
'ru-RU': 'ru',
'en': 'en',
'ru': 'ru',
}

return map[locale] || 'en';
}

// not using, now only cli
function parseSitesFile(file){
const urlRegex = /(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&#\/%=~_|$?!:,.]*\)|[A-Z0-9+&#\/%=~_|$])/ig
Expand Down

0 comments on commit a2461a0

Please sign in to comment.