2011-12-04, 13:58:18
I would need one thing to get along with GetSimple: theme localization.
You can check out a working example of how I did it: http://http:getsimple.mechantdesign.com/
Look at how I've worked it out:
1) Define localization variable in gsconfig.php:
/* Expected urls have now the following form: http://example.com/fr_FR/ */
**********
2) Changing the .htaccess rewrite rule to:
/* This will send the whole query string to index.php. This can be helpful for many other things too. */
**********
3) Do a little bit more parsing in index.php:
/* We now have a very informative array that we'll break down differently depending on if the the theme I18L is true */
/* Another function should be use to associate .../fr/ to .../fr_FR/ */
**********
4) Create a language hierarchy in the data/pages folder, so that we would have both of these pages:
en_US/i-love-get-simple.xml & fr_FR/i-love-get-simple.xml
**********
5) Modify the "get_navigation" function in admin/inc/theme_functions.php to change "$path":
/* At the very top of the function... */
**********
6) Modify the "find_url" function in admin/inc/basic.php to change output:
/* At the top of the function... */
**********
6) Create a special function, ressembling the "find_url" function in admin/inc/basic.php to change output the same page in other languages:
/* This function is a quick fix... a lot needs to be done to make it more versatile */
****************************************
ON THE SIDE:
I would also suggest to redirect url without trailing slashe to a with-slash url using the following .htaccess rule, as some search engine may consider these 2 pages as distinct (yet identical) and mark them as duplicated content.
****************************************
Please let me know what you think of the code! I haven't check for all the admin stuff, but I don't think it will be very complicated. It's really all I need to choose GetSimple as my CMS for my next project
Please, I need feedback!
Thank you!
You can check out a working example of how I did it: http://http:getsimple.mechantdesign.com/
Look at how I've worked it out:
1) Define localization variable in gsconfig.php:
Code:
define('GSTHEMEI18N', 'true');
/* Expected urls have now the following form: http://example.com/fr_FR/ */
**********
2) Changing the .htaccess rewrite rule to:
Code:
RewriteRule ^(.*)$ index.php?id=$1 [QSA,L]
/* This will send the whole query string to index.php. This can be helpful for many other things too. */
**********
3) Do a little bit more parsing in index.php:
Code:
if (isset($_GET['id'])) {
$PAGE_REQUEST = $_GET['id'];
if (substr($PAGE_REQUEST, -1) == '/') {
$PAGE_REQUEST = rtrim($PAGE_REQUEST, '/');
}
$PAGE_REQUEST = explode('/', $PAGE_REQUEST, 3);
} else {
$id = "index"; //btw, why here you use double quote here ?
}
/* We now have a very informative array that we'll break down differently depending on if the the theme I18L is true */
Code:
if (GSTHEMEI18N) {
if (count($PAGE_REQUEST) == 1) {
$LANG = $PAGE_REQUEST[0];
$id = 'index';
} if (count($PAGE_REQUEST) > 1) {
$LANG = $PAGE_REQUEST[0];
$id = end($PAGE_REQUEST);
} else {
$id = 'index';
}
}
/* Another function should be use to associate .../fr/ to .../fr_FR/ */
Code:
# define page, spit out 404 if it doesn't exist
$file = GSDATAPAGESPATH . $LANG . '/' . $id .'.xml';
...
**********
4) Create a language hierarchy in the data/pages folder, so that we would have both of these pages:
en_US/i-love-get-simple.xml & fr_FR/i-love-get-simple.xml
**********
5) Modify the "get_navigation" function in admin/inc/theme_functions.php to change "$path":
/* At the very top of the function... */
Code:
//right here
if (GSTHEMEI18N) {
global $LANG;
$path = GSDATAPAGESPATH . $LANG . '/';
}
//done
$dir_handle =...
...
**********
6) Modify the "find_url" function in admin/inc/basic.php to change output:
/* At the top of the function... */
Code:
if ($type == 'full') {
$full = $SITEURL;
//right here
if (GSTHEMEI18N) {
global $LANG;
if (!isset($link_lang)) $link_lang = $LANG;
$full .= $link_lang . '/';
}
//done
} elseif($type == 'relative') {
...
**********
6) Create a special function, ressembling the "find_url" function in admin/inc/basic.php to change output the same page in other languages:
Code:
function find_local_current_url($link_lang) {
global $SITEURL;
$full = $SITEURL;
$slug = get_page_slug(false);
if ($slug != '') $slug .= '/';
$parent = get_parent(false);
if ($parent != '') $parent .= '/';
if (GSTHEMEI18N) {
global $LANG;
if (!isset($link_lang)) $link_lang = $LANG;
$full .= $link_lang . '/';
}
$full .= $parent . $slug;
return $full;
}
/* This function is a quick fix... a lot needs to be done to make it more versatile */
****************************************
ON THE SIDE:
I would also suggest to redirect url without trailing slashe to a with-slash url using the following .htaccess rule, as some search engine may consider these 2 pages as distinct (yet identical) and mark them as duplicated content.
Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]
****************************************
Please let me know what you think of the code! I haven't check for all the admin stuff, but I don't think it will be very complicated. It's really all I need to choose GetSimple as my CMS for my next project
Please, I need feedback!
Thank you!