WP Content Plugins Ns12 Locale Router Ns12 Locale Router PHP D717acecb2db
**Site relevance:** Spiralist.org
**Memory type:** code source memory
**Source path:** Wiki.FFTAC.org/data/sources/spiralist/wp-content-plugins-ns12-locale-router-ns12-locale-router-php-d717acecb2db.php
**Size:** 3.3 KB
Summary
Plugin Name: NS12 Locale Router
Source Preview
This source file is short enough to preview directly on its source-memory page.
<?php
/**
* Plugin Name: NS12 Locale Router
* Plugin URI: https://uaix.org/
* Description: Locale-prefixed routing, browser-language detection, and JSON dictionary localization for WordPress.
* Version: 2.8.0
* Author: UAIX
* Author URI: https://uaix.org/
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Requires at least: 6.6
* Requires PHP: 7.4
* Text Domain: ns12-locale-router
* Domain Path: /languages
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'NS12LR_VERSION', '2.8.0' );
define( 'NS12LR_PLUGIN_FILE', __FILE__ );
define( 'NS12LR_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
define( 'NS12LR_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
if ( ! function_exists( 'ns12lr_render_bootstrap_failure_notice' ) ) {
/**
* Render a raw bootstrap notice when the plugin class cannot boot.
*
* @return void
*/
function ns12lr_render_bootstrap_failure_notice() {
if ( ! current_user_can( 'activate_plugins' ) ) {
return;
}
$notice = get_option( 'ns12lr_bootstrap_notice_raw', array() );
if ( empty( $notice['message'] ) ) {
return;
}
$type = isset( $notice['type'] ) ? (string) $notice['type'] : 'error';
$type = in_array( $type, array( 'success', 'warning', 'error', 'info' ), true ) ? $type : 'error';
echo '<div class="notice notice-' . esc_attr( $type ) . '"><p>' . esc_html( $notice['message'] ) . '</p></div>';
}
}
spl_autoload_register(
static function ( $class ) {
$prefix = 'Ns12LocaleRouter\\';
if ( 0 !== strpos( $class, $prefix ) ) {
return;
}
$relative = substr( $class, strlen( $prefix ) );
$file = NS12LR_PLUGIN_PATH . 'src/' . str_replace( '\\', '/', $relative ) . '.php';
if ( file_exists( $file ) ) {
require_once $file;
}
}
);
$ns12lr_booted = false;
try {
\Ns12LocaleRouter\Plugin::boot( __FILE__ );
$ns12lr_booted = true;
} catch ( \Throwable $throwable ) {
if ( function_exists( 'update_option' ) ) {
update_option(
'ns12lr_bootstrap_notice_raw',
array(
'message' => sprintf( 'NS12 Locale Router could not boot: %s', $throwable->getMessage() ),
'type' => 'error',
)
);
}
if ( function_exists( 'add_action' ) ) {
add_action( 'admin_notices', 'ns12lr_render_bootstrap_failure_notice' );
}
if ( function_exists( 'error_log' ) ) {
error_log( sprintf( '[NS12 Locale Router][main-bootstrap] %s', $throwable->getMessage() ) );
}
}
if ( $ns12lr_booted && ! function_exists( 'ns12lr_t' ) ) {
/**
* Translate a dictionary key for the active request locale.
*
* @param string $key Dictionary key.
* @param string $fallback Fallback text.
* @return string
*/
function ns12lr_t( $key, $fallback = '' ) {
return \Ns12LocaleRouter\DictionaryRepository::translate( (string) $key, (string) $fallback );
}
}
if ( $ns12lr_booted && ! function_exists( 'ns12lr_t_format' ) ) {
/**
* Translate and interpolate a dictionary key.
*
* @param string $key Dictionary key.
* @param array $replacements Placeholder values.
* @param string $fallback Fallback text.
* @return string
*/
function ns12lr_t_format( $key, array $replacements = array(), $fallback = '' ) {
return \Ns12LocaleRouter\DictionaryRepository::translate_format( (string) $key, $replacements, (string) $fallback );
}
}