Skip to content

Commit

Permalink
Merge pull request #1014 from 10up/fix/translate-js-files-947
Browse files Browse the repository at this point in the history
Tweak: create pot file with WP CLI and  move translations to JS files
  • Loading branch information
peterwilsoncc authored Mar 10, 2023
2 parents db587b0 + e6f1dd3 commit 7cced9d
Show file tree
Hide file tree
Showing 20 changed files with 679 additions and 260 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/build-stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,22 @@ jobs:
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
- name: Set PHP version
uses: shivammathur/[email protected]
with:
php-version: 7.4
tools: composer:v2
- name: Check versions
run: npm -v; node -v
run: |
npm -v
node -v
php -v
composer -v
- name: Install and build
run: |
composer install --no-dev
npm install
npm run makepot
npm run release
- name: Push to Stable
env:
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/generate-zip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Generate ZIP

on:
workflow_dispatch:
inputs:
ref:
description: 'Git Commit Ref (branch, tag, or hash)'
required: false
type: string

jobs:
generate_zip:
name: New ZIP file
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
with:
ref: ${{ inputs.ref }}
- name: Use desired version of NodeJS
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
- name: Set PHP version
uses: shivammathur/[email protected]
with:
php-version: 7.4
tools: composer:v2, wp
- name: Check versions
run: |
npm -v
node -v
php -v
composer -v
- name: Install and build
run: |
composer install --no-dev
npm install
npm run release
npm run plugin-zip
rm -rf ./release && unzip ${{ github.event.repository.name }}.zip -d ./release
- name: Upload the ZIP file as an artifact
uses: actions/upload-artifact@v3
with:
name: ${{ github.event.repository.name }}
path: release
retention-days: 5
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ vendor/*
!vendor/georgestephanis
release/*
dist/*
screenshots/
lang/
docs-built
.phpunit.result.cache
/.wp-env.override.json

tests/cypress/videos
tests/cypress/screenshots

distributor.zip
134 changes: 110 additions & 24 deletions assets/js/admin-external-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import jQuery from 'jquery';
import _ from 'underscore';
import { addQueryArgs, isURL, prependHTTP } from '@wordpress/url';
import { speak } from '@wordpress/a11y';
import { __, sprintf } from '@wordpress/i18n';
import compareVersions from 'compare-versions';

const { ajaxurl, alert, document, dt, history } = window;
Expand Down Expand Up @@ -90,7 +91,12 @@ jQuery( authorizeConnectionButton ).on( 'click', ( event ) => {

let siteURL = prependHTTP( externalSiteUrlField.value );
if ( ! isURL( siteURL ) ) {
jQuery( wizardError[ 0 ] ).text( dt.invalid_url );
jQuery( wizardError[ 0 ] ).text(
__(
'Please enter a valid URL, including the HTTP(S).',
'distributor'
)
);
return false;
}

Expand Down Expand Up @@ -128,11 +134,21 @@ jQuery( authorizeConnectionButton ).on( 'click', ( event ) => {
'version'
)
) {
jQuery( wizardError[ 0 ] ).text( dt.no_distributor );
jQuery( wizardError[ 0 ] ).text(
__(
'Distributor not installed on remote site.',
'distributor'
)
);
return;
}

jQuery( wizardError[ 0 ] ).text( dt.noconnection );
jQuery( wizardError[ 0 ] ).text(
__(
'Distributor not installed on remote site.',
'distributor'
)
);

if (
Object.prototype.hasOwnProperty.call( response, 'data' ) &&
Expand Down Expand Up @@ -164,7 +180,12 @@ jQuery( authorizeConnectionButton ).on( 'click', ( event ) => {
if (
compareVersions.compare( response.data.version, '1.6.0', '<' )
) {
jQuery( wizardError[ 0 ] ).text( dt.minversion );
jQuery( wizardError[ 0 ] ).text(
__(
'Remote site requires Distributor version 1.6.0 or greater. Upgrade Distributor on the remote site to use the Authentication Wizard.',
'distributor'
)
);
return;
}

Expand All @@ -173,7 +194,10 @@ jQuery( authorizeConnectionButton ).on( 'click', ( event ) => {
! response.data.core_application_passwords_available
) {
jQuery( wizardError[ 0 ] ).text(
dt.application_passwords_not_available
__(
'Application Passwords is not available on the remote site. Please set up connection manually!',
'distributor'
)
);
return;
}
Expand Down Expand Up @@ -207,7 +231,12 @@ jQuery( authorizeConnectionButton ).on( 'click', ( event ) => {
}

const authURL = addQueryArgs( auth_url, {
app_name: dt.distributor_from /*eslint camelcase: 0*/,
app_name: sprintf(
/* translators: %1$s: site name, %2$s: site URL */
__( 'Distributor on %1$s (%2$s)', 'distributor' ),
dt.blog_name,
dt.home_url
),
success_url: encodeURI( successURL ) /*eslint camelcase: 0*/,
reject_url: encodeURI( failureURL ) /*eslint camelcase: 0*/,
} );
Expand Down Expand Up @@ -246,7 +275,7 @@ function checkConnections() {
}

endpointResult.setAttribute( 'data-endpoint-state', 'loading' );
endpointResult.innerText = dt.endpoint_checking_message;
endpointResult.innerText = __( 'Checking endpoint…', 'distributor' );

endpointErrors.innerText = '';

Expand Down Expand Up @@ -289,7 +318,10 @@ function checkConnections() {
endpointResult.setAttribute( 'data-endpoint-state', 'error' );

if ( response.data.endpoint_suggestion ) {
endpointResult.innerText = `${ dt.endpoint_suggestion } `;
endpointResult.innerText = `${ __(
'Did you mean: ',
'distributor'
) } `;

const suggestion = document.createElement( 'button' );
suggestion.classList.add( 'suggest' );
Expand All @@ -300,43 +332,86 @@ function checkConnections() {
endpointResult.appendChild( suggestion );

speak(
`${ dt.endpoint_suggestion } ${ response.data.endpoint_suggestion }`,
`${ __( 'Did you mean: ', 'distributor' ) } ${
response.data.endpoint_suggestion
}`,
'polite'
);
} else {
endpointResult.innerText = dt.bad_connection;
endpointResult.innerText = __(
'No connection found.',
'distributor'
);

speak( dt.bad_connection, 'polite' );
speak(
__( 'No connection found.', 'distributor' ),
'polite'
);
}
} else if (
response.data.errors.no_distributor ||
! response.data.can_post.length
) {
endpointResult.setAttribute( 'data-endpoint-state', 'warning' );
endpointResult.innerText = dt.limited_connection;
endpointResult.innerText = __(
'Limited connection established.',
'distributor'
);

const warnings = [];

if ( response.data.errors.no_distributor ) {
endpointResult.innerText += ` ${ dt.no_distributor }`;
endpointResult.innerText += ` ${ __(
'Distributor not installed on remote site.',
'distributor'
) }`;
speak(
`${ dt.limited_connection } ${ dt.no_distributor }`,
`${ __(
'Limited connection established.',
'distributor'
) } ${ __(
'Distributor not installed on remote site.',
'distributor'
) }`,
'polite'
);
} else {
speak( `${ dt.limited_connection }`, 'polite' );
speak(
`${ __(
'Limited connection established.',
'distributor'
) }`,
'polite'
);
}

if ( 'no' === response.data.is_authenticated ) {
warnings.push( dt.bad_auth );
warnings.push(
__(
'Authentication failed due to invalid credentials.',
'distributor'
)
);
}

if ( 'yes' === response.data.is_authenticated ) {
warnings.push( dt.no_permissions );
warnings.push(
__(
'Authentication succeeded but your account does not have permissions to create posts on the external site.',
'distributor'
)
);
}

warnings.push( dt.no_push );
warnings.push( dt.pull_limited );
warnings.push(
__( 'Push distribution unavailable.', 'distributor' )
);
warnings.push(
__(
'Pull distribution limited to basic content, i.e. title and content body.',
'distributor'
)
);

warnings.forEach( ( warning ) => {
const warningNode = document.createElement( 'li' );
Expand All @@ -346,9 +421,15 @@ function checkConnections() {
} );
} else {
endpointResult.setAttribute( 'data-endpoint-state', 'valid' );
endpointResult.innerText = dt.good_connection;
endpointResult.innerText = __(
'Connection established.',
'distributor'
);

speak( dt.good_connection, 'polite' );
speak(
__( 'Connection established.', 'distributor' ),
'polite'
);
}
} )
.always( () => {
Expand Down Expand Up @@ -457,11 +538,11 @@ jQuery( changePassword ).on( 'click', ( event ) => {
if ( passwordField.disabled ) {
passwordField.disabled = false;
passwordField.value = '';
event.currentTarget.innerText = dt.cancel;
event.currentTarget.innerText = __( 'Cancel', 'distributor' );
} else {
passwordField.disabled = true;
passwordField.value = 'sdfdsfsdfdsfdsfsd'; // filler password
event.currentTarget.innerText = dt.change;
event.currentTarget.innerText = __( 'Change', 'distributor' );
}

checkConnections();
Expand All @@ -480,7 +561,12 @@ jQuery( rolesAllowed ).on( 'click', '.dt-role-checkbox', ( event ) => {
'administrator' !== event.target.value &&
'editor' !== event.target.value
) {
alert( dt.roles_warning ); // eslint-disable-line no-alert
alert(
__(
'Be careful assigning less trusted roles push privileges as they will inherit the capabilities of the user on the remote site.',
'distributor'
)
); // eslint-disable-line no-alert
}
} );

Expand Down
8 changes: 4 additions & 4 deletions assets/js/admin-pull.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import '../css/admin-pull-table.scss';

import jQuery from 'jquery';
import { addQueryArgs } from '@wordpress/url';
import { __ } from '@wordpress/i18n';

const { document, dt } = window;
const { document } = window;

const chooseConnection = document.getElementById( 'pull_connections' );
const choosePostType = document.getElementById( 'pull_post_type' );
Expand All @@ -13,7 +14,6 @@ const searchBtn = document.getElementById( 'search-submit' );
const form = document.getElementById( 'posts-filter' );
const asDraftCheckboxes = document.querySelectorAll( '[name=dt_as_draft]' );
const pullLinks = document.querySelectorAll( '.distributor_page_pull .pull a' );
const { pull: pullText, as_draft: pullAsDraftText } = dt;

jQuery( chooseConnection ).on( 'change', ( event ) => {
document.location =
Expand Down Expand Up @@ -58,7 +58,7 @@ if ( chooseConnection && choosePostType && form ) {
pullLinks[ i ].href = addQueryArgs( pullLinks[ i ].href, {
dt_as_draft: 'draft' /*eslint camelcase: 0*/,
} );
pullLinks[ i ].text = pullAsDraftText;
pullLinks[ i ].text = __( 'Pull as draft', 'distributor' );
}
} else {
for ( let i = 0; i < asDraftCheckboxes.length; ++i ) {
Expand All @@ -69,7 +69,7 @@ if ( chooseConnection && choosePostType && form ) {
pullLinks[ i ].href = addQueryArgs( pullLinks[ i ].href, {
dt_as_draft: '' /*eslint camelcase: 0*/,
} );
pullLinks[ i ].text = pullText;
pullLinks[ i ].text = __( 'Pull', 'distributor' );
}
}
} );
Expand Down
Loading

0 comments on commit 7cced9d

Please sign in to comment.