I am currently working on a wordpress site that should be offered in French. I found a way to get the theme to work with fr_FR po and mo files when I add the querystring variable l. i.e.
site.tldwill give a vanilla English site, and site.tld/?l=fractivate the following code in my .php functions for translating a French translation:
<?php
add_filter( 'locale', 'set_my_locale' );
function set_my_locale( $lang ) {
if ("fr" == substr(strtolower(trim(strip_tags(stripslashes($_GET['l'])))), 0, 2)) {
return "fr_FR";
} else {
return $lang;
}
}
?>
this setting is already working. my question is: how can I rewrite url, so instead site.tld/?l=frI can just add the folder structure using frie site.tld/fr/?
, site.tld/portoflio/autumn/ , site.tld/fr/portfolio/autumn/ . - Apple, .
htaccess:
RewriteBase /
RewriteCond ^[a-z]{2}/
RewriteRule ^([a-z]{2})/(.*)$ /$2?l=$1 [R,L]
, R, - 404, isntead. , , wordpress 'rewrite, . Month and name (/%year%/%monthnum%/%postname%/) .
: wordpress /fr/ - //etc?
? ? , - WISE, , NICE. http://pmg.co/a-mostly-complete-guide-to-the-wordpress-rewrite-api, .:/
UPDATE: , , @relu :
, .htaccess
i @relu, , Relu /fr:
<?
add_action( 'init', 'pmgtut_add_rewrites' );
function pmgtut_add_rewrites() {
add_rewrite_rule( '^([a-z]{2})/?$', 'index.php?l=$matches[1]', 'top' );
add_rewrite_rule( '^([a-z]{2})/(.*)$', 'index.php?l=$matches[1]&q=$matches[2]', 'top' );
}
add_filter( 'query_vars', 'pmgtut_query_vars', 10, 1 );
function pmgtut_query_vars( $vars ) {
$vars[] = 'l';
return $vars;
}
?>
/fr , , :
Wordpress . , &q=$matches[2];
. , l, echo 'l: $l'; $l = get_query_var('l'); : l: l: fr . locale ? , , queryvar, , , l: fr .. '.
aaaah help.
: qtranslate. , . y'all, esp @relu stayin pow'r.