public static function filter_gettext($translation, $text, $domain) { if ($text == 'Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction.') { $translations = get_translations_for_domain('wc-maksuturva'); return $translations->translate($text); } return $translation; }
/** * Looks up a translation in domain 'qtranslate', and if it is not there, uses the default WordPress domain to translate. * @since 3.4.5.5 */ function qtranxf_translate($s) { $t = get_translations_for_domain('qtranslate'); if (isset($t->entries[$s]) && !empty($t->entries[$s]->translations)) { return $t->entries[$s]->translations[0]; } return qtranxf_translate_wp($s); }
/** * @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')); }
/** * @ticket 341142 */ public function test_get_translations_for_domain_does_not_return_null_if_override_load_textdomain_is_used() { add_filter('locale', array($this, 'filter_set_locale_to_german')); add_filter('override_load_textdomain', '__return_true'); $translations = get_translations_for_domain('internationalized-plugin'); remove_filter('override_load_textdomain', '__return_true'); remove_filter('locale', array($this, 'filter_set_locale_to_german')); $this->assertTrue($translations instanceof NOOP_Translations); }
/** * @covers \Pressbooks\L10n\override_core_strings */ public function test_override_core_strings() { $text = 'My Sites'; $domain = 'default'; $translations = get_translations_for_domain($domain)->translate($text); $translated = \Pressbooks\L10n\override_core_strings($translations, $text, $domain); $this->assertNotEmpty($translated); $this->assertNotEquals($text, $translated); // 'My Sites' should be 'My Books', 'Mes Livres', ... }
/** * Change core WordPress strings. * * @param $translated * @param $original * @param $domain * * @return mixed */ function override_core_strings($translated, $original, $domain) { // var_dump( array( $translated, $original, $domain) ); $overrides = include_core_overrides(); if (isset($overrides[$original])) { $translations = get_translations_for_domain($domain); $translated = $translations->translate($overrides[$original]); } return $translated; }
public function filters() { $this->labels = array('singular' => listify_theme_mod('label-singular'), 'plural' => listify_theme_mod('label-plural')); /* print_r( $this->labels ); */ $this->strings = $this->get_strings(); $this->domains = apply_filters('listify_gettext_domains', array('listify', 'wp-job-manager', 'wp-job-manager-tags', 'wp-job-manager-alerts', 'wp-job-manager-locations', 'wp-job-manager-wc-paid-listings', 'wp-job-manager-simple-paid-listings')); $this->translations = get_translations_for_domain('listify'); add_filter('gettext', array($this, 'gettext'), 0, 3); add_filter('gettext_with_context', array($this, 'gettext_with_context'), 0, 4); add_filter('ngettext', array($this, 'ngettext'), 0, 5); }
function single_meta($translation, $text, $domain) { $translations = &get_translations_for_domain( $domain ); // With Tags if ( $text == 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>. Follow any comments here with the <a href="%5$s" title="Comments RSS to %4$s" rel="alternate" type="application/rss+xml">RSS feed for this post</a>.' ) { return $translations->translate( 'This entry was posted in %1$s and tagged %2$s. It can always be found at <a href="%3$s" title="Permalink to %4$s" rel="bookmark">it\'s permalink</a>. Follow any comments left here with the <a href="%5$s" title="Comments RSS to %4$s" rel="alternate" type="application/rss+xml">RSS feed for this post</a>.' ); } //Without elseif( $text == 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>. Follow any comments here with the <a href="%5$s" title="Comments RSS to %4$s" rel="alternate" type="application/rss+xml">RSS feed for this post</a>.' ) { return $translations->translate( 'This entry was posted in %1$s. It can always be found at <a href="%3$s" title="Permalink to %4$s" rel="bookmark">it\'s permalink</a>. Follow any comments left here with the <a href="%5$s" title="Comments RSS to %4$s" rel="alternate" type="application/rss+xml">RSS feed for this post</a>.' ); } return $translation; }
function qpub_filter_gettext($translated, $original, $domain) { // Get text from options page $new_text = get_option('qpub_change_draft', false); // Array of strings to be replaced $strings = array('Draft' => $new_text ? $new_text : ''); // Replace string's translation if (!empty($strings[$original])) { $translations =& get_translations_for_domain($domain); $translated = $translations->translate($strings[$original]); } return $translated; }
/** * This filter translates string before it is displayed * specifically for the words 'Use as featured image' with 'Use as Product Thumbnail' when the user is selecting a Product Thumbnail * using media gallery. * * @param $translation The current translation * @param $text The text being translated * @param $domain The domain for the translation * * @return string The translated / filtered text. */ public static function change_picture_translation($translation, $text, $domain = 'wpshop') { if ($text == 'Use as featured image' && isset($_REQUEST['post_id'])) { $post = get_post($_REQUEST['post_id']); if (!empty($post->post_type) && $post->post_type != WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) { return $translation; } $translations = get_translations_for_domain($domain); if (empty($translations->entries['Use as product thumbnail']->translations[0])) { return $translation; } return $translations->entries['Use as product thumbnail']->translations[0]; } return $translation; }
function gettext($translation, $text, $domain) { global $post; $screen = get_current_screen(); if (isset($post->post_type) && $this->is_plugin_post_type()) { $translations = get_translations_for_domain($domain); if ($text == 'Publish') { return $translations->translate('Create'); } if ($text == 'Move to Trash') { return $translations->translate('Delete'); } } return $translation; }
function comment_says_text($translation, $text, $domain) { $new_says = ''; //whatever you want to have instead of 'says' in comments $translations =& get_translations_for_domain($domain); if ($text == '<cite class="fn">%s</cite> <span class="says">says:</span>') { if ($new_says) { $new_says = ' ' . $new_says; } //compensate for the space character return $translations->translate('<cite class="fn">%s</cite>'); } else { return $translation; // standard text } }
function translation_mangler2($translation, $text, $domain) { global $post; if ($post->post_type == 'videos') { $translations =& get_translations_for_domain($domain); if ($text == 'Scheduled for: <b>%1$s</b>') { return $translations->translate('Video Date: <b>%1$s</b>'); } if ($text == 'Published on: <b>%1$s</b>') { return $translations->translate('Video Date: <b>%1$s</b>'); } if ($text == 'Publish <b>immediately</b>') { return $translations->translate('Video Date: <b>%1$s</b>'); } } return $translation; }
function dh_ptp_custom_rewrites($translation, $text, $domain) { global $post; if (!isset($post->post_type)) { return $translation; } $translations = get_translations_for_domain($domain); $translation_array = array(); switch ($post->post_type) { case 'easy-pricing-table': // enter your post type name here $translation_array = array('Enter title here' => 'Enter pricing table name here'); break; } if (array_key_exists($text, $translation_array)) { return $translations->translate($translation_array[$text]); } return $translation; }
/** * @param $string * * @return string */ public function translate($string) { $args = func_get_args(); $translated = $string; $entry = new Translation_Entry(); $entry->singular = $string; $entry->context = null; foreach ($this->domains as $domain) { /** @var $translator Translations */ $translator =& get_translations_for_domain($domain); $translation = $translator->translate_entry($entry); if ($translation && !empty($translation->translations)) { $translated = $translation->translations[0]; $translated = apply_filters('gettext', $translated, $string, $domain); break; } } return $translated; }
/** * Helper function for allowing the theme to translate the plural text strings for both Hybrid Core and * the available framework extensions. * * @since 1.6.0 * @access public * @param string $domain * @param string $single * @param string $plural * @param int $number * @param string $context * @return string */ function hybrid_translate_plural($domain, $single, $plural, $number, $context = null) { $translations = get_translations_for_domain($domain); return $translations->translate_plural($single, $plural, $number, $context); }
/** * A hybrid of _n() and _x(). It supports contexts and plurals. * * @see _n() * @see _x() * */ function _nx($single, $plural, $number, $context, $domain = 'default') { $translations =& get_translations_for_domain($domain); $translation = $translations->translate_plural($single, $plural, $number, $context); return apply_filters('ngettext_with_context', $translation, $single, $plural, $number, $context, $domain); }
/** * Translates and retrieves the singular or plural form based on the supplied number, with gettext context. * * This is a hybrid of _n() and _x(). It supports context and plurals. * * Used when you want to use the appropriate form of a string with context based on whether a * number is singular or plural. * * Example: * * $people = sprintf( _n( '%s person', '%s people', $count, 'context', 'text-domain' ), number_format_i18n( $count ) ); * * @since 2.8.0 * * @param string $single The text to be used if the number is singular. * @param string $plural The text to be used if the number is plural. * @param int $number The number to compare against to use either the singular or plural form. * @param string $context Context information for the translators. * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. * Default 'default'. * @return string The translated singular or plural form. */ function _nx($single, $plural, $number, $context, $domain = 'default') { $translations = get_translations_for_domain($domain); $translation = $translations->translate_plural($single, $plural, $number, $context); /** * Filter the singular or plural form of a string with gettext context. * * @since 2.8.0 * * @param string $translation Translated text. * @param string $single The text to be used if the number is singular. * @param string $plural The text to be used if the number is plural. * @param string $number The number to compare against to use either the singular or plural form. * @param string $context Context information for the translators. * @param string $domain Text domain. Unique identifier for retrieving translated strings. */ return apply_filters('ngettext_with_context', $translation, $single, $plural, $number, $context, $domain); }
/** * Filters 'gettext' to change the translations used for the each of the extensions' textdomains. This filter * makes it possible for the theme's MO file to translate the framework's extensions. * * @since 1.3.0 * @access private * @param string $translated The translated text. * @param string $text The original, untranslated text. * @param string $domain The textdomain for the text. * @return string $translated */ function hybrid_extensions_gettext($translated, $text, $domain) { /* Check if the current textdomain matches one of the framework extensions. */ if (in_array($domain, array('breadcrumb-trail', 'custom-field-series', 'post-stylesheets', 'theme-layouts'))) { /* If the theme supports the extension, switch the translations. */ if (current_theme_supports($domain)) { /* If the framework mofile is loaded, use its translations. */ if (hybrid_is_textdomain_loaded('hybrid-core')) { $translations =& get_translations_for_domain('hybrid-core'); } elseif (hybrid_is_textdomain_loaded(hybrid_get_parent_textdomain())) { $translations =& get_translations_for_domain(hybrid_get_parent_textdomain()); } /* If translations were found, translate the text. */ if (!empty($translations)) { $translated = $translations->translate($text); } } } return $translated; }
/** * @since 3.4.5.4 - return language name in active language, if available, otherwise the name in native language. */ function qtranxf_getLanguageName($lang = '', $locale = null, $native_name = null) { global $q_config, $l10n; if (empty($lang)) { return $q_config['language_name'][$q_config['language']]; } if (isset($q_config['language-names'][$lang])) { return $q_config['language-names'][$lang]; } if (!isset($l10n['language-names'])) { //is not loaded by default, since this place should not be hit frequently $loc = $q_config['locale'][$q_config['language']]; if (!load_textdomain('language-names', QTRANSLATE_DIR . '/lang/language-names/language-' . $loc . '.mo')) { if ($loc[2] == '_') { $loc = substr($loc, 0, 2); load_textdomain('language-names', QTRANSLATE_DIR . '/lang/language-names/language-' . $loc . '.mo'); } } } $translations = get_translations_for_domain('language-names'); if (!$locale) { $locale = $q_config['locale'][$lang]; } while (!isset($translations->entries[$locale])) { if ($locale[2] == '_') { $locale = substr($locale, 0, 2); if (isset($translations->entries[$locale])) { break; } } if (!$native_name) { $native_name = $q_config['language_name'][$lang]; } return $q_config['language-names'][$lang] = $native_name; } $n = $translations->entries[$locale]->translations[0]; if (empty($q_config['language_name_case'])) { //Camel Case by default if (function_exists('mb_convert_case')) { // module 'mbstring' may not be installed by default: https://wordpress.org/support/topic/qtranslate_utilsphp-on-line-504 $n = mb_convert_case($n, MB_CASE_TITLE); } else { $msg = 'qTranslate-X: Enable PHP module "mbstring" to get names of languages printed in "Camel Case" or disable option \'Show language names in "Camel Case"\' on admin page ' . admin_url('options-general.php?page=qtranslate-x#general') . '. You may find more information at http://php.net/manual/en/mbstring.installation.php, or search for PHP installation options on control panel of your server provider.'; error_log($msg); } } return $q_config['language-names'][$lang] = $n; }
function wpsc_filter_feature_image_text($translation, $text, $domain) { _wpsc_deprecated_function(__FUNCTION__, '3.8.13'); if ('Use as featured image' == $text && isset($_REQUEST['post_id'])) { $post = get_post($_REQUEST['post_id']); if ($post->post_type != 'wpsc-product') { return $translation; } $translations =& get_translations_for_domain($domain); return $translations->translate('Use as Product Thumbnail', 'wp-e-commerce'); //this will never happen, this is here only for gettexr to pick up the translation return __('Use as Product Thumbnail', 'wp-e-commerce'); } return $translation; }
/** * Filter the comment text on the edit screen * to be more sensible * * @since 3.0.0 * * @param $translated * * @return object full translations object */ function filter_gettext($translated, $original, $domain) { //prevent filter looping remove_filter('gettext', __NAMESPACE__ . '\\filter_gettext', 10, 3); if (isset($_REQUEST['post_type']) && WOOFAQS_POST_TYPE === $_REQUEST['post_type'] || isset($_REQUEST['post']) && WOOFAQS_POST_TYPE === get_post_type($_REQUEST['post'])) { $strings = array(__('Comments', 'woocommerce-faqs') => __('Answers', 'woocommerce-faqs'), __('Add comment', 'woocommerce-faqs') => __('Add answer', 'woocommerce-faqs'), __('Add Comment', 'woocommerce-faqs') => __('Add Answer', 'woocommerce-faqs'), __('Add new Comment', 'woocommerce-faqs') => __('Add new Answer', 'woocommerce-faqs'), __('No comments yet.', 'woocommerce-faqs') => __('No answers yet.', 'woocommerce-faqs'), __('Show comments', 'woocommerce-faqs') => __('Show answers', 'woocommerce-faqs'), __('No more comments found.', 'woocommerce-faqs') => __('No more answers found.', 'woocommerce-faqs')); if (isset($strings[$original])) { $translations = get_translations_for_domain($domain); $translated = $translations->translate($strings[$original]); } } //reset filter add_filter('gettext', __NAMESPACE__ . '\\filter_gettext', 10, 3); return $translated; }
/** * Retrieve the plural or single form based on the supplied amount with gettext context. * * This is a hybrid of _n() and _x(). It supports contexts and plurals. * * @since 2.8.0 * * @param string $single The text that will be used if $number is 1. * @param string $plural The text that will be used if $number is not 1. * @param int $number The number to compare against to use either $single or $plural. * @param string $context Context information for the translators. * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. * @return string Either $single or $plural translated text with context. */ function _nx($single, $plural, $number, $context, $domain = 'default') { $translations = get_translations_for_domain($domain); $translation = $translations->translate_plural($single, $plural, $number, $context); /** * Filter text with its translation while plural option and context are available. * * @since 2.8.0 * * @param string $translation Translated text. * @param string $single The text that will be used if $number is 1. * @param string $plural The text that will be used if $number is not 1. * @param string $number The number to compare against to use either $single or $plural. * @param string $context Context information for the translators. * @param string $domain Text domain. Unique identifier for retrieving translated strings. */ return apply_filters('ngettext_with_context', $translation, $single, $plural, $number, $context, $domain); }
function lshowcase_wps_translation_mangler($translation, $text, $domain) { global $post; if (isset($post)) { if ($post->post_type == 'lshowcase') { $translations = get_translations_for_domain($domain); if ($text == 'Publish') { return $translations->translate('SAVE'); } } } return $translation; }
/** * 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); } }
function prefix_filter_gettext($translated, $original, $domain) { $strings = array('View all posts filed under %s' => 'See all articles filed under %s', 'Howdy, %1$s' => 'Greetings, %1$s!'); if (isset($strings[$original])) { $translations =& get_translations_for_domain($domain); $translated = $translations->translate($strings[$original]); } return $translated; }
/** * @since 3.4.5.4 - return language name in active language, if available, otherwise the name in native language. */ function qtranxf_getLanguageName($lang = '') { global $q_config, $l10n; if (empty($lang)) { return $q_config['language_name'][$q_config['language']]; } if (isset($q_config['language-names'][$lang])) { return $q_config['language-names'][$lang]; } if (!isset($l10n['language-names'])) { //is not loaded by default, since this place should not be hit frequently $locale = $q_config['locale'][$q_config['language']]; if (!load_textdomain('language-names', QTRANSLATE_DIR . '/lang/language-names/language-' . $locale . '.mo')) { if ($locale[2] == '_') { $locale = substr($locale, 0, 2); load_textdomain('language-names', QTRANSLATE_DIR . '/lang/language-names/language-' . $locale . '.mo'); } } } $translations = get_translations_for_domain('language-names'); $locale = $q_config['locale'][$lang]; while (!isset($translations->entries[$locale])) { if ($locale[2] == '_') { $locale = substr($locale, 0, 2); if (isset($translations->entries[$locale])) { break; } } return $q_config['language-names'][$lang] = $q_config['language_name'][$lang]; } $n = $translations->entries[$locale]->translations[0]; return $q_config['language-names'][$lang] = mb_convert_case($n, MB_CASE_TITLE); }
function qtranxf_use_block($lang, $blocks, $show_available = false, $show_empty = false) { global $q_config; $available_langs = array(); //$content = qtranxf_split_blocks($blocks); $content = qtranxf_split_blocks($blocks, $available_langs); //qtranxf_dbg_log('qtranxf_use_block: $available_langs: ',$available_langs); // if content is available show the content in the requested language //if(!empty($content[$lang])) return $content[$lang]; if (!empty($available_langs[$lang])) { return $content[$lang]; } elseif ($show_empty) { return ''; } // content is not available in requested language (bad!!) what now? // find available and alternative languages //if(empty($content[$q_config['default_language']])){ if (empty($available_langs[$q_config['default_language']])) { $alt_lang = null; $alt_content = null; $alt_lang_is_default = false; foreach ($available_langs as $language => $b) { if (!qtranxf_isEnabled($language)) { continue; } $alt_lang = $language; $alt_content = $content[$language]; break; } } else { $alt_lang = $q_config['default_language']; $alt_content = $content[$alt_lang]; $alt_lang_is_default = true; } /* $available_languages = array(); foreach($content as $language => $lang_text) { if(empty($lang_text)) continue; if(!qtranxf_isEnabled($language)) continue; $available_languages[] = $language; if(empty($alt_lang)){ $alt_lang = $language; $alt_content = $lang_text; } } */ if (!$alt_lang) { return ''; } if (!$show_available) { if ($q_config['show_displayed_language_prefix']) { return '(' . $q_config['language_name'][$alt_lang] . ') ' . $alt_content; } else { return $alt_content; } } //qtranxf_dbg_log('$alt_content=',$alt_content); // display selection for available languages $language_list = ''; if (preg_match('/%LANG:([^:]*):([^%]*)%/', $q_config['not_available'][$lang], $match)) { $normal_separator = $match[1]; $end_separator = $match[2]; // build available languages string backward $translations = get_translations_for_domain('qtranslate'); $english_names = qtranxf_default_windows_locale(); //todo: load enabled only $i = 0; //foreach($available_languages as $language) { foreach ($available_langs as $language => $b) { if ($i == 1) { $language_list = $end_separator . $language_list; } elseif ($i > 1) { $language_list = $normal_separator . $language_list; } if (!empty($english_names[$language]) && isset($translations->entries[$english_names[$language]])) { $language_name = $translations->entries[$english_names[$language]]->translations[0]; } else { $language_name = $q_config['language_name'][$language]; } $language_list = '<a href="' . qtranxf_convertURL('', $language, false, true) . '" class="qtranxs-available-language-link qtranxs-available-language-link-' . $language . '">' . $language_name . '</a>' . $language_list; ++$i; } } //qtranxf_dbg_log('$language_list=',$language_list); $msg = ''; if (!empty($q_config['show_alternative_content']) && $q_config['show_alternative_content']) { // show content in alternative language //if(sizeof($available_languages) > 1){ if (sizeof($available_langs) > 1) { if ($alt_lang_is_default) { //$fmt = __('For the sake of viewer convenience, the content is shown below in this site default language %s.', 'qtranslate'); $msg = __('For the sake of viewer convenience, the content is shown below in this site default language.', 'qtranslate'); } else { //$fmt = __('For the sake of viewer convenience, the content is shown below in an available alternative language %s.', 'qtranslate'); $msg = __('For the sake of viewer convenience, the content is shown below in one of the available alternative languages.', 'qtranslate'); } //$msg = sprintf($fmt, '<a href="'.qtranxf_convertURL('', $language, false, true).'">'.$q_config['language_name'][$alt_lang].'</a>'); $msg .= ' ' . __('You may click one of the links to switch the site language to another available language.', 'qtranslate'); } else { $msg = __('For the sake of viewer convenience, the content is shown below in the alternative language.', 'qtranslate'); $msg .= ' ' . __('You may click the link to switch the active language.', 'qtranslate'); } $altlanguagecontent = ' ' . $msg . '</p>' . $alt_content; } else { //by default, do not show alternative content $altlanguagecontent = '</p>'; } $output = '<p class="qtranxs-available-languages-message qtranxs-available-languages-message-' . $lang . '">' . preg_replace('/%LANG:([^:]*):([^%]*)%/', $language_list, $q_config['not_available'][$lang]) . $altlanguagecontent; /* todo documentation */ return apply_filters('i18n_content_translation_not_available', $output, $lang, $language_list, $alt_lang, $alt_content, $msg, $q_config); }
/** * @ticket 21319 */ public function test_get_translations_for_domain_non_existent_file() { load_textdomain('wp-tests-domain', DIR_TESTDATA . '/non-existent-file'); $this->assertInstanceOf('NOOP_Translations', get_translations_for_domain('wp-tests-domain')); }
function qtranxf_translate_dt_format($fmt, $lang = null) { global $q_config; if (empty($lang)) { $lang = $q_config['language']; } switch ($fmt) { case 'date_format': $fmt = 'F j, Y'; break; case 'time_format': $fmt = 'g:i a'; break; case 'date_time_format': $fmt = 'F j, Y g:i a'; break; } if (empty($q_config['locale'][$lang])) { $locales = qtranxf_language_configured('locale'); if (empty($locales[$lang])) { return $fmt; } $loc = $locales[$lang]; } else { $loc = $q_config['locale'][$lang]; } $text_domain = 'locale-' . $loc; if (!isset($l10n[$text_domain])) { $mo = WP_LANG_DIR . '/' . $loc . '.mo'; if (!load_textdomain($text_domain, $mo)) { qtranxf_updateGettextDatabases(true, $lang); load_textdomain($text_domain, $mo); } } $translations = get_translations_for_domain($text_domain); if (isset($translations->entries[$fmt])) { $fmt = $translations->entries[$fmt]->translations[0]; } return $fmt; }