diff --git a/includes/Assets.php b/includes/Assets.php index e8c7106b9a..913cf2872d 100644 --- a/includes/Assets.php +++ b/includes/Assets.php @@ -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' ], @@ -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', @@ -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' => [ @@ -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( @@ -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' ); } } @@ -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( '/' ), diff --git a/package.json b/package.json index 426c5e1941..54557fa5e1 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/utils/Mixin.js b/src/utils/Mixin.js index fa001f5116..e89b40b838 100644 --- a/src/utils/Mixin.js +++ b/src/utils/Mixin.js @@ -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: { diff --git a/src/utils/i18n.js b/src/utils/i18n.js deleted file mode 100644 index b8eb8d9d18..0000000000 --- a/src/utils/i18n.js +++ /dev/null @@ -1,105 +0,0 @@ -/** - * External dependencies - */ -var i18n = {}; - -/** - * Creates a new Jed instance with specified locale data configuration. - * - * @see http://messageformat.github.io/Jed/ - * - * @param {Object} data Locale data configuration. - */ -export function setLocaleData( data ) { - var jed = new Jed( data ); - i18n[jed._textdomain] = jed; -} - -/** - * Returns the current Jed instance, initializing with a default configuration - * if not already assigned. - * - * @return {Jed} Jed instance. - */ -export function getI18n(domain = '') { - if ( ! i18n[domain] ) { - setLocaleData( { '': {} } ); - } - - return i18n[domain]; -} - -/** - * Retrieve the translation of text. - * - * @see https://developer.wordpress.org/reference/functions/__/ - * - * @param {string} text Text to translate. - * @param {string} domain Domain to retrieve the translated text. - * - * @return {string} Translated text. - */ -export function __( text, domain ) { - return getI18n(domain) ? getI18n(domain).dgettext( domain, text ) : text; -} - -/** - * Retrieve translated string with gettext context. - * - * @see https://developer.wordpress.org/reference/functions/_x/ - * - * @param {string} text Text to translate. - * @param {string} context Context information for the translators. - * @param {string} domain Domain to retrieve the translated text. - * - * @return {string} Translated context string without pipe. - */ -export function _x( text, context, domain ) { - return getI18n(domain).dpgettext( domain, context, text ); -} - -/** - * Translates and retrieves the singular or plural form based on the supplied - * number. - * - * @see https://developer.wordpress.org/reference/functions/_n/ - * - * @param {string} single The text to be used if the number is singular. - * @param {string} plural The text to be used if the number is plural. - * @param {number} number The number to compare against to use either the - * singular or plural form. - * @param {string} domain Domain to retrieve the translated text. - * - * @return {string} The translated singular or plural form. - */ -export function _n( single, plural, number, domain ) { - return getI18n(domain).dngettext( domain, single, plural, number ); -} - -/** - * Translates and retrieves the singular or plural form based on the supplied - * number, with gettext context. - * - * @see https://developer.wordpress.org/reference/functions/_nx/ - * - * @param {string} single The text to be used if the number is singular. - * @param {string} plural The text to be used if the number is plural. - * @param {number} number The number to compare against to use either the - * singular or plural form. - * @param {string} context Context information for the translators. - * @param {string} domain Domain to retrieve the translated text. - * - * @return {string} The translated singular or plural form. - */ -export function _nx( single, plural, number, context, domain ) { - return getI18n(domain).dnpgettext( domain, context, single, plural, number ); -} - -/** - * Returns a formatted string. - * - * @see http://www.diveintojavascript.com/projects/javascript-sprintf - * - * @type {string} - */ -export const sprintf = Jed.sprintf; \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index b4fcf9cd85..d0c8433caa 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -81,6 +81,7 @@ const updatedConfig = { }, plugins: [ + ...defaultConfig.plugins, new MiniCssExtractPlugin( { filename: ( { chunk } ) => {