Skip to content

Commit

Permalink
fix: dokan js translation loading (#2377)
Browse files Browse the repository at this point in the history
* fix: dokan js translation loading

* add wp_localize_script undo dokan-i18n-jed

* Delete i18n from utils

* update third param to wp_set_script_translations

---------

Co-authored-by: Shazahanul Islam Shohag <[email protected]>
  • Loading branch information
osmansufy and shohag121 authored Oct 16, 2024
1 parent 90bf67a commit f4f60ea
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 122 deletions.
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'

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

0 comments on commit f4f60ea

Please sign in to comment.