• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Beginner Qs: Nav structure and internationalization

#1
[eluser]rufisgumbo[/eluser]
My website has 3 levels of hierarchy so at present I've created a view file for each level (nav, sub_nav...)

The view files then contain arrays of links like this:


nav_view.php
Code:
<?
$links = array(    
            'home'        => 'Home',
            'general'        => 'General Information',
            'about'        => 'About Acme Co',
            'contact'        => 'Contact Us'
    );
?>

<nav>
    <ul>
        &lt;?php foreach($links as $link=>$linkName){ ?&gt;
        <li class="&lt;?php echo $link ?&gt;&lt;?php if($sectionName == $link){ ?&gt; on&lt;? } ?&gt;"><a href="&lt;?php echo base_url() . $link ?&gt;/">&lt;?php echo $linkName ?&gt;</a></li>
        &lt;?php } ?&gt;
    </ul>
</nav>

And I use the URI class to determine active links for highlighting.


1. Would I be better combining all of these arrays into one controller file or defining them in a config file?, keeping just the output loop in the view.

2. I want to add translations for the nav items, what would be the best way to do that? in terms of structuring it and where best to define.

#2
[eluser]Alur[/eluser]
As for the translations, you should have a look at the language class.

I use it together with the URI Language Identifier to build mulilanguage sites.

#3
[eluser]rufisgumbo[/eluser]
Thanks I will use the uri language identifier

As for the language class, I did look at that first but thought it was more for defining random words and lines of text that are used commonly throughout the site

You're saying that I could keep my nav how it is but essentially define a new nav_lang file for each language containing translations of all the links? Then I'd need to autoload that and pull in the relevant lines at the controller level and pass to the view?

In past on non-code igniter projects I've setup one class like this

Code:
class Link{
 var $name = array();  
 var $url;
 var $links = array();

 function add_link($links){
    $this->links[] = $links;
  }
}

$all_sections = array();

$section                = new Link();
$section->name['en']    = "Home";
$section->name['fr']]    = "Uberdurky";
$section->url           = "/";

    $sub_section                = new Link();
    $sub_section->name['en']    = "About Acme Ltd";
    $sub_section->name['fr']    = "Fabuka Acme Ltd";
    $sub_section->url           = "/about/";
$section->add_link($sub_section);

Then I have a function to loop through and output the nav, which just looks at the current name[Lang] as defined by session or URL

This actually seems less overhead than having a bunch of Lang files because both the nav structure and translations are defined in one place. But I'm new to CI so I might be misunderstanding the proposed approach... ?

#4
[eluser]rufisgumbo[/eluser]
No other thoughts? so everyone just does something like this?

korean_lang.php:

Code:
// main nav
    $lang['home'] = "한국어";
    $lang['products'] = "조선말";
    ..

    // products subnav
    $lang['shoes'] = "조선말";
    $lang['fruit'] = "한국어";
    ..

And then in my controller:
Code:
$this->lang->load('korean_lang', 'korean');

in view:
Code:
$this->lang->line('home');


Just seems very drawn out and a lot of overhead.... ?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.