Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
COMPLETE Theme I18N (HERE'S THE CODE)
#1
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:

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 Smile

Please, I need feedback!

Thank you!
Reply
#2
I feel like this would be a great addition if we ever add mvcek's plugin to the core... This would be a great starting point to add it in. Thanks for the tutorial... i'm sure it will help many people here!
- Chris
Thanks for using GetSimple! - Download

Please do not email me directly for help regarding GetSimple. Please post all your questions/problems in the forum!
Reply
#3
Hi Chris,
Thanks for the reply !
Can you tell me what exactly do you refer to when you write mvcek's plugin?
Reply
#4
lacroixca Wrote:Hi Chris,
Thanks for the reply !
Can you tell me what exactly do you refer to when you write mvcek's plugin?

The I18N plugin does all this and more without patching the GetSimple core.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply




Users browsing this thread: 1 Guest(s)