コード例 #1
0
ファイル: Emails.php プロジェクト: hyyan/woo-poly-integration
 /**
  * Reload text domains with order locale.
  *
  * @param string $language Language slug (e.g. en, de )
  */
 public function switchLanguage($language)
 {
     if (class_exists('Polylang')) {
         global $locale, $polylang, $woocommerce;
         static $cache;
         // Polylang string translations cache object to avoid loading the same translations object several times
         // Cache object not found. Create one...
         if (empty($cache)) {
             $cache = new \PLL_Cache();
         }
         //$current_language = pll_current_language( 'locale' );
         // unload plugin's textdomains
         unload_textdomain('default');
         unload_textdomain('woocommerce');
         // set locale to order locale
         $locale = apply_filters('locale', $language);
         $polylang->curlang->locale = $language;
         // Cache miss
         if (false === ($mo = $cache->get($language))) {
             $mo = new \PLL_MO();
             $mo->import_from_db($GLOBALS['polylang']->model->get_language($language));
             $GLOBALS['l10n']['pll_string'] =& $mo;
             // Add to cache
             $cache->set($language, $mo);
         }
         // (re-)load plugin's textdomain with order locale
         load_default_textdomain($language);
         $woocommerce->load_plugin_textdomain();
         $wp_locale = new \WP_Locale();
     }
 }
コード例 #2
0
ファイル: api.php プロジェクト: iq007/MadScape
function pll_translate_string($string, $lang)
{
    if (pll_current_language() == $lang) {
        return pll__($string);
    }
    static $cache;
    // cache object to avoid loading the same translations object several times
    if (empty($cache)) {
        $cache = new PLL_Cache();
    }
    if (false === ($mo = $cache->get($lang))) {
        $mo = new PLL_MO();
        $mo->import_from_db(PLL()->model->get_language($lang));
        $cache->set($lang, $mo);
    }
    return $mo->translate($string);
}