<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>gj |</title>
	<atom:link href="https://blog.gaiterjones.com/category/wordpress/wordpress-multi-language/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.gaiterjones.com/category/wordpress/wordpress-multi-language/</link>
	<description>gaiterjones</description>
	<lastBuildDate>Fri, 14 Sep 2012 13:27:58 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.3</generator>
	<item>
		<title>WordPress MultiLanguage Support the Simple Way</title>
		<link>https://blog.gaiterjones.com/wordpress-multi-language-support/</link>
					<comments>https://blog.gaiterjones.com/wordpress-multi-language-support/#respond</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Fri, 14 Sep 2012 12:43:24 +0000</pubDate>
				<category><![CDATA[5 Minute Fix]]></category>
		<category><![CDATA[Language]]></category>
		<category><![CDATA[Marketing]]></category>
		<category><![CDATA[Wordpress Multi Language]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=796</guid>

					<description><![CDATA[WordPress is a great multilanguage CMS, for a while I thought of it purely as a blogging tool but now I use it all the time when I need to...<a class="more-link" href="https://blog.gaiterjones.com/wordpress-multi-language-support/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<p><img decoding="async" class="hang-2-column     alignnone" title="Wordpress Multilanguage Support" src="http://www.ideecon.com/wp-content/uploads/2011/12/wordpresslanguages.png" alt="" width="180" height="180" />WordPress is a great multilanguage CMS, for a while I thought of it purely as a blogging tool but now I use it all the time when I need to build a quick and effective marketing site. If you find a theme that you like and is adaptable you can put together a professional, great looking site that is easy for you or your clients to maintain in very little time.</p>
<p>Getting WordPress to work well with multi language content isn&#8217;t so straight forward, there are a lot of plugins available that offer multi language solutions but these seemed to be over complex for what I wanted.</p>
<p>My WordPress marketing sites are relatively simple with just a few pages used as marketing landing pages and stepping stones to e-commerce sites. I already created a simple method in PHP of detecting browser language and matching language to content in my pages however the WordPress frontend language remained in the default language of the installation. I did not want to modify core template files within WordPress as this makes upgrading difficult so after wasting time with Plugins I developed a very simple solution that sets the WordPress interface language for each visitor based on their browser language.</p>
<p>The WordPress WP-CONFIG.php file holds the main configuration settings for your WordPress installation, a global PHP constant WPLANG is defined here that sets the admin and frontend interface language using standard <a href="http://www.gnu.org/software/gettext/manual/html_chapter/gettext_16.html#Country-Codes" target="_blank">country</a> and <a href="http://www.gnu.org/software/gettext/manual/html_chapter/gettext_16.html#Language-Codes" target="_blank">language </a>codes, the default if WPLANG is not specified is American English en-US.</p>
<p>WordPress language packs come in .mo files that are located in the WordPress wp-content/languages folder, they are named after the language code, i.e. en_US.mo, de_DE.mo etc.</p>
<p>By detecting the browser language of the visitor and then checking if a corresponding .mo file exists in the languages folder we can automatically switch the WordPress interface language to match the visitors browser language &#8211; nice!</p>
<p>Decide which languages you want to support and download the corresponding .mo files, you can find all the language files available in the WordPress language file repository here <a href="http://svn.automattic.com/wordpress-i18n/">http://svn.automattic.com/wordpress-i18n/</a> e.g. here are the German language files <a href="http://svn.automattic.com/wordpress-i18n/de_DE/branches/2.8/messages/" target="_blank">http://svn.automattic.com/wordpress-i18n/de_DE/branches/2.8/messages/</a></p>
<p>If your WordPress site does not have a wp-content/languages folder, create a new one and copy your language files into it. Note you should copy your default language file too.</p>
<p>Now edit the WP-CONFIG.php file in the root folder of your WordPress installation and find the WP-LANG constant definition and comment it out:</p>
<p>#define (&#8216;WPLANG&#8217;, &#8221;);</p>
<p>and below it paste in the following code</p>
<pre class="brush:php">/**
 * Set language and load language files
 */
function detectlanguage() {
    $langcode = explode(";", $_SERVER['HTTP_ACCEPT_LANGUAGE']);
    $langcode = explode(",", $langcode['0']);
    return $langcode['0'];
    }

function fileExists($fileName, $caseSensitive = true) {

    if(file_exists($fileName)) {
        return $fileName;
    }
    if($caseSensitive) return false;

    // Handle case insensitive requests            
    $directoryName = dirname($fileName);
    $fileArray = glob($directoryName . '/*', GLOB_NOSORT);
    $fileNameLowerCase = strtolower($fileName);
    foreach($fileArray as $file) {
        if(strtolower($file) == $fileNameLowerCase) {
            return $file;
        }
    }
    return false;
}	

$languageDefault='en_US';
$language = detectlanguage();

if (isset($_GET['set_lang'])) { $language = $_GET['set_lang']; }

$languageFile= 'wp-content/languages/'. str_replace('-','_',$language). '.mo';
$wpLanguageFile=fileExists($languageFile,false);

// check if WP language file exists for browser language
if ($wpLanguageFile) {
	$wpLanguageFile = basename($wpLanguageFile, '.mo');
	// language supported
	define ('WPLANG', $wpLanguageFile);
    //echo "Language - $language detected. Language file exists and is supported."; 
} else {
	// language not supported default to EN
    //echo "Language - $language detected. Language file does not exist - defaulting to $languageDefault."; 
	define ('WPLANG', $languageDefault);
}</pre>
<p>Save the file and test. You can force the language selection by specifying it in the URL, i.e. http://yourwordpresssite.com/?set_lang=de_DE which will force the interface language to German if you have the German language files installed. Uncomment the echo&#8217;s and you will see the language selection confirmed.</p>
<p>If all is working well the WordPress interface language will now switch to the browser language of your visitors.</p>
<p>Note that this will only change the language of the built in WordPress interface in the frontend or backend. Your content language will not change, you need to create a <a href="http://www.catswhocode.com/blog/how-to-make-a-translatable-wordpress-theme" target="_blank">translation system</a> for your content using portable object files, or alternatively use the Google translation tool.</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/wordpress-multi-language-support/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
