Skip to content

Code refactoring for a better i18n for strings that were in JS files.#147

Merged
guzzilar merged 7 commits intomasterfrom
better-i18n
Dec 9, 2019
Merged

Code refactoring for a better i18n for strings that were in JS files.#147
guzzilar merged 7 commits intomasterfrom
better-i18n

Conversation

@guzzilar
Copy link
Copy Markdown
Contributor

@guzzilar guzzilar commented Nov 11, 2019

1. Objective

There are some parts of the plugin that cannot be translated as originally it wasn't implemented for the idea of translating to another language.

This pull request is to i18n the plugin. Preparing for the up-coming feature that requires the plugin to be translated to another language : )

Related information:
Related issue(s): T2778, T17731 (internal ticket)

2. Description of change

3. Quality assurance

🔧 Environments:

  • WooCommerce: v3.8.0
  • WordPress: v5.3.2
  • PHP version: 7.3.3

✏️ Details:

Checkout page
Expectation
omise-payment-form-handler.js should be able to display a warning message using strings that is passed via server-side properly in each of cases.

3.1. In a case where card fields are left in blank when place a new order.**
Screen Shot 2562-11-13 at 05 32 13

3.2. In a case of attempting to create a new token but card informations are invalid. (I.e. using an expired card).
Expectation

Screen Shot 2562-11-13 at 09 49 22 copy

3.3. This is an edge case where the JS script cannot find a designated DOM to retrieve Omise card id at the checkout page (i.e. Omise credit card form is modified by a 3rd-party plugin or someone modified the form directly in Omise-WooCommerce code)

// assets/javascripts/omise-payment-form-handler.js
function validSelection(){
    $card_list = $("input[name='card_id']");
    $selected_card_id = $("input[name='card_id']:checked");

    ...
}

Screen Shot 2562-11-13 at 10 12 12 copy

3.4. Failed to retrieve a response back from Omise API.
Screen Shot 2562-11-13 at 10 42 09 copy

My Account page
Expectation
omise-myaccount-card-handler.js should be able to display a warning message using strings that is passed via server-side properly.

Screen Shot 2562-11-14 at 04 23 01 copy

4. Impact of the change

Some messages have been changed, corrected, and improved.
This would affect the current translation of the plugin.
https://translate.wordpress.org/projects/wp-plugins/omise

However, the plugin hasn't been properly translated for a while, so we may consider this as a, 'revamp' the entire translation work.

5. Priority of change

Normal

6. Additional Notes

This is to prepare the code to be able to translate.
The translation process will be done in GlotPress. (https://translate.wordpress.org/projects/wp-plugins/omise)

Also note that during the review, you may find some part of code that could be improved or refactored. However, I would like to leave it as it is for now, as this pull request is aiming for i18n strains at the JS files.

Personally, I'm planning to clean up the code and polish It after Konbini payment is done.
But, any thoughts are welcomed : )

To be able to translate those invalid-input error messages (field is required) properly,
we must not put an error message directly in a JS file.
'retry_or_contact_support' => wp_kses(
__( 'This incident could happen either from using an invalid card or the payment provider server is under maintainence.<br/>
You may retry again in a couple seconds, or contact our support team if you have any question.', 'omise' ),
array( 'br' => array() )
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tl;dr
Some of these strings are being used in 2 places. This could raise a potential case of unmatching translation.
However, I'm planning to have a dedicated PR to properly handle this topic as this might be a bit out of scope of this PR (and don't want to make this PR too big).


Note, some of these strings are being used in 2 places, at Omise_Payment_Creditcard and Omise_MyAccount.
This is because we're removing omise-util.js and move these invalidation messages back to server side so we can localize it.

This could raise a potential case where one place gets updated over another causing an unmatching translation.

I'm thinking of housing all the translation strings in one class (i.e. Omise_Localization) so we will have only one place to look for when these needed to be updated.

However, this might be too much for this PR.
I'm planning having a dedicated PR for this topic right after this PR (or, before releasing Konbini payment, at late – this PR may be released along with a PR that was solving 3-D Secure setting feature before I finish the Omise_Localization one).

@guzzilar guzzilar changed the title [WIP] Code refactoring for a better i18n [WIP] Code refactoring for a better i18n for strings that were in JS files. Nov 12, 2019
@guzzilar guzzilar changed the title [WIP] Code refactoring for a better i18n for strings that were in JS files. Code refactoring for a better i18n for strings that were in JS files. Nov 13, 2019

var errors = OmiseUtil.validate_card(card);
if(errors.length > 0){
let errors = [],
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is identical to that in the other file. Feels like maybe we should be reusing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I think so that we may somehow can merge these 2 JS files together. (however, please ignore the duplication here for a while as it is a bit out of scope of this PR)

Comment thread includes/class-omise-wc-myaccount.php Outdated
'key' => Omise()->settings()->public_key(),
'ajax_url' => admin_url( 'admin-ajax.php' ),
'ajax_loader_url' => plugins_url( '/assets/images/ajax-loader@2x.gif', dirname( __FILE__ ) ),
'required_card_name' => __( 'Card Holder\'s name is a required field', 'omise' ),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cardholder's

Comment thread includes/class-omise-wc-myaccount.php Outdated
'ajax_loader_url' => plugins_url( '/assets/images/ajax-loader@2x.gif', dirname( __FILE__ ) ),
'required_card_name' => __( 'Card Holder\'s name is a required field', 'omise' ),
'required_card_number' => __( 'Card Number is a required field', 'omise' ),
'required_card_expiration_month' => __( 'Card Expiry month is a required field', 'omise' ),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Card' probably unnecessary here

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and the two fields next

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message is mixed with the other invalid form input's error messages.
If possible and not grammatically wrong, as for UX of WC, I think we better explicitly say that this error is coming from the credit card form, not others.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, the error message isn't displayed next to the field?

Comment thread includes/class-omise-wc-myaccount.php Outdated
'required_card_expiration_year' => __( 'Card Expiry year is a required field', 'omise' ),
'required_card_security_code' => __( 'Card Security code is a required field', 'omise' ),
'cannot_create_card' => __( 'Unable to add a new card.', 'omise' ),
'cannot_connect_api' => __( 'Currently, the payment provider server is under maintain.', 'omise' ),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'... undergoing maintenance.'

Comment thread includes/class-omise-wc-myaccount.php Outdated
'check_internet_connection' => __( 'Please make sure that your internet connection is stable.', 'omise' ),
'retry_or_contact_support' => wp_kses(
__( 'This incident could happen either from using an invalid card or the payment provider server is under maintainence.<br/>
You may retry again in a couple seconds, or contact our support team if you have any question.', 'omise' ),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This incident could occur either from the use of an invalid card, or the payment provider server is undergoing maintenance.
You may retry again in a couple of seconds, or contact our support team if you have any questions.


$omise_params = array(
'key' => $this->public_key(),
'required_card_name' => __( 'Card Holder\'s name is a required field', 'omise' ),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cardholder

'key' => $this->public_key(),
'required_card_name' => __( 'Card Holder\'s name is a required field', 'omise' ),
'required_card_number' => __( 'Card Number is a required field', 'omise' ),
'required_card_expiration_month' => __( 'Card Expiry month is a required field', 'omise' ),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before - the word 'Card' is superfluous in this and the following 2 field messages

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, inconsistent capitalisation of field name words. Some have all words capitalised, some don't. Need to pick a style and stay with it

'required_card_expiration_year' => __( 'Card Expiry year is a required field', 'omise' ),
'required_card_security_code' => __( 'Card Security code is a required field', 'omise' ),
'invalid_card' => __( 'Invalid card.', 'omise' ),
'no_card_selected' => __( 'Please select a card or entering a new one.', 'omise' ),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please select a card or enter a new one.

'required_card_security_code' => __( 'Card Security code is a required field', 'omise' ),
'invalid_card' => __( 'Invalid card.', 'omise' ),
'no_card_selected' => __( 'Please select a card or entering a new one.', 'omise' ),
'cannot_create_token' => __( 'Unable to continue to proceed the payment.', 'omise' ),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not even sure what you're trying to say here... Maybe 'Unable to proceed to the payment.'?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is for a case where the plugin cannot retrieve a response body back from Omise.js.
I'll change to the one you suggested.

'invalid_card' => __( 'Invalid card.', 'omise' ),
'no_card_selected' => __( 'Please select a card or entering a new one.', 'omise' ),
'cannot_create_token' => __( 'Unable to continue to proceed the payment.', 'omise' ),
'cannot_connect_api' => __( 'Currently, the payment provider server is under maintain.', 'omise' ),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the payment provider server is undergoing maintenance.

'no_card_selected' => __( 'Please select a card or entering a new one.', 'omise' ),
'cannot_create_token' => __( 'Unable to continue to proceed the payment.', 'omise' ),
'cannot_connect_api' => __( 'Currently, the payment provider server is under maintain.', 'omise' ),
'retry_checkout' => __( 'Please place your order again in a couple seconds.', 'omise' ),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...couple of...

Copy link
Copy Markdown

@jonrandy jonrandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See notes

} );

data = {
action: "omise_create_card",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that code formatting correct? regarding indents.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the new one is correct, the old one is wrong.
But good catch 👍 I'm afraid to re-adjust the whole file cuz it's going to be super hard for you guys to review, also I was thinking that this file will be modified more when I work on the API translation stuff. So it's kinda mixed style now.

@guzzilar
Copy link
Copy Markdown
Contributor Author

guzzilar commented Dec 9, 2019

Thanks for the review, guys 👍

@guzzilar guzzilar merged commit 77e3a8b into master Dec 9, 2019
@guzzilar guzzilar deleted the better-i18n branch December 9, 2019 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants