WordPress.org

Forums

Contact Form Clean and Simple
[resolved] Change language without redefining 'WPLANG' (6 posts)

  1. fatbones
    Member
    Posted 1 year ago #

    Hello Meg,

    I would like to know how could I define a language file without changing the define('WPLANG',") in wp-config.php. I want my WP to be in english but need the messages in the frontend to be shown in spanish.

    Thank you so much for your incredibly work!

    https://wordpress.org/plugins/clean-and-simple-contact-form-by-meg-nicholas/

  2. megnicholas
    Member
    Plugin Author

    Posted 1 year ago #

    Hi there, sorry for the delay getting back, this was a bit of a head scratcher. In WP, plugins are loaded before themes so it wasn't as easy as I thought.

    If you add this code to the bottom of functions.php in your theme the language should be changed to spanish:

    function cscf_change_language( $locale, $domain ) {
        if ( $domain == 'cleanandsimple') {
            return 'es_ES';
        }
        else {
            return $locale;
        }
    }
    add_filter( 'plugin_locale','cscf_change_language',10,2);
    if (class_exists('CSCF')) {
        $cscf = new CSCF;
        $cscf->RegisterTextDomain();
    }

    Basically at this point the language file has already been loaded, so we have to load it again, changing the language via a filter.

    The settings screen for the plugin will also be in Spanish, but there is no avoiding this unfortunately.

  3. fatbones
    Member
    Posted 1 year ago #

    Worked perfectly!
    Thank you so much, Meg.

  4. fatbones
    Member
    Posted 1 year ago #

    Oops, I've noticed that the settings screen appears duplicated.
    Watch in on: http://es.tinypic.com/r/23ljsk4/8

    Regards.

  5. megnicholas
    Member
    Plugin Author

    Posted 1 year ago #

    Hi There,

    Try this code instead:

    function cscf_change_language( $locale, $domain ) {
        if ( $domain == 'cleanandsimple') {
            return 'es_ES';
        }
        else {
            return $locale;
        }
    }
    add_filter( 'plugin_locale','cscf_change_language',10,2);
    if (class_exists('CSCF')) {
        load_plugin_textdomain('cleanandsimple', false, 'clean-and-simple-contact-form-by-meg-nicholas/languages');
    }
  6. fatbones
    Member
    Posted 1 year ago #

    Now it's Ok.
    Thank you Meg.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic