Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save razvan-translatepress/af547ca1f71642a15a8e6d7c24ebc1fc to your computer and use it in GitHub Desktop.
Save razvan-translatepress/af547ca1f71642a15a8e6d7c24ebc1fc to your computer and use it in GitHub Desktop.
Extracting translated URLs
// 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, '' ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment