| 1 |
<?php |
| 2 |
|
| 3 |
require_once BOGO_PLUGIN_DIR . '/admin/includes/user.php'; |
| 4 |
require_once BOGO_PLUGIN_DIR . '/admin/includes/post.php'; |
| 5 |
require_once BOGO_PLUGIN_DIR . '/admin/includes/nav-menu.php'; |
| 6 |
require_once BOGO_PLUGIN_DIR . '/admin/includes/widgets.php'; |
| 7 |
|
| 8 |
add_action( 'admin_init', 'bogo_upgrade' ); |
| 9 |
|
| 10 |
function bogo_upgrade() { |
| 11 |
$old_ver = bogo_get_prop( 'version' ); |
| 12 |
$new_ver = BOGO_VERSION; |
| 13 |
|
| 14 |
if ( $old_ver != $new_ver ) { |
| 15 |
require_once BOGO_PLUGIN_DIR . '/admin/includes/upgrade.php'; |
| 16 |
do_action( 'bogo_upgrade', $new_ver, $old_ver ); |
| 17 |
bogo_set_prop( 'version', $new_ver ); |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
add_action( 'admin_enqueue_scripts', 'bogo_admin_enqueue_scripts' ); |
| 22 |
|
| 23 |
function bogo_admin_enqueue_scripts( $hook_suffix ) { |
| 24 |
wp_enqueue_style( 'bogo-admin', |
| 25 |
plugins_url( 'admin/includes/css/admin.css', BOGO_PLUGIN_BASENAME ), |
| 26 |
array(), BOGO_VERSION, 'all' ); |
| 27 |
|
| 28 |
if ( is_rtl() ) { |
| 29 |
wp_enqueue_style( 'bogo-admin-rtl', |
| 30 |
plugins_url( 'admin/includes/css/admin-rtl.css', BOGO_PLUGIN_BASENAME ), |
| 31 |
array(), BOGO_VERSION, 'all' ); |
| 32 |
} |
| 33 |
|
| 34 |
wp_enqueue_script( 'bogo-admin', |
| 35 |
plugins_url( 'admin/includes/js/admin.js', BOGO_PLUGIN_BASENAME ), |
| 36 |
array( 'jquery' ), BOGO_VERSION, true ); |
| 37 |
|
| 38 |
$local_args = array( |
| 39 |
'saveAlert' => __( |
| 40 |
"The changes you made will be lost if you navigate away from this page.", |
| 41 |
'bogo' ), |
| 42 |
'rest_api' => array( |
| 43 |
'url' => trailingslashit( rest_url( 'bogo/v1' ) ), |
| 44 |
'nonce' => wp_create_nonce( 'wp_rest' ) ) ); |
| 45 |
|
| 46 |
if ( 'nav-menus.php' == $hook_suffix ) { |
| 47 |
$nav_menu_id = absint( get_user_option( 'nav_menu_recently_edited' ) ); |
| 48 |
$nav_menu_items = wp_get_nav_menu_items( $nav_menu_id ); |
| 49 |
$locales = array(); |
| 50 |
|
| 51 |
foreach ( (array) $nav_menu_items as $item ) { |
| 52 |
$locales[$item->db_id] = $item->bogo_locales; |
| 53 |
} |
| 54 |
|
| 55 |
$local_args = array_merge( $local_args, array( |
| 56 |
'availableLanguages' => bogo_available_languages( array( |
| 57 |
'exclude_enus_if_inactive' => true, |
| 58 |
'orderby' => 'value' ) ), |
| 59 |
'locales' => $locales, |
| 60 |
'selectorLegend' => __( 'Displayed on pages in', 'bogo' ), |
| 61 |
'cbPrefix' => 'menu-item-bogo-locale' ) ); |
| 62 |
} |
| 63 |
|
| 64 |
if ( 'options-general.php' == $hook_suffix ) { |
| 65 |
$local_args = array_merge( $local_args, array( |
| 66 |
'defaultLocale' => bogo_get_default_locale() ) ); |
| 67 |
} |
| 68 |
|
| 69 |
if ( 'post.php' == $hook_suffix && ! empty( $GLOBALS['post'] ) ) { |
| 70 |
$post = $GLOBALS['post']; |
| 71 |
$local_args = array_merge( $local_args, array( |
| 72 |
'post_id' => $post->ID ) ); |
| 73 |
} |
| 74 |
|
| 75 |
wp_localize_script( 'bogo-admin', '_bogo', $local_args ); |
| 76 |
} |
| 77 |
|
| 78 |
add_action( 'admin_menu', 'bogo_admin_menu' ); |
| 79 |
|
| 80 |
function bogo_admin_menu() { |
| 81 |
add_menu_page( __( 'Languages', 'bogo' ), __( 'Languages', 'bogo' ), |
| 82 |
'bogo_manage_language_packs', 'bogo', 'bogo_tools_page', |
| 83 |
'dashicons-translation', 73 ); // between Users (70) and Tools (75) |
| 84 |
|
| 85 |
$tools = add_submenu_page( 'bogo', |
| 86 |
__( 'Language Packs', 'bogo' ), |
| 87 |
__( 'Language Packs', 'bogo' ), |
| 88 |
'bogo_manage_language_packs', 'bogo', 'bogo_tools_page' ); |
| 89 |
|
| 90 |
add_action( 'load-' . $tools, 'bogo_load_tools_page' ); |
| 91 |
|
| 92 |
$texts = add_submenu_page( 'bogo', |
| 93 |
__( 'Terms Translation', 'bogo' ), |
| 94 |
__( 'Terms Translation', 'bogo' ), |
| 95 |
'bogo_edit_terms_translation', 'bogo-texts', 'bogo_texts_page' ); |
| 96 |
|
| 97 |
add_action( 'load-' . $texts, 'bogo_load_texts_page' ); |
| 98 |
} |
| 99 |
|
| 100 |
function bogo_load_tools_page() { |
| 101 |
require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); |
| 102 |
|
| 103 |
$action = isset( $_GET['action'] ) ? $_GET['action'] : ''; |
| 104 |
|
| 105 |
if ( 'install_translation' == $action ) { |
| 106 |
check_admin_referer( 'bogo-tools' ); |
| 107 |
|
| 108 |
if ( ! current_user_can( 'bogo_manage_language_packs' ) ) { |
| 109 |
wp_die( __( "You are not allowed to install translations.", 'bogo' ) ); |
| 110 |
} |
| 111 |
|
| 112 |
$locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null; |
| 113 |
|
| 114 |
if ( wp_download_language_pack( $locale ) ) { |
| 115 |
$redirect_to = add_query_arg( |
| 116 |
array( 'locale' => $locale, 'message' => 'install_success' ), |
| 117 |
menu_page_url( 'bogo', false ) ); |
| 118 |
} else { |
| 119 |
$redirect_to = add_query_arg( |
| 120 |
array( 'locale' => $locale, 'message' => 'install_failed' ), |
| 121 |
menu_page_url( 'bogo', false ) ); |
| 122 |
} |
| 123 |
|
| 124 |
wp_safe_redirect( $redirect_to ); |
| 125 |
exit(); |
| 126 |
} |
| 127 |
|
| 128 |
if ( 'set_site_lang' == $action ) { |
| 129 |
check_admin_referer( 'bogo-tools' ); |
| 130 |
|
| 131 |
if ( ! current_user_can( 'bogo_manage_language_packs' ) ) { |
| 132 |
wp_die( __( "You are not allowed to manage translations.", 'bogo' ) ); |
| 133 |
} |
| 134 |
|
| 135 |
$locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null; |
| 136 |
|
| 137 |
if ( 'en_US' == $locale || ! bogo_is_available_locale( $locale ) ) { |
| 138 |
$locale = ''; |
| 139 |
} |
| 140 |
|
| 141 |
if ( update_option( 'WPLANG', $locale ) ) { |
| 142 |
$redirect_to = add_query_arg( |
| 143 |
array( 'locale' => $locale, 'message' => 'site_lang_success' ), |
| 144 |
menu_page_url( 'bogo', false ) ); |
| 145 |
} else { |
| 146 |
$redirect_to = add_query_arg( |
| 147 |
array( 'locale' => $locale, 'message' => 'site_lang_failed' ), |
| 148 |
menu_page_url( 'bogo', false ) ); |
| 149 |
} |
| 150 |
|
| 151 |
wp_safe_redirect( $redirect_to ); |
| 152 |
exit(); |
| 153 |
} |
| 154 |
|
| 155 |
if ( 'delete_translation' == $action ) { |
| 156 |
check_admin_referer( 'bogo-tools' ); |
| 157 |
|
| 158 |
if ( ! current_user_can( 'bogo_manage_language_packs' ) ) { |
| 159 |
wp_die( __( "You are not allowed to delete translations.", 'bogo' ) ); |
| 160 |
} |
| 161 |
|
| 162 |
$locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null; |
| 163 |
|
| 164 |
if ( bogo_delete_language_pack( $locale ) ) { |
| 165 |
$redirect_to = add_query_arg( |
| 166 |
array( 'locale' => $locale, 'message' => 'delete_success' ), |
| 167 |
menu_page_url( 'bogo', false ) ); |
| 168 |
} else { |
| 169 |
$redirect_to = add_query_arg( |
| 170 |
array( 'locale' => $locale, 'message' => 'delete_failed' ), |
| 171 |
menu_page_url( 'bogo', false ) ); |
| 172 |
} |
| 173 |
|
| 174 |
wp_safe_redirect( $redirect_to ); |
| 175 |
exit(); |
| 176 |
} |
| 177 |
|
| 178 |
if ( 'deactivate_enus' == $action ) { |
| 179 |
check_admin_referer( 'bogo-tools' ); |
| 180 |
|
| 181 |
bogo_set_prop( 'enus_deactivated', true ); |
| 182 |
|
| 183 |
$redirect_to = add_query_arg( |
| 184 |
array( 'message' => 'enus_deactivated' ), |
| 185 |
menu_page_url( 'bogo', false ) ); |
| 186 |
|
| 187 |
wp_safe_redirect( $redirect_to ); |
| 188 |
exit(); |
| 189 |
} |
| 190 |
|
| 191 |
if ( 'activate_enus' == $action ) { |
| 192 |
check_admin_referer( 'bogo-tools' ); |
| 193 |
|
| 194 |
bogo_set_prop( 'enus_deactivated', false ); |
| 195 |
|
| 196 |
$redirect_to = add_query_arg( |
| 197 |
array( 'message' => 'enus_activated' ), |
| 198 |
menu_page_url( 'bogo', false ) ); |
| 199 |
|
| 200 |
wp_safe_redirect( $redirect_to ); |
| 201 |
exit(); |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
function bogo_load_texts_page() { |
| 206 |
$action = isset( $_POST['action'] ) ? $_POST['action'] : ''; |
| 207 |
|
| 208 |
if ( 'save' == $action ) { |
| 209 |
check_admin_referer( 'bogo-edit-text-translation' ); |
| 210 |
|
| 211 |
$locale = isset( $_POST['locale'] ) ? $_POST['locale'] : null; |
| 212 |
|
| 213 |
if ( ! current_user_can( 'bogo_edit_terms_translation' ) ) { |
| 214 |
wp_die( __( "You are not allowed to edit translations.", 'bogo' ) ); |
| 215 |
} |
| 216 |
|
| 217 |
$entries = array(); |
| 218 |
|
| 219 |
foreach ( $_POST as $p_key => $p_val ) { |
| 220 |
if ( in_array( $p_key, array( 'action', 'locale', 'submit' ) ) |
| 221 |
|| substr( $p_key, 0, 1 ) == '_' ) { |
| 222 |
continue; |
| 223 |
} |
| 224 |
|
| 225 |
$entries[] = array( |
| 226 |
'singular' => $p_key, |
| 227 |
'translations' => array( $p_val ), |
| 228 |
'context' => preg_replace( '/:.*$/', '', $p_key ) ); |
| 229 |
} |
| 230 |
|
| 231 |
if ( Bogo_POMO::export( $locale, $entries ) ) { |
| 232 |
$message = 'translation_saved'; |
| 233 |
} else { |
| 234 |
$message = 'translation_failed'; |
| 235 |
} |
| 236 |
|
| 237 |
$redirect_to = add_query_arg( |
| 238 |
array( 'locale' => $locale, 'message' => $message ), |
| 239 |
menu_page_url( 'bogo-texts', false ) ); |
| 240 |
|
| 241 |
wp_safe_redirect( $redirect_to ); |
| 242 |
exit(); |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
function bogo_tools_page() { |
| 247 |
$enus_deactivated = bogo_is_enus_deactivated(); |
| 248 |
$can_install = wp_can_install_language_pack(); |
| 249 |
|
| 250 |
$default_locale = bogo_get_default_locale(); |
| 251 |
$available_locales = bogo_available_locales(); |
| 252 |
|
| 253 |
?> |
| 254 |
<div class="wrap"> |
| 255 |
|
| 256 |
<h1><?php echo esc_html( __( 'Language Packs', 'bogo' ) ); ?></h1> |
| 257 |
|
| 258 |
<?php bogo_admin_notice(); ?> |
| 259 |
|
| 260 |
<table id="bogo-languages-table" class="widefat"> |
| 261 |
<thead> |
| 262 |
<tr><th><?php echo esc_html( __( 'Language', 'bogo' ) ); ?></th></tr> |
| 263 |
</thead> |
| 264 |
<tfoot> |
| 265 |
<tr><th><?php echo esc_html( __( 'Language', 'bogo' ) ); ?></th></tr> |
| 266 |
</tfoot> |
| 267 |
<tbody id="translations"> |
| 268 |
<tr class="active" id="language-1"><td> |
| 269 |
<strong><?php echo esc_html( bogo_get_language( $default_locale ) ); ?></strong> |
| 270 |
[<?php echo esc_html( $default_locale ); ?>] |
| 271 |
<div class="status"><?php echo esc_html( __( 'Site Language', 'bogo' ) ); ?></div> |
| 272 |
</td></tr> |
| 273 |
|
| 274 |
<?php |
| 275 |
$count = 1; |
| 276 |
|
| 277 |
foreach ( $available_locales as $locale ) { |
| 278 |
if ( $locale == $default_locale ) { |
| 279 |
continue; |
| 280 |
} |
| 281 |
|
| 282 |
$count += 1; |
| 283 |
$class = 'active'; |
| 284 |
|
| 285 |
if ( ! $language = bogo_get_language( $locale ) ) { |
| 286 |
$language = $locale; |
| 287 |
} |
| 288 |
|
| 289 |
if ( 'en_US' == $locale ) { |
| 290 |
$status = $enus_deactivated |
| 291 |
? __( 'Inactive', 'bogo' ) : __( 'Active', 'bogo' ); |
| 292 |
} else { |
| 293 |
$status = __( 'Installed', 'bogo' ); |
| 294 |
} |
| 295 |
|
| 296 |
if ( 'en_US' == $locale ) { |
| 297 |
if ( $enus_deactivated ) { |
| 298 |
$activate_link = menu_page_url( 'bogo', false ); |
| 299 |
$activate_link = add_query_arg( |
| 300 |
array( 'action' => 'activate_enus' ), |
| 301 |
$activate_link ); |
| 302 |
$activate_link = wp_nonce_url( $activate_link, 'bogo-tools' ); |
| 303 |
$activate_link = sprintf( |
| 304 |
'<a href="%1$s" class="activate" aria-label="%3$s">%2$s</a>', |
| 305 |
$activate_link, |
| 306 |
esc_html( __( 'Activate', 'bogo' ) ), |
| 307 |
esc_attr( |
| 308 |
sprintf( __( 'Activate %s language pack', 'bogo' ), $language ) ) ); |
| 309 |
|
| 310 |
$row_actions = array( $activate_link ); |
| 311 |
|
| 312 |
$class = ''; |
| 313 |
} else { |
| 314 |
$sitelang_link = menu_page_url( 'bogo', false ); |
| 315 |
$sitelang_link = add_query_arg( |
| 316 |
array( 'action' => 'set_site_lang', 'locale' => $locale ), |
| 317 |
$sitelang_link ); |
| 318 |
$sitelang_link = wp_nonce_url( $sitelang_link, 'bogo-tools' ); |
| 319 |
$sitelang_link = sprintf( |
| 320 |
'<a href="%1$s" class="sitelang" aria-label="%3$s">%2$s</a>', |
| 321 |
$sitelang_link, |
| 322 |
esc_html( __( 'Set as Site Language', 'bogo' ) ), |
| 323 |
esc_attr( |
| 324 |
sprintf( __( 'Set %s as Site Language', 'bogo' ), $language ) ) ); |
| 325 |
|
| 326 |
$deactivate_link = menu_page_url( 'bogo', false ); |
| 327 |
$deactivate_link = add_query_arg( |
| 328 |
array( 'action' => 'deactivate_enus' ), |
| 329 |
$deactivate_link ); |
| 330 |
$deactivate_link = wp_nonce_url( $deactivate_link, 'bogo-tools' ); |
| 331 |
$deactivate_link = sprintf( |
| 332 |
'<a href="%1$s" class="deactivate" aria-label="%3$s">%2$s</a>', |
| 333 |
$deactivate_link, |
| 334 |
esc_html( __( 'Deactivate', 'bogo' ) ), |
| 335 |
esc_attr( sprintf( |
| 336 |
__( 'Deactivate %s language pack', 'bogo' ), $language ) ) ); |
| 337 |
|
| 338 |
$row_actions = array( $sitelang_link, $deactivate_link ); |
| 339 |
} |
| 340 |
} elseif ( $can_install ) { |
| 341 |
$sitelang_link = menu_page_url( 'bogo', false ); |
| 342 |
$sitelang_link = add_query_arg( |
| 343 |
array( 'action' => 'set_site_lang', 'locale' => $locale ), |
| 344 |
$sitelang_link ); |
| 345 |
$sitelang_link = wp_nonce_url( $sitelang_link, 'bogo-tools' ); |
| 346 |
$sitelang_link = sprintf( |
| 347 |
'<a href="%1$s" class="sitelang" aria-label="%3$s">%2$s</a>', |
| 348 |
$sitelang_link, |
| 349 |
esc_html( __( 'Set as Site Language', 'bogo' ) ), |
| 350 |
esc_attr( |
| 351 |
sprintf( __( 'Set %s as Site Language', 'bogo' ), $language ) ) ); |
| 352 |
|
| 353 |
$delete_link = menu_page_url( 'bogo', false ); |
| 354 |
$delete_link = add_query_arg( |
| 355 |
array( 'action' => 'delete_translation', 'locale' => $locale ), |
| 356 |
$delete_link ); |
| 357 |
$delete_link = wp_nonce_url( $delete_link, 'bogo-tools' ); |
| 358 |
|
| 359 |
$delete_confirm = sprintf( __( "You are about to delete %s language pack.\n 'Cancel' to stop, 'OK' to delete.", 'bogo' ), $language ); |
| 360 |
|
| 361 |
$delete_link = sprintf( '<a href="%1$s" class="delete" onclick="if (confirm(\'%3$s\')){return true;} return false;" aria-label="%4$s">%2$s</a>', |
| 362 |
$delete_link, |
| 363 |
esc_html( __( 'Delete', 'bogo' ) ), |
| 364 |
esc_js( $delete_confirm ), |
| 365 |
esc_attr( |
| 366 |
sprintf( __( 'Delete %s language pack', 'bogo' ), $language ) ) ); |
| 367 |
|
| 368 |
$row_actions = array( $sitelang_link, $delete_link ); |
| 369 |
} |
| 370 |
?> |
| 371 |
<tr class="<?php echo esc_attr( $class ); ?>" id="language-<?php echo absint( $count ); ?>"> |
| 372 |
<td> |
| 373 |
<strong><?php echo esc_html( bogo_get_language( $locale ) ); ?></strong> |
| 374 |
[<?php echo esc_html( $locale ); ?>] |
| 375 |
<div class="status"><?php echo esc_html( $status ); ?></div> |
| 376 |
<div class="row-actions"><?php echo implode( ' | ', $row_actions ); ?></div> |
| 377 |
</td> |
| 378 |
</tr> |
| 379 |
<?php |
| 380 |
} |
| 381 |
|
| 382 |
foreach ( wp_get_available_translations() as $locale => $translation ) { |
| 383 |
if ( in_array( $locale, $available_locales ) ) { |
| 384 |
continue; |
| 385 |
} |
| 386 |
|
| 387 |
$count += 1; |
| 388 |
|
| 389 |
$install_link = ''; |
| 390 |
|
| 391 |
if ( $can_install ) { |
| 392 |
$install_link = menu_page_url( 'bogo', false ); |
| 393 |
$install_link = add_query_arg( |
| 394 |
array( 'action' => 'install_translation', 'locale' => $locale ), |
| 395 |
$install_link ); |
| 396 |
$install_link = wp_nonce_url( $install_link, 'bogo-tools' ); |
| 397 |
$install_link = sprintf( '<a href="%1$s" class="install" aria-label="%3$s">%2$s</a>', |
| 398 |
$install_link, |
| 399 |
esc_html( __( 'Install', 'bogo' ) ), |
| 400 |
esc_attr( |
| 401 |
sprintf( __( 'Install %s language pack', 'bogo' ), |
| 402 |
bogo_get_language( $locale ) ) ) ); |
| 403 |
|
| 404 |
$row_actions = array( $install_link ); |
| 405 |
} |
| 406 |
?> |
| 407 |
<tr id="language-<?php echo absint( $count ); ?>"><td> |
| 408 |
<strong><?php echo esc_html( bogo_get_language( $locale ) ); ?></strong> |
| 409 |
[<?php echo esc_html( $locale ); ?>] |
| 410 |
<div class="row-actions"><?php echo implode( ' | ', $row_actions ); ?></div> |
| 411 |
</td></tr> |
| 412 |
<?php |
| 413 |
} |
| 414 |
?> |
| 415 |
|
| 416 |
</tbody> |
| 417 |
</table> |
| 418 |
|
| 419 |
</div> |
| 420 |
<?php |
| 421 |
} |
| 422 |
|
| 423 |
function bogo_texts_page() { |
| 424 |
$locale_to_edit = isset( $_GET['locale'] ) ? $_GET['locale'] : ''; |
| 425 |
|
| 426 |
if ( ! Bogo_POMO::import( $locale_to_edit ) ) { |
| 427 |
Bogo_POMO::reset(); |
| 428 |
} |
| 429 |
|
| 430 |
?> |
| 431 |
<div class="wrap"> |
| 432 |
|
| 433 |
<h1><?php echo esc_html( __( 'Terms Translation', 'bogo' ) ); ?></h1> |
| 434 |
|
| 435 |
<?php bogo_admin_notice(); ?> |
| 436 |
|
| 437 |
<form action="" method="post" id="bogo-translatable-text-strings"> |
| 438 |
<input type="hidden" name="action" value="save" /> |
| 439 |
<?php wp_nonce_field( 'bogo-edit-text-translation' ); ?> |
| 440 |
|
| 441 |
<p> |
| 442 |
<select name="locale" id="select-locale"> |
| 443 |
<option value=""><?php echo esc_html( __( '-- Select Language to Edit --', 'bogo' ) ); ?></option> |
| 444 |
<?php |
| 445 |
$available_locales = bogo_available_locales( |
| 446 |
array( 'current_user_can_access' => true ) ); |
| 447 |
|
| 448 |
foreach ( $available_locales as $locale ) { |
| 449 |
echo sprintf( '<option value="%1$s"%3$s>%2$s</option>', |
| 450 |
esc_attr( $locale ), |
| 451 |
esc_html( bogo_get_language( $locale ) ), |
| 452 |
$locale == $locale_to_edit ? ' selected="selected"' : '' ); |
| 453 |
} |
| 454 |
?> |
| 455 |
</select> |
| 456 |
</p> |
| 457 |
|
| 458 |
<?php |
| 459 |
if ( bogo_is_available_locale( $locale_to_edit ) ) : |
| 460 |
$strings = array( |
| 461 |
array( |
| 462 |
'name' => 'blogname', |
| 463 |
'original' => get_option( 'blogname' ), |
| 464 |
'translated' => bogo_translate( 'blogname', |
| 465 |
'blogname', get_option( 'blogname' ) ), |
| 466 |
'context' => __( 'Site Title', 'bogo' ) ), |
| 467 |
array( |
| 468 |
'name' => 'blogdescription', |
| 469 |
'original' => get_option( 'blogdescription' ), |
| 470 |
'translated' => bogo_translate( 'blogdescription', |
| 471 |
'blogdescription', get_option( 'blogdescription' ) ), |
| 472 |
'context' => __( 'Tagline', 'bogo' ) ) ); |
| 473 |
|
| 474 |
remove_filter( 'get_term', 'bogo_get_term_filter' ); |
| 475 |
|
| 476 |
foreach ( (array) get_taxonomies( array(), 'objects' ) as $taxonomy ) { |
| 477 |
$tax_labels = get_taxonomy_labels( $taxonomy ); |
| 478 |
$terms = get_terms( array( |
| 479 |
'taxonomy' => $taxonomy->name, |
| 480 |
'orderby' => 'slug', |
| 481 |
'hide_empty' => false ) ); |
| 482 |
|
| 483 |
foreach ( (array) $terms as $term ) { |
| 484 |
$name = sprintf( '%s:%d', $taxonomy->name, $term->term_id ); |
| 485 |
$strings[] = array( |
| 486 |
'name' => $name, |
| 487 |
'original' => $term->name, |
| 488 |
'translated' => bogo_translate( $name, |
| 489 |
$taxonomy->name, $term->name ), |
| 490 |
'context' => $tax_labels->name ); |
| 491 |
} |
| 492 |
} |
| 493 |
?> |
| 494 |
<table class="wp-list-table widefat fixed striped" id="bogo-translation-table"> |
| 495 |
<thead> |
| 496 |
<tr> |
| 497 |
<th scope="col"><?php echo esc_html( __( 'Original', 'bogo' ) ); ?></th> |
| 498 |
<th scope="col"><?php echo esc_html( __( 'Translation', 'bogo' ) ); ?></th> |
| 499 |
<th scope="col" style="width: 20%;"><?php echo esc_html( __( 'Context', 'bogo' ) ); ?></th> |
| 500 |
</tr> |
| 501 |
</thead> |
| 502 |
<tfoot> |
| 503 |
<tr> |
| 504 |
<th scope="col"><?php echo esc_html( __( 'Original', 'bogo' ) ); ?></th> |
| 505 |
<th scope="col"><?php echo esc_html( __( 'Translation', 'bogo' ) ); ?></th> |
| 506 |
<th scope="col"><?php echo esc_html( __( 'Context', 'bogo' ) ); ?></th> |
| 507 |
</tr> |
| 508 |
</tfoot> |
| 509 |
<tbody> |
| 510 |
<?php |
| 511 |
foreach( $strings as $string ) : |
| 512 |
?> |
| 513 |
<tr> |
| 514 |
<td><?php echo esc_html( $string['original'] ); ?></td> |
| 515 |
<td><input name="<?php echo esc_attr( $string['name'] ); ?>" type="text" id="<?php echo esc_attr( $string['name'] ); ?>" value="<?php echo esc_attr( $string['translated'] ); ?>" class="large-text" /></td> |
| 516 |
<td><?php echo esc_html( $string['context'] ); ?></td> |
| 517 |
</tr> |
| 518 |
<?php |
| 519 |
endforeach; |
| 520 |
?> |
| 521 |
</tbody> |
| 522 |
</table> |
| 523 |
|
| 524 |
<?php submit_button(); ?> |
| 525 |
<?php |
| 526 |
endif; |
| 527 |
?> |
| 528 |
</form> |
| 529 |
</div> |
| 530 |
<?php |
| 531 |
} |
| 532 |
|
| 533 |
function bogo_admin_notice( $reason = '' ) { |
| 534 |
if ( empty( $reason ) && isset( $_GET['message'] ) ) { |
| 535 |
$reason = $_GET['message']; |
| 536 |
} |
| 537 |
|
| 538 |
if ( 'install_success' == $reason ) { |
| 539 |
$message = __( "Translation installed successfully.", 'bogo' ); |
| 540 |
} elseif ( 'install_failed' == $reason ) { |
| 541 |
$message = __( "Translation install failed.", 'bogo' ); |
| 542 |
} elseif ( 'site_lang_success' == $reason ) { |
| 543 |
$message = __( "Site language set successfully.", 'bogo' ); |
| 544 |
} elseif ( 'site_lang_failed' == $reason ) { |
| 545 |
$message = __( "Setting site language failed.", 'bogo' ); |
| 546 |
} elseif ( 'delete_success' == $reason ) { |
| 547 |
$message = __( "Translation uninstalled successfully.", 'bogo' ); |
| 548 |
} elseif ( 'delete_failed' == $reason ) { |
| 549 |
$message = __( "Translation uninstall failed.", 'bogo' ); |
| 550 |
} elseif ( 'enus_deactivated' == $reason ) { |
| 551 |
$message = __( "English (United States) deactivated.", 'bogo' ); |
| 552 |
} elseif ( 'enus_activated' == $reason ) { |
| 553 |
$message = __( "English (United States) activated.", 'bogo' ); |
| 554 |
} elseif ( 'translation_saved' == $reason ) { |
| 555 |
$message = __( "Translation saved.", 'bogo' ); |
| 556 |
} elseif ( 'translation_failed' == $reason ) { |
| 557 |
$message = __( "Saving translation failed.", 'bogo' ); |
| 558 |
} else { |
| 559 |
return false; |
| 560 |
} |
| 561 |
|
| 562 |
if ( '_failed' == substr( $reason, -7 ) ) { |
| 563 |
echo sprintf( |
| 564 |
'<div class="error notice notice-error is-dismissible"><p>%s</p></div>', |
| 565 |
esc_html( $message ) ); |
| 566 |
} else { |
| 567 |
echo sprintf( |
| 568 |
'<div class="updated notice notice-success is-dismissible"><p>%s</p></div>', |
| 569 |
esc_html( $message ) ); |
| 570 |
} |
| 571 |
} |
| 572 |
|
| 573 |
function bogo_delete_language_pack( $locale ) { |
| 574 |
if ( 'en_US' == $locale |
| 575 |
|| ! bogo_is_available_locale( $locale ) |
| 576 |
|| bogo_is_default_locale( $locale ) ) { |
| 577 |
return false; |
| 578 |
} |
| 579 |
|
| 580 |
if ( ! is_dir( WP_LANG_DIR ) || ! $files = scandir( WP_LANG_DIR ) ) { |
| 581 |
return false; |
| 582 |
} |
| 583 |
|
| 584 |
$target_files = array( |
| 585 |
sprintf( '%s.mo', $locale ), |
| 586 |
sprintf( '%s.po', $locale ), |
| 587 |
sprintf( 'admin-%s.mo', $locale ), |
| 588 |
sprintf( 'admin-%s.po', $locale ), |
| 589 |
sprintf( 'admin-network-%s.mo', $locale ), |
| 590 |
sprintf( 'admin-network-%s.po', $locale ), |
| 591 |
sprintf( 'continents-cities-%s.mo', $locale ), |
| 592 |
sprintf( 'continents-cities-%s.po', $locale ) ); |
| 593 |
|
| 594 |
foreach ( $files as $file ) { |
| 595 |
if ( '.' === $file[0] || is_dir( $file ) ) { |
| 596 |
continue; |
| 597 |
} |
| 598 |
|
| 599 |
if ( in_array( $file, $target_files ) ) { |
| 600 |
$result = @unlink( path_join( WP_LANG_DIR, $file ) ); |
| 601 |
|
| 602 |
if ( ! $result ) { |
| 603 |
return false; |
| 604 |
} |
| 605 |
} |
| 606 |
} |
| 607 |
|
| 608 |
return true; |
| 609 |
} |
| 610 |
|