• Resolved Vivienne

    (@viviennevv)


    Hi all,
    I’m using the following code in my functions.php file to show my website in Dutch, but keep my administration pages in English:

    function custom_set_my_locale($locale) {
    	$locale = ( !is_admin() ) ? "nl_NL" : $locale;
    	return $locale;
    }
    add_filter( 'locale', 'custom_set_my_locale' );

    Everything seems to work as it should on the frontend (language_attributes() method returns lang=”nl-NL”, etc.). The only thing is that dates aren’t translated and are still shown in English. I’ve tried using the date_i18n() method, but no luck.
    When I look at the $wp_locale variable all terms are still in English. As this global variable handles the date locales, I’m thinking herein lies the problem. How can I make it so that the terms in this variable are also translated into Dutch on the frontend? Any help would be appreciated.

    NB. I’ve added the language files from the Dutch WordPress version to the wp-content/languages folder. When I select ‘Nederlands’ as site language in the general settings, $wp_locale has the correct Dutch terms.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Vivienne

    (@viviennevv)

    Did I ask this question in the wrong thread? If so, could someone please point me to the right one? I’m aware there’s a plugin ‘Admin to English’ that I can use, but I’d really like to know why the code above doesn’t work. Thanks!

    Thread Starter Vivienne

    (@viviennevv)

    OK, to close this thread with a solution: I was able to make this code work by placing it in a separate file. I then placed that file in the wp-content/mu-plugins folder (you might need to create that folder). Apparently files in that folder get loaded before all else. The locale is now correct for the $wp_locale variable as well and dates are translated correctly.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘$wp_locale keeps English terms even though locale is set to nl_NL’ is closed to new replies.