Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HOW TO: I18N Plugin + Fancy URLs + Lighttpd + Multilingual
#1
I installed I18N plugin v2.5.1 on a clean installation of GetSimple 3.0 on top of lighttpd. I enabled mod_rewrite and enabled the 10-getsimple.conf.

Instructions

For a language selector on top of every page
OPEN theme/theme-name/header.php
ADD inside wrapper div
Code:
<!-- language selection -->
                <div class="language-selector">
                <a href="<?php echo htmlspecialchars(return_i18n_setlang_url('gr')); ?>">Greek</a> | <a href="<?php echo htmlspecialchars(return_i18n_setlang_url('en')); ?>">English</a><br/>
                </div>

FIND
Code:
echo find_url('index',null);
REPLACE WITH
Code:
echo (function_exists('find_i18n_url') ? find_i18n_url('index',null) : find_url('index',null));

OPEN plugins/i18n_base/frontend.class.php
FIND
Code:
public static function getURL($slug, $slugparent, $language=null, $type='full') {
    global $url, $parent, $PERMALINK, $PERMALINK_ORIG;
AFTER, ADD
Code:
$PERMALINK_ORIG = isset($PERMALINK_ORIG) ? $PERMALINK_ORIG : $PERMALINK;

FIND inside function getFancyLanguageUrl
Code:
global $SITEURL, $PERMALINK_ORIG, $language;
REPLACE WITH
Code:
global $SITEURL, $PERMALINK, $PERMALINK_ORIG, $language;
    $PERMALINK_ORIG = isset($PERMALINK_ORIG) ? $PERMALINK_ORIG : $PERMALINK;

OPEN admin/edit.php
FIND
Code:
echo '<a href="', find_url($url, $parent) ,'" target="_blank" accesskey="', find_accesskey(i18n_r('VIEW')), '" >', i18n_r('VIEW'), ' </a>';
REPLACE WITH
Code:
if(strpos($url, '_') !== false){
                    $language = explode('_', $url);
                    $language = $language[count($language)-1];
                    if(strlen($language) == 2){
                        $url2 = substr($url, 0, -3);
                    }
                }
                $language = ($language) ? $language : return_i18n_default_language();
                echo '<a href="', (function_exists('find_i18n_url') ? find_i18n_url($url2, $parent, $language) : find_url($url2, $parent)) ,'" target="_blank" accesskey="', find_accesskey(i18n_r('VIEW')), '" >', i18n_r('VIEW'), ' </a>';

Finally, enable mod_rewrite in lighttpd.conf and enable the usage of the following conf.

10-getsimple.conf
Code:
$HTTP["host"] =~ "(^|www\.)example\.com$" {

    # Deny access to the backups, data and plugins directories...
    $HTTP["url"] =~ "^/gs/(backups|data|plugins)/" {
        # ...except the uploads, thumbs and every css, js, or images directory inside plugins
        $HTTP["url"] !~ "^/gs/(data/(uploads|thumbs)|plugins/(.*?/)(css|js|images))/?" {
            url.access-deny = ("")
        }
    }

    # Disable directory listing
    $HTTP["url"] =~ "^/gs($|/)" {
        dir-listing.activate = "disable"
    }

    
    # Use mod_rewrite for fancy URLS
    url.rewrite-if-not-file = (
        "^/gs/(en|gr)/(.*?/)?([A-Za-z0-9_-]+)/?$" => "/gs/index.php?id=$3&lang=$1",
        "^/gs/(en|gr)/?$" => "/gs/index.php?lang=$1",
    )
    

    $HTTP["url"] =~ "^/gs/?$" {
        url.redirect = (
            # Optional
            "/" => "http://www.example.com/gs/en/"
        )
    }
}

NOTE: If your GetSimple installation directory is / instead of /gs/ that I used in this example, simply search and replace all instances of /gs (without trailing slash)
NOTE 2: In this example I have only used, two languages, English and Greek. You can add as many as you want, as long as their identifier is 2 characters long and you make the appropriate changes to theme/theme-name/header.php and 10-getsimple.conf.

Have fun!!
Reply
#2
Could you tell us what you are trying to achieve with these patches?

The I18N plugin already supports fancy URLs and the language within the URL as described here.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#3
What I achieved is lighttpd correct configuration for url-rewrite with multilingual support.

The first to make GetSimple url-rewrite compatible, is Reed Murphy (link), but for one language websites.

The above mods/patches allow you to have urls such as
Code:
http://example.com/en/contact
http://example.com/gr/contact/map
etc
and change from one language to another without messing with ?setlang=en or ?lang=en flags.

Totally clean URLs, SEO friendly.
Reply
#4
intelx86 Wrote:The above mods/patches allow you to have urls such as
Code:
http://example.com/en/contact
http://example.com/gr/contact/map
etc
and change from one language to another without messing with ?setlang=en or ?lang=en flags.

???
You don't need to patch the I18N plugin to do this!
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#5
You are partially right. I hadn't added correct Custom Permalink Structure:
Code:
%language%/%parent%/%slug%/
Even so, inside the admin pages, both at "Page overview" and at "Edit page", the #/View links supplied by I18n are dead, so the patches for plugins/i18n_base/frontend.class.php and admin/edit.php are necessary.

I modified the patches in the first post.

I used I18n because I needed a multi-level multi-lingual site. I don't know if it was a bad choice. I am open to suggestions.
Reply
#6
intelx86 Wrote:I used I18n because I needed a multi-level multi-lingual site. I don't know if it was a bad choice. I am open to suggestions.

That's fine, as this is exactly what the I18N plugin is designed to do.

I corrected the page and edit links in version 2.5.4 (there is now no need to patch admin/edit.php), please check if it works. (the parent is not always set correctly in the admin links, but that should not matter)

Thanks for pointing out the problems.
But in future you might want to post the problems (and patches) first in the plugin's forum thread, so that I (or for other plugins the plugin developer) can fix the bugs and thus make it much easier for others. They won't need to patch the plugin and won't have problems updating the plugin or GetSimple.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#7
P.S.: if you use return_i18n_setlang_url without a check (i.e. assuming I18N is installed) in the template you don't need to check for function_exists('find_i18n_url') later on.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#8
I am having an issue with the I18N Search and lighttpd. When I do a search the url is /slug/?lang=en. Lighttpd is not happy with this. I only have one language and I am just using it as a search/news/blog page. Any suggestions for my Lighttpd config?

I have used the examples here http://www.reedmurphy.net/post/getsimple...d-lighttpd the rest of the permalinks work fine, just the links from the search are not working.

Thanks.
Reply
#9
coolcash Wrote:I am having an issue with the I18N Search and lighttpd. When I do a search the url is /slug/?lang=en. Lighttpd is not happy with this. I only have one language and I am just using it as a search/news/blog page. Any suggestions for my Lighttpd config?

The language parameter is added, if you use the I18N plugin.
But you can switch it off, if you have only one language, by adding the parameter i18n=0 to the search results call, e.g.
Code:
(% searchresults i18n=0 %)
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply




Users browsing this thread: 1 Guest(s)