diff --git a/cli/src/commands/build.js b/cli/src/commands/build.js index 1b0a2300e..4c68d18bf 100644 --- a/cli/src/commands/build.js +++ b/cli/src/commands/build.js @@ -89,11 +89,16 @@ const handler = async ({ } reporter.info('Generating internationalization strings...') - await i18n.extract({ input: paths.src, output: paths.i18nStrings }) + await i18n.extract({ + input: paths.src, + output: paths.i18nStrings, + paths, + }) await i18n.generate({ input: paths.i18nStrings, output: paths.i18nLocales, namespace: 'default', + paths, }) if (config.type === 'app') { diff --git a/cli/src/commands/i18n.js b/cli/src/commands/i18n.js index bc91f96cf..5a4f3e16c 100644 --- a/cli/src/commands/i18n.js +++ b/cli/src/commands/i18n.js @@ -1,5 +1,6 @@ const { namespace, reporter } = require('@dhis2/cli-helpers-engine') const i18n = require('../lib/i18n') +const makePaths = require('../lib/paths') const generate = { description: @@ -9,12 +10,10 @@ const generate = { alias: 'p', description: 'directory path to find .po/.pot files and convert to JSON', - default: './i18n/', }, output: { alias: 'o', description: 'Output directory to place converted JSON files.', - default: './src/locales/', }, namespace: { alias: 'n', @@ -22,11 +21,14 @@ const generate = { default: 'default', }, }, - handler: async argv => { + handler: async ({ cwd, path, output, namespace }) => { + const paths = makePaths(cwd) + const result = await i18n.generate({ - input: argv.path, - output: argv.output, - namespace: argv.namespace, + input: path || paths.i18nStrings, + output: output || paths.i18nLocales, + namespace, + paths, }) if (!result) { @@ -43,18 +45,19 @@ const extract = { alias: 'p', description: 'Directory path to recurse and extract i18n.t translation strings', - default: './src/', }, output: { alias: 'o', description: 'Destination path for en.pot file', - default: './i18n/', }, }, - handler: async argv => { + handler: async ({ cwd, path, output }) => { + const paths = makePaths(cwd) + const result = await i18n.extract({ - input: argv.path, - output: argv.output, + input: path || paths.src, + output: output || paths.i18nStrings, + paths, }) if (!result) { reporter.error('Failed to extract i18n strings.') diff --git a/cli/src/commands/start.js b/cli/src/commands/start.js index 0e86f4f69..08048757d 100644 --- a/cli/src/commands/start.js +++ b/cli/src/commands/start.js @@ -48,11 +48,16 @@ const handler = async ({ } reporter.info('Generating internationalization strings...') - await i18n.extract({ input: paths.src, output: paths.i18nStrings }) + await i18n.extract({ + input: paths.src, + output: paths.i18nStrings, + paths, + }) await i18n.generate({ input: paths.i18nStrings, output: paths.i18nLocales, namespace: 'default', + paths, }) reporter.info('Bootstrapping local appShell...') diff --git a/cli/src/lib/i18n/extract.js b/cli/src/lib/i18n/extract.js index ac7076988..f8df904d7 100644 --- a/cli/src/lib/i18n/extract.js +++ b/cli/src/lib/i18n/extract.js @@ -5,8 +5,8 @@ const { i18nextToPot, gettextToI18next } = require('i18next-conv') const scanner = require('i18next-scanner') const { checkDirectoryExists, walkDirectory, arrayEqual } = require('./helpers') -const extract = async ({ input, output }) => { - const relativeInput = './' + path.relative(process.cwd(), input) +const extract = async ({ input, output, paths }) => { + const relativeInput = './' + path.relative(paths.base, input) if (!checkDirectoryExists(input)) { reporter.error( `I18n source directory ${chalk.bold(relativeInput)} does not exist.` @@ -73,7 +73,7 @@ const extract = async ({ input, output }) => { reporter.print( chalk.dim( `Writing ${Object.keys(en).length} language strings to ${chalk.bold( - './' + targetPath + './' + path.relative(paths.base, targetPath) )}...` ) ) diff --git a/cli/src/lib/i18n/generate.js b/cli/src/lib/i18n/generate.js index 7f129c098..60c213011 100644 --- a/cli/src/lib/i18n/generate.js +++ b/cli/src/lib/i18n/generate.js @@ -15,9 +15,9 @@ const writeTemplate = (outFile, data) => { fs.writeFileSync(outFile, localesTemplate(data)) } -const generate = async ({ input, output, namespace }) => { +const generate = async ({ input, output, namespace, paths }) => { if (!checkDirectoryExists(input)) { - const relativeInput = './' + path.relative(process.cwd(), input) + const relativeInput = './' + path.relative(paths.base, input) reporter.debug( `Source directory ${chalk.bold( relativeInput