diff --git a/application/config/autoload.php b/application/config/autoload.php new file mode 100644 index 0000000..ca7a134 --- /dev/null +++ b/application/config/autoload.php @@ -0,0 +1,116 @@ +%s"; +$config['mci_wrapper_section'] = ""; + +// display names for the language bar +$config['mci_display']['en']['name'] = "ENG"; +$config['mci_display']['en']['title'] = "In English"; +$config['mci_display']['et']['name'] = "EST"; +$config['mci_display']['et']['title'] = "Eesti Keeles"; +$config['mci_display']['ru']['name'] = "RUS"; +$config['mci_display']['ru']['title'] = "По-Русски"; + +/* End of file mci_languages.php */ +/* Location: ./application/config/mci_languages.php */ \ No newline at end of file diff --git a/application/config/routes.php b/application/config/routes.php new file mode 100644 index 0000000..da7d72c --- /dev/null +++ b/application/config/routes.php @@ -0,0 +1,50 @@ +lang->mci_current(); + $data['content'] = 'mci_example_1'; + $data['uri'] = 'example/test'; + + $this->load->view('example', $data); + } + + function test() { + $data['i18n'] = $this->lang->mci_current(); + $data['content'] = 'mci_example_2'; + $data['uri'] = 'example'; + + $this->load->view('example', $data); + } +} + +/* End of file example.php */ +/* Location: ./application/controllers/example.php */ \ No newline at end of file diff --git a/application/core/MY_Lang.php b/application/core/MY_Lang.php new file mode 100644 index 0000000..d8a0a95 --- /dev/null +++ b/application/core/MY_Lang.php @@ -0,0 +1,102 @@ +load('mci_languages'); + + $this->mci_languages = $CFG->item('mci_languages'); + $this->mci_hide_default = $CFG->item('mci_hide_default'); + $this->mci_segment = $URI->segment(1, 0); + $this->mci_default_language = array_search($CFG->item('language'), $this->mci_languages); + + if(array_key_exists($this->mci_segment, $this->mci_languages)) { + $CFG->set_item('language', $this->mci_languages[$this->mci_segment]); + } + } + + // returns current language segment + function mci_current() { + return ((array_key_exists($this->mci_segment, $this->mci_languages)) ? $this->mci_segment : $this->mci_default_language); + } + + // checks, if currently used language is default. returns bool + function is_default() { + return (($this->mci_current() == $this->mci_default_language) ? TRUE : FALSE); + } + + // returns current uri without language segment + function mci_clean_uri() { + $ci =& get_instance(); + + $segments = $ci->uri->segment_array(); + + if(empty($segments)) { + return; + } + + if(array_key_exists($segments[1], $this->mci_languages)) { + array_shift($segments); + } + + return implode('/', $segments); + } + + // returns uri string with language segment + function mci_make_uri($language_segment, $uri = FALSE) { + $uri = ($uri === FALSE) ? $this->mci_clean_uri() : trim($uri, '/'); + + if(!array_key_exists($language_segment, $this->mci_languages)) { + return $uri; + } + + if($language_segment == $this->mci_default_language AND $this->mci_hide_default === TRUE) { + return $uri; + } + + $uri = $language_segment.'/'.$uri; + + return $uri; + } + + // returns html language bar + function mci_language_bar() { + $ci =& get_instance(); + + $display = $ci->config->item('mci_display'); + + $html = ''; + + foreach($this->mci_languages as $segment => $name) { + $uri = $this->mci_make_uri($segment); + + $row = ($segment != $this->mci_current()) ? anchor($uri, $display[$segment]['name'], 'title="'.$display[$segment]['title'].'"') : $display[$segment]['name']; + + $html .= sprintf($ci->config->item('mci_wrapper_language'), $row); + } + + return sprintf($ci->config->item('mci_wrapper_section'), $html); + } +} + +/* End of file MY_Lang.php */ +/* Location: ./application/core/MY_lang.php */ \ No newline at end of file diff --git a/application/helpers/mci_helper.php b/application/helpers/mci_helper.php new file mode 100644 index 0000000..e7fe8be --- /dev/null +++ b/application/helpers/mci_helper.php @@ -0,0 +1,33 @@ +lang->mci_make_uri($ci->lang->mci_current(), $uri); + + return anchor($uri, $title, $attributes); +} + +// Returns languge bar html +// Html can be configured in mci_languages.php config file +function langbar() { + $ci =& get_instance(); + + return $ci->lang->mci_language_bar(); +} + +/* End of file mci_helper.php */ +/* Location: ./application/helpers/mci_helper.php */ \ No newline at end of file diff --git a/application/language/english/mci_lang.php b/application/language/english/mci_lang.php new file mode 100644 index 0000000..d7a19af --- /dev/null +++ b/application/language/english/mci_lang.php @@ -0,0 +1,18 @@ +first content of this HTML5 document!"; +$lang['mci_example_2'] = "Hi, I'm the second content of this HTML5 document!"; +$lang['mci_click'] = "Click Me!"; +$lang['mci_footer'] = "Hi, I'm a footer!"; + +/* End of file mci_lang.php */ +/* Location: ./application/language/estonian/mci_lang.php */ \ No newline at end of file diff --git a/application/language/estonian/mci_lang.php b/application/language/estonian/mci_lang.php new file mode 100644 index 0000000..02cd425 --- /dev/null +++ b/application/language/estonian/mci_lang.php @@ -0,0 +1,18 @@ +esimine sisu!"; +$lang['mci_example_2'] = "Tere, Mina olen selle HTML5 dokumendi teine sisu!"; +$lang['mci_click'] = "Mulju Mind!"; +$lang['mci_footer'] = "Tere, Mina olen footer!"; + +/* End of file mci_lang.php */ +/* Location: ./application/language/estonian/mci_lang.php */ \ No newline at end of file diff --git a/application/language/russian/mci_lang.php b/application/language/russian/mci_lang.php new file mode 100644 index 0000000..1aa2adb --- /dev/null +++ b/application/language/russian/mci_lang.php @@ -0,0 +1,18 @@ +первый содержание этого документа HTML5!"; +$lang['mci_example_2'] = "Привет, я второй Содержание этого документа HTML5!"; +$lang['mci_click'] = "Нажмите здесь!"; +$lang['mci_footer'] = "Привет, я подвал!"; + +/* End of file mci_lang.php */ +/* Location: ./application/language/russian/mci_lang.php */ \ No newline at end of file diff --git a/application/views/example.php b/application/views/example.php new file mode 100644 index 0000000..f14bfa2 --- /dev/null +++ b/application/views/example.php @@ -0,0 +1,56 @@ + + + + + Multilingual CI example + + + +
+ +
+ +

+

+ +

+ + \ No newline at end of file