settings->get(); if ( ! $screen || 'post' !== $screen->base || ! $settings->is_translatable_type( (string) $screen->post_type ) ) { return; } \AddBlack\Lang\Admin\AdminAssets::errors_script(); wp_register_script( 'blocklingo-translate', BLOCKLINGO_URL . 'assets/translate.js', array(), self::version( 'translate.js' ), true ); wp_enqueue_script( 'blocklingo-editor', BLOCKLINGO_URL . 'assets/editor.js', self::DEPENDENCIES, self::version( 'editor.js' ), true ); \AddBlack\Lang\Admin\AdminAssets::translations( 'blocklingo-editor' ); // Flags as CSS content: the emoji script replaces emoji in text it sees, not in ::before. wp_register_style( 'blocklingo-editor', false, array(), BLOCKLINGO_VERSION ); wp_enqueue_style( 'blocklingo-editor' ); wp_add_inline_style( 'blocklingo-editor', '.blocklingo-flagged[data-flag]:not([data-flag=""])::before{content:attr(data-flag) " ";}' ); wp_add_inline_script( 'blocklingo-editor', 'window.blocklingoEditor = ' . wp_json_encode( $this->data() ) . ';', 'before' ); } /** @return array */ public function data(): array { // Machine translation spends the site's API key: Authors and up (see the translate-strings route). $settings = $this->settings->get(); $provider = $settings->provider(); $providers = $this->defaults->providers(); $mt_on = $settings->machine_ready() && isset( $providers[ $provider ] ) && current_user_can( 'publish_posts' ); $languages = array(); foreach ( $settings->languages() as $code => $lang ) { $languages[] = array( 'code' => $code, 'name' => $lang->name, 'flag' => $lang->flag, ); } return array( 'languages' => $languages, 'default' => $settings->default_code(), 'postTypes' => $settings->post_types(), 'mt' => $mt_on ? $providers[ $provider ]['label'] : '', 'seo' => ! empty( $settings->get( 'seo', array() )['translate'] ), 'settings' => SettingsPage::url(), // Registered shortcode tags: kept out of machine translation. 'shortcodes' => \AddBlack\Lang\MachineTranslation\Shortcodes::tags(), 'skipBlocks' => \AddBlack\Lang\MachineTranslation\BlockTexts::untranslated_blocks(), ); } /** Cache-busting version: plugin version plus file time. */ private static function version( string $file ): string { return BLOCKLINGO_VERSION . '.' . (string) filemtime( BLOCKLINGO_DIR . 'assets/' . $file ); } }