From e2db58db29c4e8213053659caaf89388c213942a Mon Sep 17 00:00:00 2001 From: Pavlo Karatsiuba Date: Sat, 4 Mar 2023 15:50:50 +0100 Subject: [PATCH 1/2] Added command line parameter to not create zim for languages with variants --- README.md | 7 +++++++ steps/get.ts | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 950c316..c160093 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,13 @@ npm i && npm start The above will eventually output a ZIM file to ```dist/``` ## Command line arguments +`--withoutLanguageVariants` uses to exclude languages with County variant. For example `en_ca` will not be present in zim with this argument. + +Available only on GET step: +```bash +--withoutLanguageVariants ... +``` + Available on GET and EXPORT steps only: ```bash --includeLanguages lang_1 [lang_2] [lang_3] ... diff --git a/steps/get.ts b/steps/get.ts index b93fee7..2942b5b 100644 --- a/steps/get.ts +++ b/steps/get.ts @@ -20,7 +20,7 @@ import { hideBin } from 'yargs/helpers' dotenv.config() -const { argv } = yargs(hideBin(process.argv)).array('includeLanguages').array('excludeLanguages') +const { argv } = yargs(hideBin(process.argv)).boolean('withoutLanguageVariants').array('includeLanguages').array('excludeLanguages') const failedDownloadsCountBeforeStop = 10 const outDir = 'state/get/' @@ -81,6 +81,9 @@ const fetchLanguages = async (): Promise => { rows.forEach((item) => { const url = $(item).find('td.list-highlight-background:first-child a').attr('href') const slug = /locale=(.*)$/.exec(url)?.pop() + if (argv.withoutLanguageVariants && slug.includes('_')) { + return + } const name = $(item).find('td.list-highlight-background:first-child a span').text() const nativeLangName = ISO6391.getNativeName(slug) From 25ee244cadd79eb5c5ab98087581f4e4663218bb Mon Sep 17 00:00:00 2001 From: Pavlo Karatsiuba Date: Sun, 5 Mar 2023 11:06:03 +0100 Subject: [PATCH 2/2] Added log message to see skipped languages. Description typos fixed --- README.md | 2 +- steps/get.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c160093..6a6220f 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ npm i && npm start The above will eventually output a ZIM file to ```dist/``` ## Command line arguments -`--withoutLanguageVariants` uses to exclude languages with County variant. For example `en_ca` will not be present in zim with this argument. +`--withoutLanguageVariants` uses to exclude languages with Country variant. For example `en_CA` will not be present in zim with this argument. Available only on GET step: ```bash diff --git a/steps/get.ts b/steps/get.ts index 2942b5b..a1d7e4a 100644 --- a/steps/get.ts +++ b/steps/get.ts @@ -82,6 +82,7 @@ const fetchLanguages = async (): Promise => { const url = $(item).find('td.list-highlight-background:first-child a').attr('href') const slug = /locale=(.*)$/.exec(url)?.pop() if (argv.withoutLanguageVariants && slug.includes('_')) { + log.info(`Skipping ${slug} language`) return } const name = $(item).find('td.list-highlight-background:first-child a span').text()