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

Multilingual with Polylang #16

Open
samikeijonen opened this issue Jan 11, 2023 · 1 comment
Open

Multilingual with Polylang #16

samikeijonen opened this issue Jan 11, 2023 · 1 comment

Comments

@samikeijonen
Copy link
Member

Dates and translated strings doesn't work out of the box.

/**
 * Filters the locale ID of the WordPress installation based on Polylang language.
 *
 * @param string $locale The locale ID.
 */
function set_correct_language( $locale ) {
    // Return current language or original language.
    return function_exists( 'pll_current_language' ) ? pll_current_language( 'locale' ) : $locale;
}
add_filter( 'locale', __NAMESPACE__ . '\set_correct_language' );

Somehow we need to do this again :)

@samikeijonen
Copy link
Member Author

samikeijonen commented Mar 17, 2023

Remember to check is_admin so that this doesn't mess with plugins like Yoast.

/**
 * Filters the locale ID of the WordPress installation based on Polylang language.
 *
 * @param string $locale The locale ID.
 */
function set_correct_language( $locale ) {
    // Return current language or original language.
    if ( ! is_admin() ) {
        return function_exists( 'pll_current_language' ) ? pll_current_language( 'locale' ) : $locale;
    }

    return $locale;
}
add_filter( 'locale', __NAMESPACE__ . '\set_correct_language' );

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