diff --git a/bin/po2android.js b/bin/po2android.js index 6b9c5e87c2..ce307dde64 100755 --- a/bin/po2android.js +++ b/bin/po2android.js @@ -33,6 +33,21 @@ function escapeResourceXML( unsafeXMLValue ) { } ); } +/** + * Android specifics replacements. + * + * @param {string} XMLValue input to apply replacements. + * @return {string} valid string passing Android linter rules. + */ +function androidReplacements( XMLValue ) { + return XMLValue.replace( /(-|\.\.\.)/gm, function( character ) { + switch ( character ) { + case '-': return '–'; // Android lint rule: TypographyDashes. + case '...': return '…'; // Android lint rule: TypographyEllipsis + } + } ); +} + /** * Generate a unique string identifier to use as the `name` property in our xml. * Try using the string first by stripping any non-alphanumeric characters and cropping it @@ -74,8 +89,8 @@ function po2Android( poInput ) { return result; } const uniqueName = getUniqueName( translation.msgid ); - const escapedValue = escapeResourceXML( translation.msgid ); - const escapedValuePlural = escapeResourceXML( translation.msgid_plural || '' ); + const escapedValue = androidReplacements( escapeResourceXML( translation.msgid ) ); + const escapedValuePlural = androidReplacements( escapeResourceXML( translation.msgid_plural || '' ) ); const comment = translation.comments.extracted || ''; let localizedEntry = ''; if ( comment ) {