ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

URI Language Identifier

April 09, 2008 11:45pm

Subscribe [14]
  • #31 / Apr 20, 2008 9:12am

    lonnrot

    8 posts

    OK. You are using a .htaccess rule.
    If you don´t use an .htacces rule you will obtain a url like this:
    http://example.com/index.phpen
    and you should modify the library to place a ‘/’ between index.php and language uri.
    Can I suggest that this little advice could be added to wiki?
    But now I get this error message:

    An Error Was Encountered

    Unable to load the requested language file: language/spanish_lang.php

    or english,etc..

  • #32 / Apr 20, 2008 6:45pm

    wiredesignz

    2882 posts

    Thanks for that tip, I’ll add it to the next update.

    Also language files need to be located in their own directory:
    ie: language/spanish/spanish_lang.php

  • #33 / Apr 20, 2008 11:25pm

    wiredesignz

    2882 posts

    Version 0.10 is available on the wiki.

    Added checks and code adjustments for $config[‘index_page’] being set.

  • #34 / Apr 21, 2008 4:17am

    tchule

    14 posts

    It is strange, I am using the URI Language Identifier on two websites, both of which also use Validation with no problems.

    However you might need to make sure the form action is using site_url() and not base_url()

    OK, I probably have missed something.

    I’ve tried with site_url(), but I see no difference in the result and in the HTML code generated. So I’ve tried to add manually in the post URL the beginning /en between the site_url and my controller name and this solves the problem.

    So I think that the site_url() helper function does not add the language to the URL string like it should. I’ve used a fresh CI 1.6.1 install and I think I’ve followed the wiki link.

    Regards,

    Tchule

  • #35 / Apr 21, 2008 4:27am

    tchule

    14 posts

    Some more informations about my problem, In fact the URL I call to view my form is something like “localhost/myapp/mycontroller”.

    When the form page is shown on the browser, it as been redirected to “localhost/myapp/fr/mycontroller”, despite the fact that the “fr” abbreviation should be ignored.

    $config['lang_ignore'] = "fr";

    The generated form validation URL is “localhost/myapp/mycontroller/validate”. When called like this, the content of the post is empty.

    If I manually change the URL to “localhost/myapp/fr/mycontroller/validate”, the validation works fine.

    Tchule.

  • #36 / Apr 21, 2008 4:37am

    wiredesignz

    2882 posts

    @tchule, The language abbreviation is added to the $config[‘index_page’] value and site_url() uses this value, whereas base_url() does not. You may not see a difference in the rendered url if index_page value is blank, but it is important.

    Please post your config settings for base_url, index_page and all those for language.

  • #37 / Apr 21, 2008 5:11am

    wiredesignz

    2882 posts

    Version 0.11 is available on the wiki.
    Corrected a bug with redirect

  • #38 / Apr 21, 2008 5:50am

    tchule

    14 posts

    @tchule, The language abbreviation is added to the $config[‘index_page’] value and site_url() uses this value, whereas base_url() does not. You may not see a difference in the rendered url if index_page value is blank, but it is important.

    Please post your config settings for base_url, index_page and all those for language.

    Hello wiredesignz, and thanks for your reply.

    Here are my settings:

    $config['base_url']    = "http://localhost/myapp/";
    
    $config['index_page'] = "";
    
    $config['language'] = "french";
    
    //default language abbreviation
    $config['language_abbr'] = "fr";
    
    //set available language abbreviations
    $config['lang_uri_abbr'] = array("fr" => "french", "en" => "english");
    
    //ignore this language abbreviation
    $config['lang_ignore'] = "fr";
  • #39 / Apr 21, 2008 5:57am

    wiredesignz

    2882 posts

    Ok. I have never tested what happens if you try to ignore the default language.

    Looking at the code it seems like it will always cause a redirect after rebuilding the url to include the default abbreviation.

    It seems to me that it should probably load the default language and ignore the url. I’ll do some tests. Thanks.

  • #40 / Apr 21, 2008 7:13am

    tchule

    14 posts

    OK, thanks.

    In the meantime, I’ve desactivated the ignore parameter and it works fine.

    A little proposal (it’s probably not the best thread to discuss it), i’ve changed the line method of the Language library in order to identify on the web site what strings have to be translated by adding some “[]”.

    /**
         * Fetch a single line of text from the language array
         *
         * @access    public
         * @param    string    the language line
         * @return    string
         */
        function line($line = '')
        {
            return ($line == '' OR ! isset($this->language[$line])) ? '['.$line.']' : $this->language[$line];
        }

    Tchule.

  • #41 / Apr 21, 2008 7:33am

    wiredesignz

    2882 posts

    Version 0.12 is available on the wiki.

    Fixed issues with using default language ignore. Thanks tchule 😉

  • #42 / Apr 21, 2008 8:09am

    tchule

    14 posts

    Nice, works fine.

    Thanks for your work Wiredesignz, it’s a cool extension.

    Tchule.

  • #43 / Apr 21, 2008 8:20am

    wiredesignz

    2882 posts

    No worries, you’re welcome. 😊

  • #44 / Apr 30, 2008 1:14pm

    lonnrot

    8 posts

    I have been working with your (fantastic) extension, but I needed to display links to the content in alternative languages, so I wrote this little helper. I have been testing it and it works without problems, but I am new in codeigniter so I am sure that it can be improved.
    You can see it in action in Agro-forestal
    Here it goes
    add to the config a few lines like this:

    //language descriptions
    $config['lang_desc']=array("es"=>"Versión en español",
                               "en" => "English version",
                               "gl" => "Versión en galego");

    Place this file in your application
    MY_url_helper.php

    <?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
    /**
    * Alternative languages helper
    *
    * Returns a string with links to the content in alternative languages
    *
    * version 0.2
    * @author Luis <[email protected]>
    */
    
    function alt_site_url($uri = '')
    {
        $CI =& get_instance();
        $actual_lang=$CI->uri->segment(1);
        $languages=$CI->config->item('lang_desc');
        $ignore_lang=$CI->config->item('lang_ignore');
        if (empty($actual_lang))
        {
            $uri=$ignore_lang.$CI->uri->uri_string();
            $actual_lang=$ignore_lang;
        }
        else
        {
            if (!array_key_exists($actual_lang,$languages))
            {
                $uri=$ignore_lang.$CI->uri->uri_string();
                $actual_lang=$ignore_lang;
            }
            else
            {
                $uri=$CI->uri->uri_string();
                $uri=substr_replace($uri,'',0,1);
            }
        }
        $alt_url='';
        foreach ($languages as $lang=>$lang_desc)
        {
    
             if ($actual_lang!=$lang)
             {
                $alt_url.='<a href="http://example.com/mycontroller/myfunction/%22&gtconfig-&gtslash_item%27base_url%27">http://example.com/es/mycontroller/myfunction/</a>.  This is what  you will obtain:
    <pre><code><div id="alternative_languages">
    <a ]English version[/url]
    
    <a href="http://example.com/gl/mycontroller/myfunction/">Versión en galego</a>
    
    </div>

    Errors? sugestions?.

  • #45 / Apr 30, 2008 7:56pm

    wiredesignz

    2882 posts

    Good work. Add your helper to the URI Language Identifier wiki article. 😉

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases