|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getGlotPressFunction( properties ) { |
|
|
let wpFunc = [ '_' ]; |
|
|
|
|
|
if ( properties.plural ) { |
|
|
wpFunc.push( 'n' ); |
|
|
} |
|
|
if ( properties.context ) { |
|
|
wpFunc.push( 'x' ); |
|
|
} |
|
|
|
|
|
wpFunc = wpFunc.join( '' ); |
|
|
|
|
|
if ( 1 === wpFunc.length ) { |
|
|
return '__'; |
|
|
} |
|
|
|
|
|
return wpFunc; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function buildPHPString( properties, textdomain ) { |
|
|
const wpFunc = getGlotPressFunction( properties ); |
|
|
const response = []; |
|
|
const closing = textdomain ? ', "' + textdomain.replace( /"/g, '\\"' ) + '" ),' : ' ),'; |
|
|
const stringFromFunc = { |
|
|
__: '__( ' + properties.single + closing, |
|
|
_x: '_x( ' + [ properties.single, properties.context ].join( ', ' ) + closing, |
|
|
_nx: |
|
|
'_nx( ' + |
|
|
[ properties.single, properties.plural, properties.count, properties.context ].join( ', ' ) + |
|
|
closing, |
|
|
_n: '_n( ' + [ properties.single, properties.plural, properties.count ].join( ', ' ) + closing, |
|
|
}; |
|
|
|
|
|
|
|
|
if ( properties.comment ) { |
|
|
|
|
|
response.push( '/* translators: ' + properties.comment.replace( /\*\//g, '*\\/' ) + ' */' ); |
|
|
} |
|
|
|
|
|
let string = stringFromFunc[ wpFunc ]; |
|
|
|
|
|
if ( properties.line ) { |
|
|
string += ' // ' + properties.line; |
|
|
} |
|
|
|
|
|
response.push( string ); |
|
|
|
|
|
return response.join( '\n' ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = function formatInPHP( matches, options ) { |
|
|
const arrayName = options.phpArrayName || options.projectName + '_i18n_strings'; |
|
|
return [ |
|
|
|
|
|
'<?php', |
|
|
'/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */', |
|
|
'$' + arrayName + ' = array(', |
|
|
matches.map( ( element ) => buildPHPString( element, options.textdomain ) ).join( '\n' ), |
|
|
');', |
|
|
'/* THIS IS THE END OF THE GENERATED FILE */', |
|
|
].join( '\n' ); |
|
|
}; |
|
|
|