PHP code example of nativemind / wp-translation

1. Go to this page and download the library: Download nativemind/wp-translation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nativemind / wp-translation example snippets


   // Edit multisite/my_domains.php
   cybo_add_extra_domain( 'your-domain.com', '/', 1 );
   

[nm_language_switcher show_flags="true" show_names="true" dropdown="false"]

echo nm_get_language_switcher(array(
    'show_flags' => true,
    'show_names' => true,
    'dropdown' => false
));

// Add to i18n/menu/custom.php
$nm_custom = array(
    'en' => array(
        'Home' => 'Home',
        'About' => 'About Us'
    ),
    'ru' => array(
        'Home' => 'Главная',
        'About' => 'О нас'
    )
);

// Clear all cache
$cleared = NativeMindCache::clear_all();

// Get cache statistics  
$stats = NativeMindCache::get_stats();

// Manual cache control
$cache_key = NativeMindCache::generate_cache_key($content, 'en', 'ru');
NativeMindCache::set($cache_key, $translated_content);

// Configure in multisite/my_domains.php
cybo_add_extra_domain( 'en.example.com', '/', 1 );  // English site
cybo_add_extra_domain( 'ru.example.com', '/', 2 );  // Russian site
cybo_add_extra_domain( 'example.ru', '/', 2 );      // Alternative Russian domain

// Plugin initialization
do_action('nm_plugin_loaded');

// Translation events
do_action('nm_translation_start', $content, $from_lang, $to_lang);
do_action('nm_translation_complete', $translated_content, $original_content);
do_action('nm_translation_error', $error_message, $content);

// Cache events
do_action('nm_cache_cleared');
do_action('nm_cache_cleanup');

// Modify translation before processing
$content = apply_filters('nm_pre_translate', $content, $from_lang, $to_lang);

// Modify translated content
$translated = apply_filters('nm_post_translate', $translated_content, $original_content);

// Customize language switcher output
$switcher_html = apply_filters('nm_language_switcher_html', $html, $args);

// Modify cache key generation
$cache_key = apply_filters('nm_cache_key', $cache_key, $content, $lang_from, $lang_to);

$quality = nm_check_translation_quality($original, $translated);
echo "Quality Score: " . $quality['quality_score'] . "%";

$browser_lang = nm_get_browser_language();
if ($browser_lang !== 'en') {
    // Redirect to appropriate language site
    nm_auto_redirect_language();
}

$flag = nm_get_flag_emoji('de'); // Returns 🇩🇪

// Access via browser
http://yoursite.com/wp-content/plugins/nativelang-wordpress/test_cache.php

// Or 

// In wp-config.php
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);

// Check logs at /wp-content/debug.log
bash
   # Set in your server environment or wp-config.php
   define('GOOGLE_TRANSLATE_API_KEY', 'your-api-key-here');
   
bash
   # Copy the template and add your API key
   cp translateTextGoogle.php.example translateTextGoogle.php
   # Edit translateTextGoogle.php and add your API key