Commits

Anonymous committed 2c4c010

Multi language support.

Comments (0)

Files changed (3)

config/breadcrumb.php

 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
-/*
-* ------------------------
-* Config: set home
-* ------------------------
-* Default value:
-* $config['set_home'] = "Home";
-*
-* Change initial breadcrumb link
-*/
+/**
+ * --------------------------
+ * Config: Multi language
+ * --------------------------
+ * Default value:
+ * $config['multilang'] = FALSE;
+ * 
+ * If TRUE than replacer can be set to another language. See Config: Replacer below.
+ */
+$config['multilang'] = FALSE;
+
+/**
+ * ------------------------
+ * Config: set home
+ * ------------------------
+ * Default value:
+ * $config['set_home'] = "Home";
+ * 
+ * Change initial breadcrumb link
+ */
 $config['set_home'] = "Home";
 
-/*
-* ------------------------
-* Config: Delimiter
-* ------------------------
-* Default value:
-* $config['delimiter'] = ' > ';
-*/
+/**
+ * -----------------------
+ * Config: Delimiter
+ * ------------------------
+ * Default value:
+ * $config['delimiter'] = ' > ';
+ */
 $config['delimiter'] = " ";
 
-/*
+/**
  * --------------------------
  * Config: Replacer
  * --------------------------
  * =======
  * URL = http://localhost/arstock/warehouse/stocks/search_direct
  * $config['replacer'] = array('search_direct' => 'edit', 'warehouse' => array('/dept_list|departments', 'warehouse department'), 'stocks' => array('stocks', '/warehouse/action_list|actions'), 'edit' => array('edit', 'item 1', 'item_2|item 2'));
- * Breadcrumb = Home > Departments > Warehouse Department > Stocks > Actions > Edit > Item > Item 2
+ * Breadcrumb = Home > Departments > Warehouse Department > Stocks > Actions > Edit > Item 1 > Item 2
  * Departments' url 			= http://localhost/arstock/dept_list/
  * Warehouse Department's url 	= http://localhost/arstock/warehouse/
  * Stocks' url 					= http://localhost/arstock/warehouse/stocks
  * Actions' url 				= http://localhost/arstock/warehouse/action_list
  * Edit's url 					= http://localhost/arstock/warehouse/stocks/edit
- * Item's url 					= http://localhost/arstock/warehouse/stocks/edit
+ * Item 1's url 				= http://localhost/arstock/warehouse/stocks/edit
  * Item 2's url 				= http://localhost/arstock/warehouse/stocks/edit/item_2
+ * 
+ * 5. Multilanguage support (since version 9.10.1)
+ * 
+ * Example:
+ * ========
+ * Let's see an example on feature number 4. If you set $config['multilang'] = TRUE than your replacer should be change to:
+ * $config['replacer'] = array('search_direct' => 'edit', 'warehouse' => array('/dept_list|departments', 'warehouse_department'), 'stocks' => array('stocks', '/warehouse/action_list|actions'), 'edit' => array('edit', 'item_1', 'item_2|item_2'));
+ * and don't forget to add lang files as well, your breadcrumb_lang.php should contain variable that replace link name depend on language selected. For this example:
+ * lang['edit'] = 'some text';
+ * lang['departments'] = 'some text'; 
+ * lang['warehouse_department'] = 'some text';
+ * lang['stocks'] = 'some text';
+ * lang['actions'] = 'some text';
+ * lang['item_1'] = 'some text';
+ * lang['item_2'] = 'some text';
  */
+//$config['replacer'] = array();
 $config['replacer'] = array();
-
 /**
  * --------------------------
  * Config: Exclude
  * ---------------------
  * Default value:
  * $config['hide_number'] = TRUE;
+ * $config['hide_number_on_last_segment'] = TRUE;
  *
  * If set to TRUE then any number without a word in a segment will be hide.
  * 
  */
 $config['hide_number'] = TRUE;
 
+$config['hide_number_on_last_segment'] = TRUE;
+
 /**
  * -------------------------
  * Config: Strip characters
  * -------------------------
  * Default value:
- * $config['strip_characters'] =  array ('_', '-', '.html', '.php', '.htm');
+ * $config['strip_characters'] =  array('_', '-', '.html', '.php', '.htm');
  *
  * All characters in the array will be stripped from breadcrumbs
  * 
  * http://mysite.com/blog/7-habbits/request.html
  * will have breadcrumbs: Home > Blog > 7 Habbits > Request
  */
-$config['strip_characters'] = array ('_', '-', '.html', '.php', '.htm');
+$config['strip_characters'] = array('_', '-', '.html', '.php', '.htm');
 
 /**
  * ------------------------------------
  * Config: Strip by Regular Expression
  * ------------------------------------
  * Default value:
- * $config['strip_regexp'] =  array ();
+ * $config['strip_regexp'] =  array();
  *
  * All regular expression in the array will be stripped from breadcrumbs
  * 
  * set config to: $config['strip_regexp'] =  array ('/-[0-9]+.html/');
  * then we will have breadcrumbs: Home > Blog > 7 Habbits > Request
  */
-$config['strip_regexp'] = array ();
+$config['strip_regexp'] = array();
 
 /* End of file breadcrumb.php */
 /* Location: ./system/application/config/breadcrumb.php */

helpers/breadcrumb_helper.php

  * - Return the breadcrumb in a list (<ul><li></li></ul>) or something else.
  * - Auto link beauty.
  * - Can unlink last segment of breadcrumb.
+ * - Multilanguage support.
  *
  * Installation:
  * 1. Put breadcrumb_helper.php to application/helpers.
  * @subpackage	Helpers
  * @category	Helpers
  * @author          Ardinoto Wahono
- * @version         5.10.1
+ * @version         9.10.1
  * @copyright        Copyright (c) 2009-2010 Ardinoto Wahono, WAH-IT Web Division
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
     {
         $CI =& get_instance();
         $CI->load->helper('url');
+        $CI->lang->load('breadcrumb');
         $CI->config->load('breadcrumb');
 
         // Load configuration
         // If last segment is a number ?
         $show_last_number = -1;
         $number_array = count($uri_array_original);
-        $l_array = $number_array - 1; // last array number
-        if (preg_match("/^[0-9]/", $uri_array_original[$l_array]) AND ! preg_match("/[a-zA-Z]+/", $uri_array_original[$l_array]))
+        if (! $CI->config->item('hide_number_on_last_segment'))
         {
-            $show_last_number = $l_array;
+        	$l_array = $number_array - 1; // last array number
+        	if (preg_match("/^[0-9]/", $uri_array_original[$l_array]) AND ! preg_match("/[a-zA-Z]+/", $uri_array_original[$l_array]))
+        	{
+        		$show_last_number = $l_array;
+        	}
         }
 
         // Find segments uri that only contain a number
         $uri_array = $uri_array_original;
 
         // Change link name as mentioned on $replacer
-        $j = 0;
         foreach ($replacer as $key => $value)
         {
             if ($value && array_search($key, $uri_array_original))
             {
                 $key_uri = array_search($key, $uri_array_original);
+				
+                // Add multilanguage
+                if (! is_array($value) && $CI->config->item('multilang'))
+                {
+                	$value = ucwords($CI->lang->line($value));
+                }
+                
                 $replacement = array($key_uri => $value);
-                if ($j = 0)
-                {
-                    $uri_array = array_replace($uri_array_original, $replacement);
-                }
-                else
                 {
                     $uri_array = array_replace($uri_array, $replacement);
                 }
             }
-            $j++;
         }
 
         // Set wrapper
 
         // Begin writing breadcrumb string
         $init_link = $CI->config->item('set_home');
+        if ($CI->config->item('multilang'))
+        {
+        	$init_link = $CI->lang->line('set_home');
+        }
+        $init_link = $CI->lang->line('set_home');
         $str = $wrapper[0].$wrapper_inline[0].anchor('', $init_link).$wrapper_inline[1];
         $segment = '';
         $i = 0;
                             $val_name = $pv_array[1];
                         }
                         
+                        // Add multilanguage
+                        if ($CI->config->item('multilang'))
+                        {
+                        	$val_name = ucwords($CI->lang->line($val_name));
+                        }
+                        
                         // Url preparation
                         // If no url define (array key is empty)
                         if ($number_pv_array == 1 || $val_url == $uri_array_original[$i])

language/english/breadcrumb_lang.php

+<?php
+
+$lang['set_home'] = 'Home';
+
+/* End of file breadcrumb_lang.php */
+/* Location: ./application/language/english/breadcrumb_lang.php */