-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update pot scripts to add dist files as additional reference
- Loading branch information
Showing
4 changed files
with
74 additions
and
53 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
const fs = require( 'fs' ); | ||
|
||
const PATH = './lang/sensei-lms.pot'; | ||
|
||
/** | ||
* Additional references by RegExp. | ||
*/ | ||
const additionalReferences = [ | ||
{ | ||
re: /^#: assets\/onboarding\//gm, | ||
reference: '#: assets/dist/onboarding/index.js:1', | ||
}, | ||
]; | ||
|
||
/** | ||
* Run script to add new references. | ||
*/ | ||
const run = () => { | ||
fs.readFile( PATH, 'utf8', ( err, data ) => { | ||
if ( err ) throw err; | ||
|
||
saveChanges( addNewReferences( data ) ); | ||
} ); | ||
}; | ||
|
||
/** | ||
* Save changes. | ||
* | ||
* @param {string} newPotString New content to be saved. | ||
*/ | ||
const saveChanges = ( newPotString ) => { | ||
fs.writeFile( PATH, newPotString, 'utf8', ( err ) => { | ||
if ( err ) throw err; | ||
} ); | ||
}; | ||
|
||
/** | ||
* Add new references to the pot string. | ||
* | ||
* @param {string} potString Current pot string to be replaced. | ||
* | ||
* @return {string} Pot string after adding new references. | ||
*/ | ||
const addNewReferences = ( potString ) => { | ||
const potSplitter = '\n\n'; | ||
const splittedPot = potString.split( potSplitter ); | ||
const header = splittedPot[ 0 ]; | ||
|
||
const messages = splittedPot | ||
.slice( 1 ) // Skip header. | ||
.map( ( message ) => { | ||
let newMessage = message; | ||
|
||
additionalReferences.forEach( ( r ) => { | ||
if ( ! message.match( r.re ) ) { | ||
return; | ||
} | ||
|
||
newMessage = newMessage.replace( | ||
/\n(?!#)/, | ||
'\n' + r.reference + '\n' | ||
); | ||
} ); | ||
|
||
return newMessage; | ||
} ); | ||
|
||
return [ header, ...messages ].join( potSplitter ); | ||
}; | ||
|
||
run(); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters