'', 'name' => '', 'value' => '' ) * @param string $name The name of the string to help identify the string, e.g. copyright text * @param string $context The context of the string to help identify the string's origin, e.g. Blograzzi theme * * @package Blograzzi * @since Blograzzi 1.8 */ function blograzzi_add_t_string( $strings, $name = '', $context = 'Blograzzi theme' ){ global $blograzzi_t_strings; if ( is_array( $strings ) ) { foreach ( $strings as $string ) { if ( ! ( $string['value'] && $string['name'] ) ) continue; if ( ! $string['context'] ) $string['context'] = $context; $blograzzi_t_strings[] = $string; } } else { $string = array( 'value' => $strings, 'name' => $name, 'context' => $context ); $blograzzi_t_strings[] = $string; } } /** * Get the translated string * * @param string $value The default value that will be returned if string hasn't been translated * @param string $name The name of the string * @param string $context The context of the string * * @package Blograzzi * @since Blograzzi 1.8 */ function blograzzi_icl_t( $name, $value = '', $context = 'Blograzzi theme' ){ if ( ! function_exists( 'icl_t' ) ) return $value; else return icl_t( $context, $name, $value ); } /** * Registers the translatable options */ function blograzzi_register_t_options(){ if ( ! function_exists( 'icl_t' ) ) return; global $blograzzi_settings; $options = array( array( 'name' => 'Copyright text', 'value' => $blograzzi_settings['copy_text'], 'context' => '' ) , array( 'name' => 'Home nav menu description', 'value' => $blograzzi_settings['navmenu_home_desc'], 'context' => '' ) ); foreach ( $blograzzi_settings['social_profiles'] as $social_profile ) { $options[] = array( 'name' => 'Social icon - ' . $social_profile['name'], 'value' => wp_kses_decode_entities( $social_profile['title'] ), 'context' => '' ); } blograzzi_add_t_string( $options ); } /** * Replace the strings in the theme's settings with the translated strings */ function blograzzi_translate_settings(){ if ( ! function_exists( 'icl_t' ) ) return; if ( is_admin() ) return; global $blograzzi_settings; $blograzzi_settings['copy_text'] = blograzzi_icl_t( 'Copyright text', $blograzzi_settings['copy_text'] ); $blograzzi_settings['navmenu_home_desc'] = blograzzi_icl_t( 'Home nav menu description', $blograzzi_settings['navmenu_home_desc'] ); foreach ( $blograzzi_settings['social_profiles'] as $key => $social_profile ) { $blograzzi_settings['social_profiles'][$key]['title'] = blograzzi_icl_t( 'Social icon - ' . $social_profile['name'], wp_kses_decode_entities( $social_profile['title'] ) ); } } add_action( 'template_redirect', 'blograzzi_translate_settings' ); /** * Adjusts object IDs for multilingual functionality * * @package Blograzzi * @since Blograzzi 1.8.4 */ function blograzzi_object_id( $ids, $type = '', $return_original_if_missing = false, $language_code = NULL ){ $is_array = true; if ( function_exists( 'icl_object_id' ) ) { if ( ! is_array( $ids ) ) { $ids = (array) $ids; $is_array = false; } foreach ( $ids as $key => $id ) { $current_type = ( ! $type ) ? get_post_type( $id ) : $type; $ids[$key] = icl_object_id( $id, $current_type, $return_original_if_missing, $language_code ); } } if ( ! $is_array ) $ids = array_pop( $ids ); return $ids; }