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

fix: dokan js translation loading #2377

Merged
merged 4 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
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
32 changes: 18 additions & 14 deletions includes/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,17 +368,18 @@ public function get_scripts() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
$asset_url = DOKAN_PLUGIN_ASSEST;
$asset_path = DOKAN_DIR . '/assets/';
$bootstrap_deps = [ 'dokan-vue-vendor', 'dokan-i18n-jed', 'wp-hooks' ];
$bootstrap_deps = [ 'dokan-vue-vendor', 'wp-i18n', 'wp-hooks' ];

$scripts = [
'jquery-tiptip' => [
'src' => WC()->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js',
'deps' => [ 'jquery' ],
],
'dokan-i18n-jed' => [
'src' => $asset_url . '/vendors/i18n/jed.js',
'deps' => [ 'jquery' ],
],
// Remove `dokan-i18n-jed` in next release.
'dokan-i18n-jed' => [
'src' => $asset_url . '/vendors/i18n/jed.js',
'deps' => [ 'jquery', 'wp-i18n' ],
],
'dokan-accounting' => [
'src' => WC()->plugin_url() . '/assets/js/accounting/accounting.min.js',
'deps' => [ 'jquery' ],
Expand Down Expand Up @@ -472,23 +473,23 @@ public function get_scripts() {
],
'dokan-admin' => [
'src' => $asset_url . '/js/dokan-admin.js',
'deps' => [ 'jquery', 'dokan-i18n-jed' ],
'deps' => [ 'jquery', 'wp-i18n' ],
'version' => filemtime( $asset_path . 'js/dokan-admin.js' ),
],
'dokan-vendor-registration' => [
'src' => $asset_url . '/js/vendor-registration.js',
'deps' => [ 'dokan-form-validate', 'jquery', 'speaking-url', 'dokan-i18n-jed' ],
'deps' => [ 'dokan-form-validate', 'jquery', 'speaking-url', 'wp-i18n' ],
'version' => filemtime( $asset_path . 'js/vendor-registration.js' ),
],
'dokan-script' => [
'src' => $asset_url . '/js/dokan.js',
'deps' => [ 'imgareaselect', 'customize-base', 'customize-model', 'dokan-i18n-jed', 'jquery-tiptip', 'moment', 'dokan-date-range-picker', 'dokan-accounting' ],
'deps' => [ 'imgareaselect', 'customize-base', 'customize-model', 'wp-i18n', 'jquery-tiptip', 'moment', 'dokan-date-range-picker', 'dokan-accounting' ],
'version' => filemtime( $asset_path . 'js/dokan.js' ),
],
'dokan-vue-vendor' => [
'src' => $asset_url . '/js/vue-vendor.js',
'version' => filemtime( $asset_path . 'js/vue-vendor.js' ),
'deps' => [ 'dokan-i18n-jed', 'dokan-tinymce-plugin', 'dokan-chart' ],
'deps' => [ 'wp-i18n', 'dokan-tinymce-plugin', 'dokan-chart' ],
],
'dokan-vue-bootstrap' => [
'src' => $asset_url . '/js/vue-bootstrap.js',
Expand All @@ -497,23 +498,23 @@ public function get_scripts() {
],
'dokan-vue-admin' => [
'src' => $asset_url . '/js/vue-admin.js',
'deps' => [ 'jquery', 'jquery-ui-datepicker', 'dokan-i18n-jed', 'dokan-vue-vendor', 'dokan-vue-bootstrap', 'selectWoo' ],
'deps' => [ 'jquery', 'jquery-ui-datepicker', 'wp-i18n', 'dokan-vue-vendor', 'dokan-vue-bootstrap', 'selectWoo' ],
'version' => filemtime( $asset_path . 'js/vue-admin.js' ),
],
'dokan-vue-frontend' => [
'src' => $asset_url . '/js/vue-frontend.js',
'deps' => [ 'jquery', 'dokan-i18n-jed', 'dokan-vue-vendor', 'dokan-vue-bootstrap' ],
'deps' => [ 'jquery', 'wp-i18n', 'dokan-vue-vendor', 'dokan-vue-bootstrap' ],
'version' => filemtime( $asset_path . 'js/vue-frontend.js' ),
],

'dokan-login-form-popup' => [
'src' => $asset_url . '/js/login-form-popup.js',
'deps' => [ 'dokan-modal', 'dokan-i18n-jed' ],
'deps' => [ 'dokan-modal', 'wp-i18n' ],
'version' => filemtime( $asset_path . 'js/login-form-popup.js' ),
],
'dokan-sweetalert2' => [
'src' => $asset_url . '/vendors/sweetalert2/sweetalert2.all.min.js',
'deps' => [ 'dokan-modal', 'dokan-i18n-jed' ],
'deps' => [ 'dokan-modal', 'wp-i18n' ],
'version' => filemtime( $asset_path . 'vendors/sweetalert2/sweetalert2.all.min.js' ),
],
'dokan-util-helper' => [
Expand Down Expand Up @@ -635,7 +636,10 @@ public function enqueue_front_scripts() {

$localize_data = array_merge( $localize_script, $vue_localize_script );

// Remove `dokan-i18n-jed` in next release.
wp_localize_script( 'dokan-i18n-jed', 'dokan', $localize_data );
wp_localize_script( 'dokan-vue-bootstrap', 'dokan', $localize_data );
wp_localize_script( 'dokan-script', 'dokan', $localize_data );

// localized vendor-registration script
wp_localize_script(
Expand Down Expand Up @@ -1083,6 +1087,7 @@ public function register_scripts( $scripts ) {
$version = isset( $script['version'] ) ? $script['version'] : DOKAN_PLUGIN_VERSION;

wp_register_script( $handle, $script['src'], $deps, $version, $in_footer );
wp_set_script_translations( $handle, 'dokan-lite', plugin_dir_path( DOKAN_FILE ) . 'languages' );
}
}

Expand Down Expand Up @@ -1162,7 +1167,6 @@ public function get_admin_localized_scripts() {
'showPromoBanner' => empty( Helper::dokan_get_promo_notices() ),
'hasNewVersion' => Helper::dokan_has_new_version(),
'proVersion' => dokan()->is_pro_exists() ? dokan_pro()->version : '',
'i18n' => [ 'dokan-lite' => dokan_get_jed_locale_data( 'dokan-lite', DOKAN_DIR . '/languages/' ) ],
'urls' => [
'adminRoot' => admin_url(),
'siteUrl' => home_url( '/' ),
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
"vue-template-compiler": "^2.7.14",
"vue-wp-list-table": "^1.3.0",
"vue2-daterange-picker": "^0.6.8",
"wp-readme-to-markdown": "^1.0.1",
"vuedraggable": "^2.24.3"
"vuedraggable": "^2.24.3",
"wp-readme-to-markdown": "^1.0.1"
},
"dependencies": {
"@wordpress/i18n": "^5.8.0"
}
}
2 changes: 1 addition & 1 deletion src/utils/Mixin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setLocaleData, __, _x, __n, _nx, sprintf } from '@/utils/i18n'
import { setLocaleData, __, _x, __n, _nx, sprintf } from '@wordpress/i18n'

Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Import Path Successfully Updated. Review src/utils/i18n.js for Redundancy.

The shell script confirms that there are no remaining imports from @/utils/i18n, and all usages of the internationalization functions are now correctly referencing @wordpress/i18n. However, the src/utils/i18n.js file is still present in the codebase.

  • Action Items:
    • Verify if src/utils/i18n.js is used elsewhere in the project.
    • If unused, consider removing it to maintain a clean and efficient codebase.
Analysis chain

LGTM! Verify consistency across the codebase.

The change from '@/utils/i18n' to '@wordpress/i18n' aligns with the PR objective of fixing JavaScript translation loading. This shift to using WordPress's built-in i18n functions is a good practice for maintaining consistency with WordPress standards.

To ensure this change is consistent across the codebase and doesn't introduce any breaking changes, please run the following verification script:

Additionally, please ensure comprehensive testing is performed to verify that all internationalization functions continue to work as expected after this change.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining imports from '@/utils/i18n' and usages of the imported functions

# Test 1: Check for any remaining imports from '@/utils/i18n'
echo "Checking for remaining imports from '@/utils/i18n':"
rg --type js "from '@/utils/i18n'" src

# Test 2: Check for usages of the imported functions
echo "Checking for usages of imported i18n functions:"
rg --type js -w "setLocaleData|__|_x|__n|_nx|sprintf" src

# Note: Review the output to ensure all occurrences are using '@wordpress/i18n'

Length of output: 73419

export default {
methods: {
Expand Down
105 changes: 0 additions & 105 deletions src/utils/i18n.js

This file was deleted.

1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const updatedConfig = {
},

plugins: [
...defaultConfig.plugins,
new MiniCssExtractPlugin(
{
filename: ( { chunk } ) => {
Expand Down
Loading