Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hello

    I think you’re more of a developer than you give yourself credit for, especially with at least finding and applying that codepile snippet. Chances are with that part, it’s not receiving that the queries should include the recipe, when doing the translated version. However, how to potentially intercept those or at least detect them, would be more on the polylang support side than ours.

    Regarding the rest and internationalization as a whole, as you can see it’s a known weak spot simply because of the fact that we store our values/options in the database, nice and hardcoded and not translatable. We’re not sure exactly how to help that yet.

    Looking at my personal github account, and I have https://github.com/tw2113/custom-post-type-ui-i18n started, but it’s just the skeleton starter point. I believe my idea was to either copy/paste all the available label fields or somehow dynamically fetch them, and provide UI to choose the language to translate to and then fields to fill in the translations for. Technically it’d still be saving to a database, but it would be able to be filtered in by current language as well, since each version would get saved :D. At least that is the idea behind that start.

    That said, I wonder if simply providing a __( ‘recipe’, ‘some-slug’ ) spot that can be then filtered in, or simply filtering in the translated version would do.
    Does polylang offer a way to get the current language, that you know of?

    I know we have this filter available:

    /**
     * Filters the arguments used for a post type right before registering.
     *
     * @since 1.0.0
     * @since 1.3.0 Added original passed in values array
     *
     * @param array  $args      Array of arguments to use for registering post type.
     * @param string $value     Post type slug to be registered.
     * @param array  $post_type Original passed in values for post type.
     */
    $args = apply_filters( 'cptui_pre_register_post_type', $args, $post_type['name'], $post_type );
    

    and I’m mulling over the idea of something like this:

    karinaglf_filter_post_type( $args, $slug ) {
        if ( 'reciple !== $slug ) {
            return $args;
        }
    
        $args['rewrite']['slug'] = ( 'br' === get_current_locale() ) ? 'receita' : 'recipe';
    
        return $args;
    }
    add_filter( 'cptui_pre_register_post_type', 'karinaglf_filter_post_type', 10, 2 );
    

    Not tested, and I’m not sure how readily get_current_locale() may or may not exist, but I hope I have at least given a general idea of how to possibly approach.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Any further questions or new developments @karinaglf ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Slugs withs Polyang’ is closed to new replies.