Code refactoring for a better i18n for strings that were in JS files.#147
Code refactoring for a better i18n for strings that were in JS files.#147
Conversation
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.
6f3b120 to
6a0044f
Compare
7a32564 to
7cbad19
Compare
| '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() ) |
There was a problem hiding this comment.
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).
|
|
||
| var errors = OmiseUtil.validate_card(card); | ||
| if(errors.length > 0){ | ||
| let errors = [], |
There was a problem hiding this comment.
This code is identical to that in the other file. Feels like maybe we should be reusing?
There was a problem hiding this comment.
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)
| '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' ), |
| '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' ), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Ah, the error message isn't displayed next to the field?
| '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' ), |
| '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' ), |
There was a problem hiding this comment.
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' ), |
| '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' ), |
There was a problem hiding this comment.
Same as before - the word 'Card' is superfluous in this and the following 2 field messages
There was a problem hiding this comment.
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' ), |
There was a problem hiding this comment.
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' ), |
There was a problem hiding this comment.
Not even sure what you're trying to say here... Maybe 'Unable to proceed to the payment.'?
There was a problem hiding this comment.
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' ), |
There was a problem hiding this comment.
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' ), |
0380f7b to
bc279c3
Compare
| } ); | ||
|
|
||
| data = { | ||
| action: "omise_create_card", |
There was a problem hiding this comment.
is that code formatting correct? regarding indents.
There was a problem hiding this comment.
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.
|
Thanks for the review, guys 👍 |
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:
✏️ 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.**

3.2. In a case of attempting to create a new token but card informations are invalid. (I.e. using an expired card).
Expectation
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)
3.4. Failed to retrieve a response back from Omise API.

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.
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 : )