WordPress.org

Ready to get started?Download WordPress

Forums

Multisite Language Switcher
[resolved] Change the generated URLs (11 posts)

  1. lucaslem
    Member
    Posted 10 months ago #

    I am successfully using your snippet to resolve localization of my cpt. If I wanted to extend this for my custom taxonomy slugs do I need to create an entirely new function specific for the taxonomy or can I add some code to this one?
    Thanks.

    http://wordpress.org/plugins/multisite-language-switcher/

  2. realloc
    Member
    Plugin Author

    Posted 10 months ago #

    You can just add the necessary code to one function.

    Read on here: http://codex.wordpress.org/Conditional_Tags#A_Post_Type

    Cheers,
    Dennis.

  3. lucaslem
    Member
    Posted 10 months ago #

    Thanks Dennis,
    This is working very well for my cpt slugs. For my custom tax, it works once in one direction and then stops switching. In other words:

    When I use the switcher like this I have succes:
    eng-custom-tax/eng-post-slug -> fr-custom-tax/fr-post-slug

    But when I use it to go back, this is what I get:
    fr-custom-tax/fr-post-slug -> fr-custom-tax/eng-post-slug

    Any ideas what might be messing up the round trip?

    Just for information: I have my .po and .mo files all good. My custom tax is registered like so:

    'rewrite' => array(
                'slug' => _x('workshop/category', 'URL slug', 'ismh-workshops'),
                'with_front' => true,
                'query_var' => true
            ),

    And in my functions.php I have:

    function my_url_translator( $url, $language ) {
    	if ( 'fr_FR' == $language ) {
    	    $url = str_replace( '/workshop/category/', '/atelier/categorie/', $url );
        }
        return $url;
    }
    add_filter( 'msls_options_get_permalink', 'my_url_translator', 10, 2 );

    Thanks

  4. realloc
    Member
    Plugin Author

    Posted 10 months ago #

    It would be interesting to know what's in $url in the problematic case.

  5. realloc
    Member
    Plugin Author

    Posted 9 months ago #

    Is this problem resolved?

  6. lucaslem
    Member
    Posted 9 months ago #

    Hi, thank-you for follow-up; I have been away on holiday and back to this project today.

    No, the issue is not resolved however I am unsure how to answer your question.

    I will try to reiterate the problem here:

    Starting from english:
    domain.dev/workshop/category/youth/
    I click the language switcher which takes me to french:
    fr.domain.dev/atelier/categorie/jeunes/
    Which is the desired outcome.

    From there if I click on the switcher again to go back to english custom category, rather than being take back to the expected domain.dev/workshop/category/youth/, it takes me to domain.dev/atelier/categorie/youth, and obviously a 404 page.

    So while the actual category changes back correctly ("jeunes" goes back to "youth"), the rest of the URL does not goes back from "atelier/category" to "worskhop/category". From English -> French is no problem, but the other direction does not work.

    For the sake of clarification, this is not specific to only "youth", but all custom categories.

    Thank-you for any pointers on where I am going wrong.

  7. lucaslem
    Member
    Posted 9 months ago #

    I think I may have an idea looking at my code above in my my_url_translator function, which specifies the url replacement from english to french, but perhaps I need also specify from french back to english. I am learning php as I go and I am unsure of this is a case of "multiple if statements" or "else if" but either way I am getting errors. Here is what I am attempting and obviously getting errors:

    function my_url_translator( $url, $language ) {
    	if ( 'fr_FR' == $language ) {
    	    $url = str_replace( '/workshop/category/', '/atelier/categorie/', $url );
        }
        return $url;
    
        }
        if ('fr_FR' !== $language) {
    	    	$url = str_replace( '/atelier/categorie/', '/workshop/category/', $url );
    	    }
    	    return $url;
    }
    add_filter( 'msls_options_get_permalink', 'my_url_translator', 10, 2 );

    Thanks

  8. realloc
    Member
    Plugin Author

    Posted 9 months ago #

    Hi,

    the presence of the first return is problematic... Try this:

    function my_url_translator( $url, $language ) {
        if ( 'fr_FR' == $language ) {
            $url = str_replace(
                '/workshop/category/',
                '/atelier/categorie/',
                $url
            );
        }
        else {
            $url = str_replace(
                '/atelier/categorie/',
                '/workshop/category/',
                $url
            );
        }
        return $url;
    }
    add_filter( 'msls_options_get_permalink', 'my_url_translator', 10, 2 );
  9. lucaslem
    Member
    Posted 9 months ago #

    Yes!! Thank-you so much for all your generous help customizing the functionality of your fantastic plugin Dennis. Is there a way to donate?

  10. realloc
    Member
    Plugin Author

    Posted 9 months ago #

    OK, very good. If you don't want to donate to Greenpeace - which would be great - consider my Amazon Wishlist. ;)

  11. realloc
    Member
    Plugin Author

    Posted 9 months ago #

    Thank you so much for your donation to Greenpeace, Lucas!

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.