Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions bin/po2android.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ) {
Expand Down