function wpcf7_load_textdomain($locale = null) { global $l10n; $domain = 'contact-form-7'; if (get_locale() == $locale) { $locale = null; } if (empty($locale)) { if (is_textdomain_loaded($domain)) { return true; } else { return load_plugin_textdomain($domain, false, $domain . '/languages'); } } else { $mo_orig = $l10n[$domain]; unload_textdomain($domain); $mofile = $domain . '-' . $locale . '.mo'; $path = WP_PLUGIN_DIR . '/' . $domain . '/languages'; if ($loaded = load_textdomain($domain, $path . '/' . $mofile)) { return $loaded; } else { $mofile = WP_LANG_DIR . '/plugins/' . $mofile; return load_textdomain($domain, $mofile); } $l10n[$domain] = $mo_orig; } return false; }
/** * @ticket 21319 */ function test_is_textdomain_loaded_for_no_translations() { $this->assertFalse(load_textdomain('wp-tests-domain', DIR_TESTDATA . '/non-existent-file')); $this->assertFalse(is_textdomain_loaded('wp-tests-domain')); $this->assertInstanceOf('NOOP_Translations', get_translations_for_domain('wp-tests-domain')); // Ensure that we don't confuse NOOP_Translations to be a loaded text domain. $this->assertFalse(is_textdomain_loaded('wp-tests-domain')); $this->assertFalse(unload_textdomain('wp-tests-domain')); }
function test_load_unload_textdomain() { $this->assertFalse(is_textdomain_loaded('wp-tests-domain')); $this->assertFalse(unload_textdomain('wp-tests-domain')); $file = DIR_TESTDATA . '/pomo/simple.mo'; $this->assertTrue(load_textdomain('wp-tests-domain', $file)); $this->assertTrue(is_textdomain_loaded('wp-tests-domain')); $this->assertTrue(unload_textdomain('wp-tests-domain')); $this->assertFalse(is_textdomain_loaded('wp-tests-domain')); }
/** * @ticket 34114 */ public function test_theme_translation_should_be_translated_without_calling_load_theme_textdomain() { add_filter('locale', array($this, 'filter_set_locale_to_german')); switch_theme('internationalized-theme'); include_once get_stylesheet_directory() . '/functions.php'; $is_textdomain_loaded_before = is_textdomain_loaded('internationalized-theme'); $expected_output = i18n_theme_test(); $is_textdomain_loaded_after = is_textdomain_loaded('internationalized-theme'); unload_textdomain('internationalized-theme'); remove_filter('locale', array($this, 'filter_set_locale_to_german')); $this->assertFalse($is_textdomain_loaded_before); $this->assertSame('Das ist ein Dummy Theme', $expected_output); $this->assertTrue($is_textdomain_loaded_after); }
public function set_language($lang) { global $sitepress, $woocommerce; $sitepress->switch_lang($lang, true); $this->locale = $sitepress->get_locale($lang); add_filter('plugin_locale', array($this, 'set_locale'), 10, 2); unload_textdomain('woocommerce'); unload_textdomain('woocommerce-germanized'); unload_textdomain('woocommerce-germanized-pro'); unload_textdomain('default'); $woocommerce->load_plugin_textdomain(); WC_germanized()->load_plugin_textdomain(); do_action('woocommerce_gzd_wpml_lang_changed', $lang); load_default_textdomain(); global $wp_locale; $wp_locale = new WP_Locale(); }
/** * Bootstrap localisation of self */ public static function load_textdomain($locale = null) { if (is_null($locale)) { $locale = get_locale(); } if (!$locale || 0 === strpos($locale, 'en')) { self::$locale and unload_textdomain(Loco::NS); $locale = 'en_US'; } else { if (self::$locale !== $locale) { $plugin_rel_path = basename(self::basedir()); load_plugin_textdomain(Loco::NS, false, $plugin_rel_path . '/languages'); } } // detect changes in plugin locale, binding once only isset(self::$locale) or add_filter('plugin_locale', array(__CLASS__, 'filter_plugin_locale'), 10, 2); self::$locale = $locale; }
function test_switches_to_es() { // We need to something in order to set the Global $l10n $file = DIR_TESTDATA . '/pomo/simple.mo'; load_textdomain('wp-tests-domain', $file); $this->assertEquals('es_ES', switch_to_locale('es_ES')); $this->assertEquals('es_ES', get_locale()); $this->assertEquals('en_GB', switch_to_locale('en_GB')); $this->assertEquals('en_GB', get_locale()); // return early if you try to switch to the same locale $this->assertEquals('en_GB', switch_to_locale('en_GB')); $this->assertEquals('en_GB', get_locale()); $this->assertEquals('es_ES', restore_locale()); $this->assertEquals('es_ES', get_locale()); $this->assertEquals('en_US', restore_locale(true)); $this->assertEquals('en_US', get_locale()); $this->assertEquals('xx_XX', switch_to_locale('xx_XX')); $this->assertEquals('xx_XX', get_locale()); // tidy up unload_textdomain('wp-tests-domain'); global $l10n; $l10n = null; }
function k12nn_locale_func($atts, $content = null) { $a = shortcode_atts(array('locale' => 'en_US'), $atts); global $k12nn_locale; global $k12nn_previous_locale; $k12nn_previous_locale = get_locale(); $k12nn_locale = $a['locale']; add_filter('locale', 'k12nn_redefine_locale'); setlocale(LC_ALL, $k12nn_locale); if (function_exists('dk_speakout_translate')) { unload_textdomain('dk_speakout'); dk_speakout_translate(); } $return = do_shortcode($content); $k12nn_locale = $k12nn_previous_locale; remove_filter('locale', 'k12nn_redefine_locale'); setlocale(LC_ALL, $k12nn_locale); if (function_exists('dk_speakout_translate')) { unload_textdomain('dk_speakout'); dk_speakout_translate(); } return $return; }
$value = null; if (isset($_POST[$option])) { $value = $_POST[$option]; if (!is_array($value)) { $value = trim($value); } $value = wp_unslash($value); } update_option($option, $value); } // Switch translation in case WPLANG was changed. $language = get_option('WPLANG'); if ($language) { load_default_textdomain($language); } else { unload_textdomain('default'); } } /** * Handle settings errors and return to options page */ // If no settings errors were registered add a general 'updated' message. if (!count(get_settings_errors())) { add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated'); } set_transient('settings_errors', get_settings_errors(), 30); /** * Redirect back to the settings page that was submitted */ $goback = add_query_arg('settings-updated', 'true', wp_get_referer()); wp_redirect($goback);
/** * create missing pages */ function create_missing_store_pages() { global $sitepress, $wp_rewrite, $woocommerce_wpml, $woocommerce; $miss_lang = $this->get_missing_store_pages(); //dummy array for names $names = array(__('Cart', 'woocommerce-multilingual'), __('Checkout', 'woocommerce-multilingual'), __('Checkout → Pay', 'woocommerce-multilingual'), __('Order Received', 'woocommerce-multilingual'), __('My Account', 'woocommerce-multilingual'), __('Change Password', 'woocommerce-multilingual'), __('Edit My Address', 'woocommerce-multilingual'), __('Logout', 'woocommerce-multilingual'), __('Lost Password', 'woocommerce-multilingual'), __('View Order', 'woocommerce-multilingual'), __('Shop', 'woocommerce-multilingual')); if (isset($miss_lang['codes'])) { $wp_rewrite = new WP_Rewrite(); $check_pages = $this->get_wc_pages(); $default_language = $sitepress->get_default_language(); if (in_array($default_language, $miss_lang['codes'])) { $miss_lang['codes'] = array_merge(array($default_language), array_diff($miss_lang['codes'], array($default_language))); } foreach ($miss_lang['codes'] as $mis_lang) { $args = array(); unload_textdomain('woocommerce-multilingual'); $sitepress->switch_lang($mis_lang); load_textdomain('woocommerce-multilingual', WCML_LOCALE_PATH . '/woocommerce-multilingual-' . $sitepress->get_locale($mis_lang) . '.mo'); foreach ($check_pages as $page) { $orig_id = get_option($page); $trid = $sitepress->get_element_trid($orig_id, 'post_page'); $translations = $sitepress->get_element_translations($trid, 'post_page', true); if (!isset($translations[$mis_lang]) || !is_null($translations[$mis_lang]->element_id) && get_post_status($translations[$mis_lang]->element_id) != 'publish') { $orig_page = get_post($orig_id); switch ($page) { case 'woocommerce_shop_page_id': $page_title = __('Shop', 'woocommerce-multilingual'); break; case 'woocommerce_cart_page_id': $page_title = __('Cart', 'woocommerce-multilingual'); break; case 'woocommerce_checkout_page_id': $page_title = __('Checkout', 'woocommerce-multilingual'); break; case 'woocommerce_myaccount_page_id': $page_title = __('My Account', 'woocommerce-multilingual'); break; default: $page_title = __($orig_page->post_title, 'woocommerce-multilingual'); break; } $args['post_title'] = $page_title; $args['post_type'] = $orig_page->post_type; $args['post_content'] = $orig_page->post_content; $args['post_excerpt'] = $orig_page->post_excerpt; $args['post_status'] = isset($translations[$mis_lang]->element_id) && get_post_status($translations[$mis_lang]->element_id) != 'publish' ? 'publish' : $orig_page->post_status; $args['menu_order'] = $orig_page->menu_order; $args['ping_status'] = $orig_page->ping_status; $args['comment_status'] = $orig_page->comment_status; $post_parent = apply_filters('translate_object_id', $orig_page->post_parent, 'page', false, $mis_lang); $args['post_parent'] = is_null($post_parent) ? 0 : $post_parent; $new_page_id = wp_insert_post($args); if (isset($translations[$mis_lang]->element_id) && get_post_status($translations[$mis_lang]->element_id) == 'trash' && $mis_lang == $default_language) { update_option($page, $new_page_id); } if (isset($translations[$mis_lang]->element_id) && !is_null($translations[$mis_lang]->element_id)) { $sitepress->set_element_language_details($translations[$mis_lang]->element_id, 'post_page', false, $mis_lang); } $trid = $sitepress->get_element_trid($orig_id, 'post_page'); $sitepress->set_element_language_details($new_page_id, 'post_page', $trid, $mis_lang); } } unload_textdomain('woocommerce-multilingual'); $sitepress->switch_lang($default_language); load_textdomain('woocommerce-multilingual', WCML_LOCALE_PATH . '/woocommerce-multilingual-' . $sitepress->get_locale($default_language) . '.mo'); } wp_redirect(admin_url('admin.php?page=wpml-wcml')); exit; } }
/** * Gives a nicely-formatted list of timezone strings. * * @since 2.9.0 * @since 4.7.0 Added the `$locale` parameter. * * @staticvar bool $mo_loaded * @staticvar string $locale_loaded * * @param string $selected_zone Selected timezone. * @param string $locale Optional. Locale to load the timezones in. Default current site locale. * @return string */ function wp_timezone_choice($selected_zone, $locale = null) { static $mo_loaded = false, $locale_loaded = null; $continents = array('Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific'); // Load translations for continents and cities. if (!$mo_loaded || $locale !== $locale_loaded) { $locale_loaded = $locale ? $locale : get_locale(); $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; unload_textdomain('continents-cities'); load_textdomain('continents-cities', $mofile); $mo_loaded = true; } $zonen = array(); foreach (timezone_identifiers_list() as $zone) { $zone = explode('/', $zone); if (!in_array($zone[0], $continents)) { continue; } // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later $exists = array(0 => isset($zone[0]) && $zone[0], 1 => isset($zone[1]) && $zone[1], 2 => isset($zone[2]) && $zone[2]); $exists[3] = $exists[0] && 'Etc' !== $zone[0]; $exists[4] = $exists[1] && $exists[3]; $exists[5] = $exists[2] && $exists[3]; $zonen[] = array('continent' => $exists[0] ? $zone[0] : '', 'city' => $exists[1] ? $zone[1] : '', 'subcity' => $exists[2] ? $zone[2] : '', 't_continent' => $exists[3] ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') : '', 't_city' => $exists[4] ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') : '', 't_subcity' => $exists[5] ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') : ''); } usort($zonen, '_wp_timezone_choice_usort_callback'); $structure = array(); if (empty($selected_zone)) { $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>'; } foreach ($zonen as $key => $zone) { // Build value in an array to join later $value = array($zone['continent']); if (empty($zone['city'])) { // It's at the continent level (generally won't happen) $display = $zone['t_continent']; } else { // It's inside a continent group // Continent optgroup if (!isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) { $label = $zone['t_continent']; $structure[] = '<optgroup label="' . esc_attr($label) . '">'; } // Add the city to the value $value[] = $zone['city']; $display = $zone['t_city']; if (!empty($zone['subcity'])) { // Add the subcity to the value $value[] = $zone['subcity']; $display .= ' - ' . $zone['t_subcity']; } } // Build the value $value = join('/', $value); $selected = ''; if ($value === $selected_zone) { $selected = 'selected="selected" '; } $structure[] = '<option ' . $selected . 'value="' . esc_attr($value) . '">' . esc_html($display) . "</option>"; // Close continent optgroup if (!empty($zone['city']) && (!isset($zonen[$key + 1]) || isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent'])) { $structure[] = '</optgroup>'; } } // Do UTC $structure[] = '<optgroup label="' . esc_attr__('UTC') . '">'; $selected = ''; if ('UTC' === $selected_zone) { $selected = 'selected="selected" '; } $structure[] = '<option ' . $selected . 'value="' . esc_attr('UTC') . '">' . __('UTC') . '</option>'; $structure[] = '</optgroup>'; // Do manual UTC offsets $structure[] = '<optgroup label="' . esc_attr__('Manual Offsets') . '">'; $offset_range = array(-12, -11.5, -11, -10.5, -10, -9.5, -9, -8.5, -8, -7.5, -7, -6.5, -6, -5.5, -5, -4.5, -4, -3.5, -3, -2.5, -2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 5.75, 6, 6.5, 7, 7.5, 8, 8.5, 8.75, 9, 9.5, 10, 10.5, 11, 11.5, 12, 12.75, 13, 13.75, 14); foreach ($offset_range as $offset) { if (0 <= $offset) { $offset_name = '+' . $offset; } else { $offset_name = (string) $offset; } $offset_value = $offset_name; $offset_name = str_replace(array('.25', '.5', '.75'), array(':15', ':30', ':45'), $offset_name); $offset_name = 'UTC' . $offset_name; $offset_value = 'UTC' . $offset_value; $selected = ''; if ($offset_value === $selected_zone) { $selected = 'selected="selected" '; } $structure[] = '<option ' . $selected . 'value="' . esc_attr($offset_value) . '">' . esc_html($offset_name) . "</option>"; } $structure[] = '</optgroup>'; return join("\n", $structure); }
function wcml_refresh_text_domain() { global $woocommerce; $domain = 'woocommerce'; unload_textdomain($domain); $woocommerce->load_plugin_textdomain(); }
function change_email_language($lang) { global $sitepress, $woocommerce; $sitepress->switch_lang($lang, true); $this->locale = $sitepress->get_locale($lang); unload_textdomain('woocommerce'); unload_textdomain('default'); $woocommerce->load_plugin_textdomain(); load_default_textdomain(); global $wp_locale; $wp_locale = new WP_Locale(); }
/** * 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(); } }
/** * Enable localisation * @internal */ function twitter_api_load_textdomain($locale = null, $domain = 'twitter-api') { static $current_locale; if (is_null($locale)) { $locale = get_locale(); } if (!$locale || 0 === strpos($locale, 'en')) { $current_locale and unload_textdomain($domain); $locale = 'en_US'; } else { if ($current_locale !== $locale) { // purposefully not calling load_plugin_textdomain, due to symlinking // and not knowing what plugin this could be called from. $mofile = realpath(twitter_api_basedir() . '/lang/' . $domain . '-' . $locale . '.mo'); if (!load_textdomain($domain, $mofile)) { $mofile = WP_LANG_DIR . '/plugins/' . $domain . '-' . $locale . '.mo'; load_textdomain($domain, $mofile); } } } // detect changes in plugin locale, binding once only if (!isset($current_locale)) { add_filter('plugin_locale', '_twitter_api_filter_plugin_locale', 10, 2); } $current_locale = $locale; }
function ab_deactivate() { // unload l10n unload_textdomain('ab'); }
function test_override_load_textdomain_custom_mofile() { add_filter('override_load_textdomain', array($this, '_override_load_textdomain_filter'), 10, 3); $load_textdomain = load_textdomain('wp-tests-domain', WP_LANG_DIR . '/plugins/internationalized-plugin-de_DE.mo'); remove_filter('override_load_textdomain', array($this, '_override_load_textdomain_filter')); $is_textdomain_loaded = is_textdomain_loaded('wp-tests-domain'); unload_textdomain('wp-tests-domain'); $is_textdomain_loaded_after = is_textdomain_loaded('wp-tests-domain'); $this->assertTrue($load_textdomain); $this->assertTrue($is_textdomain_loaded); $this->assertFalse($is_textdomain_loaded_after); }
function json_api($args = array()) { $json_api_args = $args[0]; $verify_api_user_args = $args[1]; $method = (string) $json_api_args[0]; $url = (string) $json_api_args[1]; $post_body = is_null($json_api_args[2]) ? null : (string) $json_api_args[2]; $user_details = (array) $json_api_args[4]; $locale = (string) $json_api_args[5]; if (!$verify_api_user_args) { $user_id = 0; } elseif ('internal' === $verify_api_user_args[0]) { $user_id = (int) $verify_api_user_args[1]; if ($user_id) { $user = get_user_by('id', $user_id); if (!$user || is_wp_error($user)) { return false; } } } else { $user_id = call_user_func(array($this, 'test_api_user_code'), $verify_api_user_args); if (!$user_id) { return false; } } /* debugging error_log( "-- begin json api via jetpack debugging -- " ); error_log( "METHOD: $method" ); error_log( "URL: $url" ); error_log( "POST BODY: $post_body" ); error_log( "VERIFY_ARGS: " . print_r( $verify_api_user_args, 1 ) ); error_log( "VERIFIED USER_ID: " . (int) $user_id ); error_log( "-- end json api via jetpack debugging -- " ); */ if ('en' !== $locale) { // .org mo files are named slightly different from .com, and all we have is this the locale -- try to guess them. $new_locale = $locale; if (strpos($locale, '-') !== false) { $pieces = explode('-', $locale); $new_locale = $locale_pieces[0]; $new_locale .= !empty($locale_pieces[1]) ? '_' . strtoupper($locale_pieces[1]) : ''; } else { // .com might pass 'fr' because thats what our language files are named as, where core seems // to do fr_FR - so try that if we don't think we can load the file. if (!file_exists(WP_LANG_DIR . '/' . $locale . '.mo')) { $new_locale = $locale . '_' . strtoupper($locale); } } if (file_exists(WP_LANG_DIR . '/' . $new_locale . '.mo')) { unload_textdomain('default'); load_textdomain('default', WP_LANG_DIR . '/' . $new_locale . '.mo'); } } $old_user = wp_get_current_user(); wp_set_current_user($user_id); $token = Jetpack_Data::get_access_token(get_current_user_id()); if (!$token || is_wp_error($token)) { return false; } define('REST_API_REQUEST', true); define('WPCOM_JSON_API__BASE', 'public-api.wordpress.com/rest/v1'); // needed? require_once ABSPATH . 'wp-admin/includes/admin.php'; require_once JETPACK__PLUGIN_DIR . 'class.json-api.php'; $api = WPCOM_JSON_API::init($method, $url, $post_body); $api->token_details['user'] = $user_details; require_once JETPACK__PLUGIN_DIR . 'class.json-api-endpoints.php'; $display_errors = ini_set('display_errors', 0); ob_start(); $content_type = $api->serve(false); $output = ob_get_clean(); ini_set('display_errors', $display_errors); $nonce = wp_generate_password(10, false); $hmac = hash_hmac('md5', $nonce . $output, $token->secret); wp_set_current_user(isset($old_user->ID) ? $old_user->ID : 0); return array((string) $output, (string) $nonce, (string) $hmac); }
/** * Switches the translations according to the given locale. * * @since 4.6.0 * * @param string $locale The locale. * * @return string $locale |false */ public function switch_to_locale($locale) { $current_locale = get_locale(); if ($current_locale === $locale) { return $locale; } if (!in_array($locale, get_available_languages())) { return false; } // add here so not to record duplicate switches $this->locales[] = $locale; /** * @global MO[] $l10n */ global $l10n; // return early if on no language to switch from if (null === $l10n) { return false; } $textdomains = array_keys($l10n); if (!$this->has_translations_for_locale($current_locale)) { foreach ($textdomains as $textdomain) { $this->translations[$current_locale][$textdomain] = get_translations_for_domain($textdomain); } } $this->remove_filters(); $this->add_filter_for_locale($locale); if ($this->has_translations_for_locale($locale)) { foreach ($textdomains as $textdomain) { if (isset($this->translations[$locale][$textdomain])) { $l10n[$textdomain] = $this->translations[$locale][$textdomain]; } } } else { foreach ($l10n as $textdomain => $mo) { if ('default' === $textdomain) { load_default_textdomain(); continue; } unload_textdomain($textdomain); if ($mofile = $mo->get_filename()) { load_textdomain($textdomain, $mofile); } $this->translations[$locale][$textdomain] = get_translations_for_domain($textdomain); } } /** * @global WP_Locale $wp_locale */ $GLOBALS['wp_locale'] = new WP_Locale(); return $locale; }
/** * @ticket 37113 */ public function test_should_allow_unloading_of_text_domain() { add_filter('locale', array($this, 'filter_set_locale_to_german')); require_once DIR_TESTDATA . '/plugins/internationalized-plugin.php'; $expected_output_before = i18n_plugin_test(); $is_textdomain_loaded_before = is_textdomain_loaded('internationalized-plugin'); unload_textdomain('internationalized-plugin'); remove_filter('locale', array($this, 'filter_set_locale_to_german')); $expected_output_after = i18n_plugin_test(); $is_textdomain_loaded_after = is_textdomain_loaded('internationalized-plugin'); add_filter('locale', array($this, 'filter_set_locale_to_german')); load_textdomain('internationalized-plugin', WP_LANG_DIR . '/plugins/internationalized-plugin-de_DE.mo'); $expected_output_final = i18n_plugin_test(); $is_textdomain_loaded_final = is_textdomain_loaded('internationalized-plugin'); unload_textdomain('internationalized-plugin'); remove_filter('locale', array($this, 'filter_set_locale_to_german')); // Text domain loaded just in time. $this->assertSame('Das ist ein Dummy Plugin', $expected_output_before); $this->assertTrue($is_textdomain_loaded_before); // Text domain unloaded. $this->assertSame('This is a dummy plugin', $expected_output_after); $this->assertFalse($is_textdomain_loaded_after); // Text domain loaded manually again. $this->assertSame('Das ist ein Dummy Plugin', $expected_output_final); $this->assertTrue($is_textdomain_loaded_final); }
/** * create missing pages */ function create_missing_store_pages() { global $sitepress, $wp_rewrite, $woocommerce_wpml; $miss_lang = $this->get_missing_store_pages(); //dummy array for names $names = array(__('Cart', 'wpml-wcml'), __('Checkout', 'wpml-wcml'), __('Checkout → Pay', 'wpml-wcml'), __('Order Received', 'wpml-wcml'), __('My Account', 'wpml-wcml'), __('Change Password', 'wpml-wcml'), __('Edit My Address', 'wpml-wcml'), __('Logout', 'wpml-wcml'), __('Lost Password', 'wpml-wcml'), __('View Order', 'wpml-wcml'), __('Shop', 'wpml-wcml')); if ($miss_lang) { $wp_rewrite = new WP_Rewrite(); $current_language = $sitepress->get_current_language(); $check_pages = apply_filters('wcml_wc_installed_pages', array('woocommerce_shop_page_id', 'woocommerce_cart_page_id', 'woocommerce_checkout_page_id', 'woocommerce_myaccount_page_id')); if (in_array($sitepress->get_default_language(), $miss_lang['codes'])) { $miss_lang['codes'] = array_merge(array($sitepress->get_default_language()), array_diff($miss_lang['codes'], array($sitepress->get_default_language()))); } foreach ($miss_lang['codes'] as $mis_lang) { $args = array(); foreach ($check_pages as $page) { $orig_id = get_option($page); $trnsl_id = icl_object_id($orig_id, 'page', false, $mis_lang); if ($orig_id && (is_null($trnsl_id) || get_post_status($trnsl_id) != 'publish')) { $orig_page = get_post($orig_id); unload_textdomain('wpml-wcml'); $sitepress->switch_lang($mis_lang); $woocommerce_wpml->load_locale(); $args['post_title'] = __($orig_page->post_title, 'wpml-wcml'); $args['post_type'] = $orig_page->post_type; $args['post_content'] = $orig_page->post_content; $args['post_excerpt'] = $orig_page->post_excerpt; $args['post_status'] = get_post_status($trnsl_id) != 'publish' ? 'publish' : $orig_page->post_status; $args['menu_order'] = $orig_page->menu_order; $args['ping_status'] = $orig_page->ping_status; $args['comment_status'] = $orig_page->comment_status; $post_parent = icl_object_id($orig_page->post_parent, 'page', false, $mis_lang); $args['post_parent'] = is_null($post_parent) ? 0 : $post_parent; $new_page_id = wp_insert_post($args); if (get_post_status($trnsl_id) == 'trash' && $mis_lang == $sitepress->get_default_language()) { update_option($page, $new_page_id); } $trid = $sitepress->get_element_trid($orig_id, 'post_' . $orig_page->post_type); $sitepress->set_element_language_details($new_page_id, 'post_' . $orig_page->post_type, $trid, $mis_lang); if (!is_null($trnsl_id)) { $sitepress->set_element_language_details($trnsl_id, 'post_' . $orig_page->post_type, false, $mis_lang); } $sitepress->switch_lang($current_language); } } } unload_textdomain('wpml-wcml'); $sitepress->switch_lang($current_language); $woocommerce_wpml->load_locale(); wp_redirect(admin_url('admin.php?page=wpml-wcml')); exit; } }
/** * Load translations for a given locale. * * When switching to a locale, translations for this locale must be loaded from scratch. * * @since 4.7.0 * @access private * * @global Mo[] $l10n An array of all currently loaded text domains. * * @param string $locale The locale to load translations for. */ private function load_translations($locale) { global $l10n; $domains = $l10n ? array_keys($l10n) : array(); load_default_textdomain($locale); foreach ($domains as $domain) { if ('default' === $domain) { continue; } unload_textdomain($domain); get_translations_for_domain($domain); } }
/** * Load default translated strings based on locale. * * Loads the .mo file in WP_LANG_DIR constant path from WordPress root. * The translated (.mo) file is named based on the locale. * * @see load_textdomain() * * @since 1.5.0 * * @param string $locale Optional. Locale to load. Default is the value of {@see get_locale()}. * @return bool Whether the textdomain was loaded. */ function load_default_textdomain($locale = null) { if (null === $locale) { $locale = get_locale(); } // Unload previously loaded strings so we can switch translations. unload_textdomain('default'); $return = load_textdomain('default', WP_LANG_DIR . "/{$locale}.mo"); if ((is_multisite() || defined('WP_INSTALLING_NETWORK') && WP_INSTALLING_NETWORK) && !file_exists(WP_LANG_DIR . "/admin-{$locale}.mo")) { load_textdomain('default', WP_LANG_DIR . "/ms-{$locale}.mo"); return $return; } if (is_admin() || wp_installing() || defined('WP_REPAIRING') && WP_REPAIRING) { load_textdomain('default', WP_LANG_DIR . "/admin-{$locale}.mo"); } if (is_network_admin() || defined('WP_INSTALLING_NETWORK') && WP_INSTALLING_NETWORK) { load_textdomain('default', WP_LANG_DIR . "/admin-network-{$locale}.mo"); } return $return; }
/** * Remove translations from memory. * * @since 0.3.0 * @access public * @return bool true if the text domain was loaded, false if it was not. */ public function unload() { return unload_textdomain($this->text_domain); }
/** * Get all possible translations for a String based on the given Languages and Domains * * WARNING: This function is slow because it deals with files, so don't overuse it! * * @todo Include support for the `load_theme_textdomain` + `load_muplugin_textdomain` * * @param array $strings An array of strings (required) * @param array $languages Which l10n to fetch the string (required) * @param array $domains Possible Domains to re-load * @param string $default_language The default language to avoid re-doing that * * @return array A multi level array with the possible translations for the given strings */ public function get_i18n_strings($strings, $languages, $domains = array(), $default_language = 'en_US') { $domains = wp_parse_args($domains, array('default' => true, 'the-events-calendar' => $this->pluginDir . 'lang/')); foreach ($languages as $language) { foreach ((array) $domains as $domain => $file) { // Configure the language $this->_locale = $language; add_filter('locale', array($this, '_set_locale')); // Reload it with the correct language unload_textdomain($domain); if ('default' === $domain) { load_default_textdomain(); } else { load_plugin_textdomain($domain, false, $file); } // Loop on the strings the build the possible translations foreach ($strings as $key => $value) { $value = is_array($value) ? reset($value) : $value; if (!is_string($value)) { continue; } // Make sure we have an Array $strings[$key] = (array) $strings[$key]; // Grab the possible strings for Default and Any other domain if ('default' === $domain) { $strings[$key][] = __($value); $strings[$key][] = __(strtolower($value)); $strings[$key][] = __(ucfirst($value)); } else { $strings[$key][] = __($value, $domain); $strings[$key][] = __(strtolower($value), $domain); $strings[$key][] = __(ucfirst($value), $domain); } } // Set back to the default language remove_filter('locale', array($this, '_set_locale')); // Reload it with the correct language unload_textdomain($domain); if ('default' === $domain) { load_default_textdomain(); } else { load_plugin_textdomain($domain, false, $file); } } } // Prevent Empty Strings and Duplicates foreach ($strings as $key => $value) { $strings[$key] = array_filter(array_unique(array_map('sanitize_title_with_dashes', $value))); } return $strings; }
/** * Load translations for a given locale. * * When switching to a locale, translations for this locale must be loaded from scratch. * * @since 4.7.0 * @access private * * @global Mo[] $l10n An array of all currently loaded text domains. * * @param string $locale The locale to load translations for. */ private function load_translations($locale) { global $l10n; $domains = $l10n ? array_keys($l10n) : array(); load_default_textdomain($locale); foreach ($domains as $domain) { if ('default' === $domain) { continue; } $mofile = $l10n[$domain]->get_filename(); unload_textdomain($domain); if ($mofile) { load_textdomain($domain, $mofile); } get_translations_for_domain($domain); } }
function filter_woocommerce_order_review() { global $woocommerce; unload_textdomain('woocommerce'); $woocommerce->load_plugin_textdomain(); }
/** * Get all possible translations for a String based on the given Languages and Domains * * WARNING: This function is slow because it deals with files, so don't overuse it! * Differently from the `get_i18n_strings` method this will not use any domain that's not specified. * * @todo Include support for the `load_theme_textdomain` + `load_muplugin_textdomain` * * @param array $strings An array of strings (required) * @param array $languages Which l10n to fetch the string (required) * @param array $domains Possible Domains to re-load * * @return array A multi level array with the possible translations for the given strings */ public function get_i18n_strings_for_domains($strings, $languages, $domains = array('default')) { foreach ($languages as $language) { $this->_locale = $language; foreach ((array) $domains as $domain => $file) { // Configure the language add_filter('locale', array($this, '_set_locale')); // Reload it with the correct language unload_textdomain($domain); if ('default' === $domain) { load_default_textdomain(); } else { Tribe__Main::instance()->load_text_domain($domain, $file); } // Loop on the strings the build the possible translations foreach ($strings as $key => $value) { $value = is_array($value) ? reset($value) : $value; if (!is_string($value)) { continue; } // Make sure we have an Array $strings[$key] = (array) $strings[$key]; // Grab the possible strings for Default and Any other domain if ('default' === $domain) { $strings[$key][] = __($value); $strings[$key][] = __(strtolower($value)); $strings[$key][] = __(ucfirst($value)); } else { $strings[$key][] = __($value, $domain); $strings[$key][] = __(strtolower($value), $domain); $strings[$key][] = __(ucfirst($value), $domain); } } // Set back to the default language remove_filter('locale', array($this, '_set_locale')); // Reload it with the correct language unload_textdomain($domain); if ('default' === $domain) { load_default_textdomain(); } else { Tribe__Main::instance()->load_text_domain($domain, $file); } } } // Prevent Empty Strings and Duplicates foreach ($strings as $key => $value) { $strings[$key] = array_filter(array_unique(array_map('sanitize_title_with_dashes', (array) $value))); } return $strings; }
function custom_box_html($html, $template_data, $lang) { if ($template_data['product_content'] == '_product_tabs') { global $wc_tab_manager; $orig_prod_tabs = $wc_tab_manager->get_product_tabs($template_data['product_id']); if (!$orig_prod_tabs) { return ''; } if ($template_data['tr_product_id']) { $tr_prod_tabs = $wc_tab_manager->get_product_tabs($template_data['tr_product_id']); if (!is_array($tr_prod_tabs)) { return __('Please update original product', 'wpml-wcml'); } foreach ($tr_prod_tabs as $key => $prod_tab) { if (in_array($prod_tab['type'], array('product', 'core'))) { if ($prod_tab['type'] == 'core') { $template_data['tr_tabs'][$prod_tab['id']]['id'] = $prod_tab['id']; $template_data['tr_tabs'][$prod_tab['id']]['type'] = $prod_tab['type']; $template_data['tr_tabs'][$prod_tab['id']]['title'] = $prod_tab['title']; $template_data['tr_tabs'][$prod_tab['id']]['heading'] = isset($prod_tab['heading']) ? $prod_tab['heading'] : ''; } else { $template_data['tr_tabs'][$prod_tab['position']]['id'] = $prod_tab['id']; $template_data['tr_tabs'][$prod_tab['position']]['type'] = $prod_tab['type']; } } } } else { global $sitepress, $woocommerce; $current_language = $sitepress->get_current_language(); foreach ($orig_prod_tabs as $key => $prod_tab) { if ($prod_tab['type'] == 'core') { unload_textdomain('woocommerce'); $sitepress->switch_lang($lang); $woocommerce->load_plugin_textdomain(); $title = __($prod_tab['title'], 'woocommerce'); if ($prod_tab['title'] != $title) { $template_data['tr_tabs'][$prod_tab['id']]['title'] = $title; } if (!isset($prod_tab['heading'])) { $template_data['tr_tabs'][$prod_tab['id']]['heading'] = ''; } else { $heading = __($prod_tab['heading'], 'woocommerce'); if ($prod_tab['heading'] != $heading) { $template_data['tr_tabs'][$prod_tab['id']]['heading'] = $heading; } } unload_textdomain('woocommerce'); $sitepress->switch_lang($current_language); $woocommerce->load_plugin_textdomain(); } } } foreach ($orig_prod_tabs as $key => $prod_tab) { if (in_array($prod_tab['type'], array('product', 'core'))) { if ($prod_tab['type'] == 'core') { $template_data['orig_tabs'][$prod_tab['id']]['id'] = $prod_tab['id']; $template_data['orig_tabs'][$prod_tab['id']]['type'] = $prod_tab['type']; } else { $template_data['orig_tabs'][$prod_tab['position']]['id'] = $prod_tab['id']; $template_data['orig_tabs'][$prod_tab['position']]['type'] = $prod_tab['type']; } } } return include WCML_PLUGIN_PATH . '/compatibility/templates/wc_tab_manager_custom_box_html.php'; } return $html; }
/** * Load default translated strings based on locale. * * Loads the .mo file in WP_LANG_DIR constant path from WordPress root. * The translated (.mo) file is named based on the locale. * * @see load_textdomain() * * @since 1.5.0 * * @param string $locale Optional. Locale to load. Default is the value of {@see get_locale()}. * @return bool Whether the textdomain was loaded. */ function load_default_textdomain($locale = null) { if (null === $locale) { $locale = get_locale(); } // Unload previously loaded strings so we can switch translations. unload_textdomain('default'); $return = load_textdomain('default', WP_LANG_DIR . "/{$locale}.mo"); if (is_admin() || wp_installing() || defined('WP_REPAIRING') && WP_REPAIRING) { load_textdomain('default', WP_LANG_DIR . "/admin-{$locale}.mo"); } return $return; }