• I’m developing a bilingual website. So the content is mostly in English and German. That is OK. But some texts like on buttons and messages for the user I don’t want to show in both languages as Next/Weiter or Read More / Weiterlesesen or Submit / Absenden etc.
    The best solution would be, if the browser of the user is set to German WPLANG should set to German otherwise leave the default setting in English.
    I guess it should be only some lines of code to do this – or not? Does anyone already has a solution for this? Or a link to an article?

    Any help appreciated
    Tom

    • This topic was modified 4 years, 5 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
Viewing 4 replies - 1 through 4 (of 4 total)
  • If you use a commercial plugin (wpml.org) and need support, please go to their official support channel. In order to be good stewards of the WordPress community, and encourage innovation and progress, we feel it’s important to direct people to those official locations.

    Forum volunteers are also not given access to commercial products, so they would not know why your commercial theme or plugin is not working properly. This is one other reason why volunteers forward you to the commercial product’s vendors. The vendors are responsible for supporting their commercial product.

    Thread Starter Tom

    (@tomybyte)

    Hi Fahim, you didn’t read my post above. I know WPML very well and I’m the owner of a lifetime licence. I could use WPML but that would be overkill. In this case I want a very small and lightweight solution. By the way WPML puts very much data in tables. I have another website using WPML, there is a table with a size bigger than 1 GByte. No – WPML is here absolutely no solution. But thank you for your time to answer.

    • This reply was modified 4 years, 5 months ago by Tom.
    Thread Starter Tom

    (@tomybyte)

    Maybe helpful for someone else too. This little code in my plugins function file does the trick:

    function maybe_set_locale_to_german( $locale ) {
    	$l =  t3c_get_user_lang();
    	if( $l=='de_DE' ){
    		$locale = 'de_DE';
    	}
    	return $locale;
    }
    add_filter( 'locale', 'maybe_set_locale_to_german', 1, 1 );
    
    function t3c_get_user_lang(){
        static $set_lang = '';
        
        $server_lang = filter_var( $_SERVER['HTTP_ACCEPT_LANGUAGE'], FILTER_SANITIZE_STRING );
        $browserlang = substr($server_lang, 0, 2);
            
        if( $browserlang == "de" ){
            $set_lang = 'de_DE';
        }
       return $set_lang;        
    }
    • This reply was modified 4 years, 5 months ago by Tom.

    Thanks so much Tom, for sharing the solution.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to set WPLANG by browser language’ is closed to new replies.