Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically Create Custom Post Type Translations #19

Open
codestic opened this issue Mar 16, 2015 · 0 comments
Open

Dynamically Create Custom Post Type Translations #19

codestic opened this issue Mar 16, 2015 · 0 comments

Comments

@codestic
Copy link

Hi guys,

first off thanks a lot for creating this plugin. It seems to have helped many people so far - so good Karma your way!

Now to my question
Maybe I misunderstood the way this plugin works, but for me in the current state it doesn't make much sense. I developed a theme that I use on on several sites. The theme includes many custom post type plugins that - until now - had a configurable "slug_rewrite" option using Advanced Custom Fields (ACF PRO). Now I want to make the rewrite slugs translatable, I do not want to translate them myself, but offer the option to translate them for every language.

This seems not to be supported, neither with this plugin nor with the capabilities within Polylang.

I managed to come up with an idea but basic testing tells me that this would be a terrible way of doing it, since Polylang would need to load ALL languages on ALL requests ALL the time (unless you cache it, but still). This of course is resource hungry and not a great way of doing this.

add_filter('pll_translated_post_type_rewrite_slugs', function($post_type_translated_slugs) {
    if (!isset($post_type_translated_slugs) || !is_array($post_type_translated_slugs)) {
        $post_type_translated_slugs = [];
    }

    global $polylang;
    $languages = $polylang->model->get_languages_list();

    foreach ($languages as $language) {
        $mo = new PLL_MO();
        $mo->import_from_db($language);

        $post_type_translated_slugs['test-cpt'][$language->slug] = [
            'has_archive' => true,
            'rewrite' => [
                'slug' => $mo->translate('testslug')
            ]
        ];
    }

    return $post_type_translated_slugs;
});

This works but cannot possibly be the intended way?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant