diff --git a/lib/commands/localization/update.js b/lib/commands/localization/update.js index 63630f2e..ccf82bd1 100644 --- a/lib/commands/localization/update.js +++ b/lib/commands/localization/update.js @@ -1,5 +1,6 @@ import Command from "#lib/command"; import { ansi } from "#core/text"; +import glob from "#core/glob"; export default class extends Command { static cli () { @@ -8,24 +9,41 @@ export default class extends Command { // public async run () { + var packages; - // XXX if root not founsd - start from the current dir - // const rootPackage = this._findRootPackage(); - const rootPackage = this._findNearestPackage(); + const rootPackage = this._findRootPackage(); - if ( !rootPackage ) this._throwError( `Unable to find root package` ); + if ( rootPackage ) { + packages = [ rootPackage ]; + } + else { + const files = glob( "**/*.po" ), + idx = {}; + + for ( const file of files ) { + const pkg = this._findNearestPackage( file ); + + if ( !pkg ) continue; + + idx[ pkg.root ] = pkg; + } + + packages = Object.values( idx ); + } - const res = await rootPackage.localization.update(); + for ( const pkg of packages ) { + const res = await pkg.localization.update(); - if ( !res.ok ) this._exitOnError(); + if ( !res.ok ) this._exitOnError(); - const localizationStatus = rootPackage.localization.status(); + const localizationStatus = rootPackage.localization.status(); - if ( localizationStatus.data ) { - console.log( "Localization status:\n" ); + if ( localizationStatus.data ) { + console.log( "Localization status:\n" ); - for ( const [ poFilePath, isTranslated ] of Object.entries( localizationStatus.data ) ) { - console.log( isTranslated ? " OK " : ansi.error( " FUZZY " ), poFilePath ); + for ( const [ poFilePath, isTranslated ] of Object.entries( localizationStatus.data ) ) { + console.log( isTranslated ? " OK " : ansi.error( " FUZZY " ), poFilePath ); + } } } }