首页>文档>TranslatePress教程>提取翻译后的 URL

提取翻译后的 URL

以下代码示例以默认语言 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, '' ) );
    }
}
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
搜索