Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new androidReplacements function to comply with Android Typography lint rules #2107

Merged
merged 1 commit into from
Apr 3, 2020
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