本文整理汇总了PHP中icl_get_string_id函数的典型用法代码示例。如果您正苦于以下问题:PHP icl_get_string_id函数的具体用法?PHP icl_get_string_id怎么用?PHP icl_get_string_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了icl_get_string_id函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: build_label_array
private function build_label_array($singular_label, $label, $str_lang, $corrections)
{
global $sitepress;
$return = array('en' => array('singular' => $singular_label, 'general' => $label, 'original' => true));
$str_lang = $str_lang ? $str_lang : 'en';
$str_name_singular = 'taxonomy singular name: ' . $singular_label;
$return['id_singular'] = icl_get_string_id($singular_label, 'WordPress', $str_name_singular);
if (!$return['id_singular'] && ($str_lang == 'en' || $corrections == 2)) {
$return['id_singular'] = icl_register_string('WordPress', $str_name_singular, $singular_label);
}
$str_name_general = 'taxonomy general name: ' . $label;
$return['id_general'] = icl_get_string_id($label, 'WordPress', $str_name_general);
if (!$return['id_general'] && ($str_lang === 'en' || $corrections == 2)) {
$return['id_general'] = icl_register_string('WordPress', $str_name_general, $label);
}
$active_lang_codes = array_keys($sitepress->get_active_languages(true));
foreach ($active_lang_codes as $language) {
if ($language == 'en') {
continue;
}
$exists_singular = null;
$translated_label = icl_translate('WordPress', $str_name_singular, $singular_label, false, $exists_singular, $language);
if ($exists_singular) {
$return[$language]['singular'] = $translated_label;
}
$exists_plural = null;
$translated_label = icl_translate('WordPress', $str_name_general, $label, false, $exists_plural, $language);
if ($exists_plural) {
$return[$language]['general'] = $translated_label;
}
}
return $return;
}
示例2: translated_attribute_label
function translated_attribute_label($label, $name)
{
global $sitepress;
if (is_admin() && !wpml_is_ajax()) {
global $wpdb, $sitepress_settings;
$string_id = icl_get_string_id('taxonomy singular name: ' . $label, 'WordPress');
if (defined('ICL_SITEPRESS_VERSION') && version_compare(ICL_SITEPRESS_VERSION, '3.2', '>=')) {
$strings_language = icl_st_get_string_language($string_id);
} else {
$strings_language = $sitepress_settings['st']['strings_language'];
}
if ($string_id && $sitepress_settings['admin_default_language'] != $strings_language) {
$string = $wpdb->get_var($wpdb->prepare("SELECT value FROM {$wpdb->prefix}icl_string_translations WHERE string_id = %s and language = %s", $string_id, $sitepress_settings['admin_default_language']));
if ($string) {
return $string;
}
} else {
return $label;
}
}
$name = sanitize_title($name);
$lang = $sitepress->get_current_language();
$trnsl_labels = get_option('wcml_custom_attr_translations');
if (isset($trnsl_labels[$lang][$name])) {
return $trnsl_labels[$lang][$name];
}
return icl_t('WordPress', 'taxonomy singular name: ' . $label, $label);
}
示例3: build_label_array
private function build_label_array($singular_label, $label)
{
global $sitepress, $wpdb;
$return = array();
$str_name_singular = 'taxonomy singular name: ' . $singular_label;
$return['id_singular'] = icl_get_string_id($singular_label, 'WordPress', $str_name_singular);
if (!$return['id_singular']) {
$return['id_singular'] = icl_register_string('WordPress', $str_name_singular, $singular_label);
}
$str_name_general = 'taxonomy general name: ' . $label;
$return['id_general'] = icl_get_string_id($label, 'WordPress', $str_name_general);
if (!$return['id_general']) {
$return['id_general'] = icl_register_string('WordPress', $str_name_general, $label);
}
$active_lang_codes = array_keys($sitepress->get_active_languages(true));
foreach ($active_lang_codes as $language) {
$exists_singular = null;
$translated_label = icl_translate('WordPress', $str_name_singular, $singular_label, false, $exists_singular, $language);
if ($exists_singular) {
$return[$language]['singular'] = $translated_label;
}
$exists_plural = null;
$translated_label = icl_translate('WordPress', $str_name_general, $label, false, $exists_plural, $language);
if ($exists_plural) {
$return[$language]['general'] = $translated_label;
}
}
$string = new WPML_ST_String($return['id_singular'], $wpdb);
$return[$string->get_language()] = array('singular' => $singular_label, 'general' => $label, 'original' => true);
$return['st_default_lang'] = $string->get_language();
return $return;
}
示例4: translated_attribute_label
function translated_attribute_label($label, $name)
{
global $sitepress;
if (is_admin() && !wpml_is_ajax()) {
global $wpdb, $sitepress_settings;
if ($sitepress_settings['admin_default_language'] == $sitepress_settings['st']['strings_language']) {
return $label;
} else {
$string_id = icl_get_string_id('taxonomy singular name: ' . $label, 'WordPress');
if ($string_id) {
$string = $wpdb->get_var($wpdb->prepare("SELECT value FROM {$wpdb->prefix}icl_string_translations WHERE string_id = %s and language = %s", $string_id, $sitepress_settings['admin_default_language']));
if ($string) {
return $string;
}
}
}
}
$name = woocommerce_sanitize_taxonomy_name($name);
$lang = $sitepress->get_current_language();
$trnsl_labels = get_option('wcml_custom_attr_translations');
if (isset($trnsl_labels[$lang][$name])) {
return $trnsl_labels[$lang][$name];
}
return icl_t('WordPress', 'taxonomy singular name: ' . $label, $label);
}
示例5: test_add_default_slug_translations
function test_add_default_slug_translations()
{
$category_base = !empty($this->wc_permalinks['category_base']) ? $this->wc_permalinks['category_base'] : $this->url_translation->default_product_category_base;
$name = $this->url_translation->url_string_name('product_cat');
$this->url_translation->add_default_slug_translations($category_base, $name);
$string_id = icl_get_string_id($category_base, $this->url_translation->url_strings_context(), $name);
$translations = icl_get_string_translations_by_id($string_id);
$this->assertEquals('categorie-produit', $translations['fr']['value']);
}
示例6: get_endpoint_translation
function get_endpoint_translation($key, $endpoint, $language = null)
{
global $wpdb;
$string = icl_get_string_id($endpoint, 'WooCommerce Endpoints', $key);
if (!$string && function_exists('icl_register_string')) {
do_action('wpml_register_single_string', 'WooCommerce Endpoints', $key, $endpoint);
} else {
$this->endpoints_strings[] = $string;
}
if (function_exists('icl_t')) {
return apply_filters('wpml_translate_single_string', $endpoint, 'WooCommerce Endpoints', $key, $language);
} else {
return $endpoint;
}
}
示例7: translated_attribute_label
function translated_attribute_label($label, $name, $product_obj = false)
{
global $sitepress, $product, $woocommerce;
$product_id = false;
$lang = $sitepress->get_current_language();
$name = sanitize_title($name);
if (isset($product->id)) {
$product_id = $product->id;
} elseif (isset($product_obj->id)) {
$product_id = $product_obj->id;
}
if ($product_id) {
$custom_attr_translation = get_post_meta($product_id, 'attr_label_translations', true);
if ($custom_attr_translation) {
if (isset($custom_attr_translation[$lang][$name])) {
return $custom_attr_translation[$lang][$name];
}
}
}
if (is_admin() && !wpml_is_ajax()) {
global $wpdb, $sitepress_settings;
$string_id = icl_get_string_id('taxonomy singular name: ' . $label, 'WordPress');
if (WPML_SUPPORT_STRINGS_IN_DIFF_LANG) {
$strings_language = icl_st_get_string_language($string_id);
} else {
$strings_language = $sitepress_settings['st']['strings_language'];
}
if ($string_id && $sitepress_settings['admin_default_language'] != $strings_language) {
$string = $wpdb->get_var($wpdb->prepare("SELECT value FROM {$wpdb->prefix}icl_string_translations WHERE string_id = %s and language = %s", $string_id, $sitepress_settings['admin_default_language']));
if ($string) {
return $string;
}
} else {
return $label;
}
}
$trnsl_label = apply_filters('wpml_translate_single_string', $label, 'WordPress', 'taxonomy singular name: ' . $label, $lang);
if ($label != $trnsl_label) {
return $trnsl_label;
}
// backward compatibility for WCML < 3.6.1
$trnsl_labels = get_option('wcml_custom_attr_translations');
if (isset($trnsl_labels[$lang][$name]) && !empty($trnsl_labels[$lang][$name])) {
return $trnsl_labels[$lang][$name];
}
return $label;
}
示例8: test_translate_attributes_label_in_wp_taxonomies
function test_translate_attributes_label_in_wp_taxonomies()
{
global $wp_taxonomies, $sitepress, $WPML_String_Translation;
$WPML_String_Translation->init_active_languages();
$label = 'Test attr';
$name = wc_attribute_taxonomy_name($label);
$taxonomy_data = array('hierarchical' => true, 'update_count_callback' => '_update_post_term_count', 'labels' => array('name' => $label, 'singular_name' => $label, 'search_items' => sprintf(__('Search %s', 'woocommerce'), $label), 'all_items' => sprintf(__('All %s', 'woocommerce'), $label), 'parent_item' => sprintf(__('Parent %s', 'woocommerce'), $label), 'parent_item_colon' => sprintf(__('Parent %s:', 'woocommerce'), $label), 'edit_item' => sprintf(__('Edit %s', 'woocommerce'), $label), 'update_item' => sprintf(__('Update %s', 'woocommerce'), $label), 'add_new_item' => sprintf(__('Add New %s', 'woocommerce'), $label), 'new_item_name' => sprintf(__('New %s', 'woocommerce'), $label)), 'show_ui' => true, 'show_in_menu' => false, 'show_in_nav_menus' => false, 'meta_box_cb' => false, 'query_var' => 1, 'rewrite' => false, 'sort' => false, 'public' => 1, 'show_in_nav_menus' => 1, 'capabilities' => array('manage_terms' => 'manage_product_terms', 'edit_terms' => 'edit_product_terms', 'delete_terms' => 'delete_product_terms', 'assign_terms' => 'assign_product_terms'));
$taxonomy_data['rewrite'] = array('slug' => empty($permalinks['attribute_base']) ? '' : trailingslashit($permalinks['attribute_base']) . sanitize_title($label), 'with_front' => false, 'hierarchical' => true);
do_action('wpml_register_single_string', 'WordPress', 'taxonomy singular name: ' . $label, $label);
$string_id = icl_get_string_id($label, 'WordPress', 'taxonomy singular name: ' . $label);
icl_add_string_translation($string_id, 'es', 'Test attr es', ICL_TM_COMPLETE);
$WPML_String_Translation->clear_string_filter('es');
$sitepress->switch_lang('es');
register_taxonomy($name, apply_filters("woocommerce_taxonomy_objects_{$name}", array('product')), apply_filters("woocommerce_taxonomy_args_{$name}", $taxonomy_data));
$this->assertTrue((bool) has_filter('wpml_translate_single_string'));
$this->assertEquals('Test attr es', $wp_taxonomies[$name]->labels->name);
}
示例9: get_filtered_comments
function get_filtered_comments($comments)
{
$user_id = get_current_user_id();
if ($user_id) {
global $wpdb, $woocommerce_wpml;
$user_language = get_user_meta($user_id, 'icl_admin_language', true);
foreach ($comments as $key => $comment) {
$comment_string_id = icl_get_string_id($comment->comment_content, 'woocommerce');
if ($comment_string_id) {
$comment_strings = icl_get_string_translations_by_id($comment_string_id);
if ($comment_strings) {
$comments[$key]->comment_content = $comment_strings[$user_language]['value'];
}
}
}
}
return $comments;
}
示例10: test_created_or_edited_link_category_action
public function test_created_or_edited_link_category_action()
{
$this->instantiate_link_manager('edit-tags.php');
$cat_name = "My cat";
$taxonomy = 'link_category';
$args = array('description' => "My cat description");
$term = wp_insert_term($cat_name, $taxonomy, $args);
$cat = get_term($term['term_id'], $taxonomy);
// check if name & description strings are registered
$context = $this->get_category_string_context($cat);
$name_name = $this->lm_helper->get_category_string_name('name', $cat);
$name_desc = $this->lm_helper->get_category_string_name('description', $cat);
$cat_has_strings = false;
if (icl_get_string_id($cat->name, $context, $name_name) && icl_get_string_id($cat->description, $context, $name_desc)) {
$cat_has_strings = true;
}
$this->assertTrue($cat_has_strings);
}
示例11: get_label_translations
public static function get_label_translations($taxonomy)
{
global $sitepress, $wpdb;
$return = false;
$taxonomy_object = get_taxonomy($taxonomy);
// Careful index checking here, otherwise some of those private taxonomies used by WooCommerce will result in errors here.
if (defined('WPML_ST_FOLDER') && $taxonomy_object && isset($taxonomy_object->label) && isset($taxonomy_object->labels) && isset($taxonomy_object->labels->singular_name)) {
$label = $taxonomy_object->label;
$singular_label = $taxonomy_object->labels->singular_name;
$str_lang = $sitepress->get_user_admin_language($sitepress->get_current_user()->ID);
$corrections = 0;
if ($str_lang != 'en') {
$label_translations_sql = "\n\t\t\t\t\t\t\t\t\t\tSELECT s.value as original, t.value as translation\n\t\t\t\t\t\t\t\t\t\tFROM {$wpdb->prefix}icl_strings s\n\t\t\t\t\t\t\t\t\t\tJOIN {$wpdb->prefix}icl_string_translations t ON t.string_id = s.id\n\t\t\t\t\t\t\t\t\t\tAND s.name LIKE 'taxonomy%%name:%%'\n\t\t\t\t\t\t\t";
$label_translations = $wpdb->get_results($label_translations_sql);
foreach ($label_translations as $label_translation) {
if ($label_translation->translation == $singular_label) {
$singular_label = $label_translation->original;
$corrections++;
} elseif ($label_translation->translation == $label) {
$label = $label_translation->original;
$corrections++;
}
}
}
$return = array('en' => array('singular' => $singular_label, 'general' => $label, 'original' => true));
$return['id_singular'] = icl_get_string_id($singular_label, 'WordPress');
if (!$return['id_singular'] && ($str_lang == 'en' || $corrections == 2)) {
$return['id_singular'] = icl_register_string('WordPress', 'taxonomy singular name: ' . $singular_label, $singular_label);
}
$return['id_general'] = icl_get_string_id($label, 'WordPress');
if (!$return['id_general'] && ($str_lang == 'en' || $corrections == 2)) {
$return['id_general'] = icl_register_string('WordPress', 'taxonomy general name: ' . $label, $label);
}
$active_lang_codes = array_keys($sitepress->get_active_languages(true));
foreach ($active_lang_codes as $language) {
if ($language == 'en') {
continue;
}
$exists_singular = null;
$translated_label = icl_translate('WordPress', 'taxonomy singular name: ' . $singular_label, $singular_label, false, $exists_singular, $language);
if ($exists_singular) {
$return[$language]['singular'] = $translated_label;
}
$exists_plural = null;
$translated_label = icl_translate('WordPress', 'taxonomy general name: ' . $label, $label, false, $exists_plural, $language);
if ($exists_plural) {
$return[$language]['general'] = $translated_label;
}
}
}
$return['st_default_lang'] = 'en';
return $return;
}
示例12: get_label_translations
public static function get_label_translations($taxonomy)
{
global $sitepress;
remove_all_filters('gettext_with_context', -1000);
remove_all_filters('gettext', -1000);
$return = false;
$taxonomy_object = get_taxonomy($taxonomy);
// Careful index checking here, otherwise some of those private taxonomies used by WooCommerce will result in errors here.
if (defined('WPML_ST_FOLDER') && $taxonomy_object && isset($taxonomy_object->label) && isset($taxonomy_object->labels) && isset($taxonomy_object->labels->singular_name)) {
$label = $taxonomy_object->label;
$singular_label = $taxonomy_object->labels->singular_name;
$return = array('en' => array('singular' => $singular_label, 'general' => $label, 'original' => true));
$return['id_singular'] = icl_get_string_id($singular_label, 'WordPress');
if (!$return['id_singular']) {
$return['id_singular'] = icl_register_string('WordPress', 'taxonomy singular name: ' . $singular_label, $singular_label);
}
$return['id_general'] = icl_get_string_id($label, 'WordPress');
if (!$return['id_general']) {
$return['id_general'] = icl_register_string('WordPress', 'taxonomy general name: ' . $label, $label);
}
$active_lang_codes = array_keys($sitepress->get_active_languages(true));
foreach ($active_lang_codes as $language) {
if ($language == 'en') {
continue;
}
$exists_singular = null;
$translated_label = icl_translate('WordPress', 'taxonomy singular name: ' . $singular_label, $singular_label, false, $exists_singular, $language);
if ($exists_singular) {
$return[$language]['singular'] = $translated_label;
}
$exists_plural = null;
$translated_label = icl_translate('WordPress', 'taxonomy general name: ' . $label, $label, false, $exists_plural, $language);
if ($exists_plural) {
$return[$language]['general'] = $translated_label;
}
}
}
$return['st_default_lang'] = 'en';
return $return;
}
开发者ID:StudioCreate,项目名称:Uncle-Hummer-WordPress-Theme,代码行数:40,代码来源:taxonomy-translation-display.class.php
示例13: serialize_settings
/**
* Translate the plugin settings before they are saved to DB.
*
* @since 1.0.1.0
*
* @param array $obj The serialized data collection.
* @param MS_Model_Settings $model The source object.
* @return array The serialized data collection.
*/
public function serialize_settings($data, $model)
{
if ($this->current_lang == $this->default_lang) {
return $data;
}
// Save the translated values before resetting the model.
$translations = array();
foreach ($model->protection_messages as $key => $message) {
$translations[$key] = $message;
}
// Reset the values to Default language.
$data['protection_messages'] = $model->reset_field('protection_messages');
// Store translations via WPML.
if (function_exists('icl_add_string_translation')) {
foreach ($translations as $key => $tr_message) {
$string_name = 'ms-set-protection-' . $key;
do_action('wpml_register_single_string', self::CONTEXT, $string_name, $model->protection_messages[$key]);
$string_id = icl_get_string_id($model->protection_messages[$key], self::CONTEXT, $string_name);
if ($string_id) {
icl_add_string_translation($string_id, $this->current_lang, $tr_message, ICL_TM_COMPLETE);
}
}
}
return $data;
}
示例14: translate_attribute_taxonomies_labels
function translate_attribute_taxonomies_labels($attribute_taxonomies)
{
global $sitepress;
if (is_admin() && !wpml_is_ajax()) {
foreach ($attribute_taxonomies as $key => $attribute_taxonomy) {
$string_language = $this->get_string_language($attribute_taxonomy->attribute_name, 'WordPress', 'taxonomy singular name: ' . $attribute_taxonomy->attribute_name);
if ($sitepress->get_current_language() == $string_language) {
continue;
}
$string_id = icl_get_string_id($attribute_taxonomy->attribute_name, 'WordPress', 'taxonomy singular name: ' . $attribute_taxonomy->attribute_name);
$strings = icl_get_string_translations_by_id($string_id);
if ($strings && isset($strings[$sitepress->get_current_language()])) {
$attribute_taxonomies[$key]->attribute_label = $strings[$sitepress->get_current_language()]['value'];
}
}
}
return $attribute_taxonomies;
}
示例15: tl_rescan_p
function tl_rescan_p()
{
global $wpdb, $sitepress_settings;
set_time_limit(0);
if (preg_replace('#M$#', '', ini_get('memory_limit')) < 128) {
ini_set('memory_limit', '128M');
}
$plugins = array();
if (!empty($_POST['plugin'])) {
foreach ($_POST['plugin'] as $plugin) {
$plugins[] = array('file' => $plugin, 'mu' => 0);
// regular plugins
}
}
if (!empty($_POST['mu-plugin'])) {
foreach ($_POST['mu-plugin'] as $plugin) {
$plugins[] = array('file' => $plugin, 'mu' => 1);
//mu plugins
}
}
$scan_stats = '';
foreach ($plugins as $p) {
$plugin = $p['file'];
if (false !== strpos($plugin, '/') && !$p['mu']) {
$plugin = dirname($plugin);
}
if ($p['mu']) {
$plugin_path = WPMU_PLUGIN_DIR . '/' . $plugin;
} else {
$plugin_path = WP_PLUGIN_DIR . '/' . $plugin;
}
$scan_stats .= icl_st_scan_plugin_files($plugin_path);
if ($_POST['icl_load_mo'] && !$p['mu']) {
$mo_files = icl_st_get_mo_files($plugin_path);
foreach ($mo_files as $m) {
$i = preg_match('#[-]([a-z_]+)\\.mo$#i', $m, $matches);
if ($i && ($lang = $wpdb->get_var("SELECT code FROM {$wpdb->prefix}icl_locale_map WHERE locale='" . $matches[1] . "'"))) {
$tr_pairs = icl_st_load_translations_from_mo($m);
foreach ($tr_pairs as $original => $translation) {
$string_id = icl_get_string_id($original, 'plugin ' . basename($plugin_path));
if (!$wpdb->get_var("SELECT id FROM {$wpdb->prefix}icl_string_translations WHERE string_id={$string_id} AND language='{$lang}'")) {
icl_add_string_translation($string_id, $lang, $translation, ICL_STRING_TRANSLATION_COMPLETE);
}
}
}
}
}
}
echo '1|' . $scan_stats;
exit;
}