__( "The changes you made will be lost if you navigate away from this page.", 'bogo' ), 'rest_api' => array( 'url' => trailingslashit( rest_url( 'bogo/v1' ) ), 'nonce' => wp_create_nonce( 'wp_rest' ) ) ); if ( 'nav-menus.php' == $hook_suffix ) { $nav_menu_id = absint( get_user_option( 'nav_menu_recently_edited' ) ); $nav_menu_items = wp_get_nav_menu_items( $nav_menu_id ); $locales = array(); foreach ( (array) $nav_menu_items as $item ) { $locales[$item->db_id] = $item->bogo_locales; } $local_args = array_merge( $local_args, array( 'availableLanguages' => bogo_available_languages( array( 'exclude_enus_if_inactive' => true, 'orderby' => 'value' ) ), 'locales' => $locales, 'selectorLegend' => __( 'Displayed on pages in', 'bogo' ), 'cbPrefix' => 'menu-item-bogo-locale' ) ); } if ( 'options-general.php' == $hook_suffix ) { $local_args = array_merge( $local_args, array( 'defaultLocale' => bogo_get_default_locale() ) ); } if ( 'post.php' == $hook_suffix && ! empty( $GLOBALS['post'] ) ) { $post = $GLOBALS['post']; $local_args = array_merge( $local_args, array( 'post_id' => $post->ID ) ); } $local_args['pagenow'] = isset( $_GET['page'] ) ? trim( $_GET['page'] ) : ''; wp_localize_script( 'bogo-admin', '_bogo', $local_args ); } add_action( 'admin_menu', 'bogo_admin_menu' ); function bogo_admin_menu() { add_menu_page( __( 'Languages', 'bogo' ), __( 'Languages', 'bogo' ), 'bogo_manage_language_packs', 'bogo', 'bogo_tools_page', 'dashicons-translation', 73 ); // between Users (70) and Tools (75) $tools = add_submenu_page( 'bogo', __( 'Language Packs', 'bogo' ), __( 'Language Packs', 'bogo' ), 'bogo_manage_language_packs', 'bogo', 'bogo_tools_page' ); add_action( 'load-' . $tools, 'bogo_load_tools_page' ); $texts = add_submenu_page( 'bogo', __( 'Terms Translation', 'bogo' ), __( 'Terms Translation', 'bogo' ), 'bogo_edit_terms_translation', 'bogo-texts', 'bogo_texts_page' ); add_action( 'load-' . $texts, 'bogo_load_texts_page' ); } function bogo_load_tools_page() { require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); $action = isset( $_GET['action'] ) ? $_GET['action'] : ''; if ( 'install_translation' == $action ) { check_admin_referer( 'bogo-tools' ); if ( ! current_user_can( 'bogo_manage_language_packs' ) ) { wp_die( __( "You are not allowed to install translations.", 'bogo' ) ); } $locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null; if ( wp_download_language_pack( $locale ) ) { $redirect_to = add_query_arg( array( 'locale' => $locale, 'message' => 'install_success' ), menu_page_url( 'bogo', false ) ); } else { $redirect_to = add_query_arg( array( 'locale' => $locale, 'message' => 'install_failed' ), menu_page_url( 'bogo', false ) ); } wp_safe_redirect( $redirect_to ); exit(); } if ( 'set_site_lang' == $action ) { check_admin_referer( 'bogo-tools' ); if ( ! current_user_can( 'bogo_manage_language_packs' ) ) { wp_die( __( "You are not allowed to manage translations.", 'bogo' ) ); } $locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null; if ( 'en_US' == $locale || ! bogo_is_available_locale( $locale ) ) { $locale = ''; } if ( update_option( 'WPLANG', $locale ) ) { $redirect_to = add_query_arg( array( 'locale' => $locale, 'message' => 'site_lang_success' ), menu_page_url( 'bogo', false ) ); } else { $redirect_to = add_query_arg( array( 'locale' => $locale, 'message' => 'site_lang_failed' ), menu_page_url( 'bogo', false ) ); } wp_safe_redirect( $redirect_to ); exit(); } if ( 'delete_translation' == $action ) { check_admin_referer( 'bogo-tools' ); if ( ! current_user_can( 'bogo_manage_language_packs' ) ) { wp_die( __( "You are not allowed to delete translations.", 'bogo' ) ); } $locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null; if ( bogo_delete_language_pack( $locale ) ) { $redirect_to = add_query_arg( array( 'locale' => $locale, 'message' => 'delete_success' ), menu_page_url( 'bogo', false ) ); } else { $redirect_to = add_query_arg( array( 'locale' => $locale, 'message' => 'delete_failed' ), menu_page_url( 'bogo', false ) ); } wp_safe_redirect( $redirect_to ); exit(); } if ( 'deactivate_enus' == $action ) { check_admin_referer( 'bogo-tools' ); bogo_set_prop( 'enus_deactivated', true ); $redirect_to = add_query_arg( array( 'message' => 'enus_deactivated' ), menu_page_url( 'bogo', false ) ); wp_safe_redirect( $redirect_to ); exit(); } if ( 'activate_enus' == $action ) { check_admin_referer( 'bogo-tools' ); bogo_set_prop( 'enus_deactivated', false ); $redirect_to = add_query_arg( array( 'message' => 'enus_activated' ), menu_page_url( 'bogo', false ) ); wp_safe_redirect( $redirect_to ); exit(); } } function bogo_load_texts_page() { $action = isset( $_POST['action'] ) ? $_POST['action'] : ''; if ( 'save' == $action ) { check_admin_referer( 'bogo-edit-text-translation' ); $locale = isset( $_POST['locale'] ) ? $_POST['locale'] : null; if ( ! current_user_can( 'bogo_edit_terms_translation' ) ) { wp_die( __( "You are not allowed to edit translations.", 'bogo' ) ); } $entries = array(); foreach ( $_POST as $p_key => $p_val ) { if ( in_array( $p_key, array( 'action', 'locale', 'submit' ) ) || substr( $p_key, 0, 1 ) == '_' ) { continue; } $entries[] = array( 'singular' => $p_key, 'translations' => array( $p_val ), 'context' => preg_replace( '/:.*$/', '', $p_key ) ); } if ( Bogo_POMO::export( $locale, $entries ) ) { $message = 'translation_saved'; } else { $message = 'translation_failed'; } $redirect_to = add_query_arg( array( 'locale' => $locale, 'message' => $message ), menu_page_url( 'bogo-texts', false ) ); wp_safe_redirect( $redirect_to ); exit(); } } function bogo_tools_page() { $enus_deactivated = bogo_is_enus_deactivated(); $can_install = wp_can_install_language_pack(); $default_locale = bogo_get_default_locale(); $available_locales = bogo_available_locales(); ?>

'activate_enus' ), $activate_link ); $activate_link = wp_nonce_url( $activate_link, 'bogo-tools' ); $activate_link = sprintf( '%2$s', $activate_link, esc_html( __( 'Activate', 'bogo' ) ), esc_attr( sprintf( __( 'Activate %s language pack', 'bogo' ), $language ) ) ); $row_actions = array( $activate_link ); $class = ''; } else { $sitelang_link = menu_page_url( 'bogo', false ); $sitelang_link = add_query_arg( array( 'action' => 'set_site_lang', 'locale' => $locale ), $sitelang_link ); $sitelang_link = wp_nonce_url( $sitelang_link, 'bogo-tools' ); $sitelang_link = sprintf( '%2$s', $sitelang_link, esc_html( __( 'Set as Site Language', 'bogo' ) ), esc_attr( sprintf( __( 'Set %s as Site Language', 'bogo' ), $language ) ) ); $deactivate_link = menu_page_url( 'bogo', false ); $deactivate_link = add_query_arg( array( 'action' => 'deactivate_enus' ), $deactivate_link ); $deactivate_link = wp_nonce_url( $deactivate_link, 'bogo-tools' ); $deactivate_link = sprintf( '%2$s', $deactivate_link, esc_html( __( 'Deactivate', 'bogo' ) ), esc_attr( sprintf( __( 'Deactivate %s language pack', 'bogo' ), $language ) ) ); $row_actions = array( $sitelang_link, $deactivate_link ); } } elseif ( $can_install ) { $sitelang_link = menu_page_url( 'bogo', false ); $sitelang_link = add_query_arg( array( 'action' => 'set_site_lang', 'locale' => $locale ), $sitelang_link ); $sitelang_link = wp_nonce_url( $sitelang_link, 'bogo-tools' ); $sitelang_link = sprintf( '%2$s', $sitelang_link, esc_html( __( 'Set as Site Language', 'bogo' ) ), esc_attr( sprintf( __( 'Set %s as Site Language', 'bogo' ), $language ) ) ); $delete_link = menu_page_url( 'bogo', false ); $delete_link = add_query_arg( array( 'action' => 'delete_translation', 'locale' => $locale ), $delete_link ); $delete_link = wp_nonce_url( $delete_link, 'bogo-tools' ); $delete_confirm = sprintf( __( "You are about to delete %s language pack.\n 'Cancel' to stop, 'OK' to delete.", 'bogo' ), $language ); $delete_link = sprintf( '%2$s', $delete_link, esc_html( __( 'Delete', 'bogo' ) ), esc_js( $delete_confirm ), esc_attr( sprintf( __( 'Delete %s language pack', 'bogo' ), $language ) ) ); $row_actions = array( $sitelang_link, $delete_link ); } ?> $translation ) { if ( in_array( $locale, $available_locales ) ) { continue; } $count += 1; $install_link = ''; if ( $can_install ) { $install_link = menu_page_url( 'bogo', false ); $install_link = add_query_arg( array( 'action' => 'install_translation', 'locale' => $locale ), $install_link ); $install_link = wp_nonce_url( $install_link, 'bogo-tools' ); $install_link = sprintf( '%2$s', $install_link, esc_html( __( 'Install', 'bogo' ) ), esc_attr( sprintf( __( 'Install %s language pack', 'bogo' ), bogo_get_language( $locale ) ) ) ); $row_actions = array( $install_link ); } ?>
[]
[]
[]

'blogname', 'original' => get_option( 'blogname' ), 'translated' => bogo_translate( 'blogname', 'blogname', get_option( 'blogname' ) ), 'context' => __( 'Site Title', 'bogo' ) ), array( 'name' => 'blogdescription', 'original' => get_option( 'blogdescription' ), 'translated' => bogo_translate( 'blogdescription', 'blogdescription', get_option( 'blogdescription' ) ), 'context' => __( 'Tagline', 'bogo' ) ) ); remove_filter( 'get_term', 'bogo_get_term_filter' ); foreach ( (array) get_taxonomies( array(), 'objects' ) as $taxonomy ) { $tax_labels = get_taxonomy_labels( $taxonomy ); $terms = get_terms( array( 'taxonomy' => $taxonomy->name, 'orderby' => 'slug', 'hide_empty' => false ) ); foreach ( (array) $terms as $term ) { $name = sprintf( '%s:%d', $taxonomy->name, $term->term_id ); $strings[] = array( 'name' => $name, 'original' => $term->name, 'translated' => bogo_translate( $name, $taxonomy->name, $term->name ), 'context' => $tax_labels->name ); } } ?>

%s

', esc_html( $message ) ); } else { echo sprintf( '

%s

', esc_html( $message ) ); } } function bogo_delete_language_pack( $locale ) { if ( 'en_US' == $locale || ! bogo_is_available_locale( $locale ) || bogo_is_default_locale( $locale ) ) { return false; } if ( ! is_dir( WP_LANG_DIR ) || ! $files = scandir( WP_LANG_DIR ) ) { return false; } $target_files = array( sprintf( '%s.mo', $locale ), sprintf( '%s.po', $locale ), sprintf( 'admin-%s.mo', $locale ), sprintf( 'admin-%s.po', $locale ), sprintf( 'admin-network-%s.mo', $locale ), sprintf( 'admin-network-%s.po', $locale ), sprintf( 'continents-cities-%s.mo', $locale ), sprintf( 'continents-cities-%s.po', $locale ) ); foreach ( $files as $file ) { if ( '.' === $file[0] || is_dir( $file ) ) { continue; } if ( in_array( $file, $target_files ) ) { $result = @unlink( path_join( WP_LANG_DIR, $file ) ); if ( ! $result ) { return false; } } } return true; }