以下代码示例以默认语言 URL 的绝对路径开头,生成所有活动语言的翻译 URL。
// list of urls in default language for which you need the equivalent in all languages $product_feed_url_list_in_default_language = [ 'http://example.com/product1', 'http://example.com/product2' ]; $trp = TRP_Translate_Press::get_trp_instance(); $trp_settings = $trp->get_component( 'settings' ); $settings = $trp_settings->get_settings(); $url_converter = $trp->get_component( 'url_converter' ); $translated_urls = []; foreach ( $product_feed_url_list_in_default_language as $url ) { // iterating over active TranslatePress languages foreach ( $settings['publish-languages'] as $language ) { if ( $settings['default-language'] === $language ) { // skip default language continue; } // generate translated url for a particular language $translated_urls[] = esc_url( $url_converter->get_url_for_language( $language, $url, '' ) ); } }
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容