superblock errors?
3,099
/dev/sda is the wrong device to run fsck on. sda is the whole disk. Your Linux filesystem is on /dev/sda5.
Related videos on Youtube
Author by
Jezen Thomas
Updated on September 18, 2022Comments
-
Jezen Thomas over 1 year
I would like to add a language code segment to my URIs in CodeIgniter, but I'd like to somehow — possibly with routing — force the browser to stop interpreting a language code as a path.
I haven't yet successfully implemented any of the i18n libraries in my CodeIgniter install, and I'm fairly certain my problem is simple enough to solve without a library anyway.
The method I had in mind was simply to load the appropriate language files respective of the language code that appears in the URI.
For example
http://example.com/about // Default language http://example.com/sv/about // Load Swedish language
Here's the controller logic:
<?php // ** Update ** // The following updated code works, as long as the language code appears // at the end of the URI, e.g, http://example.com/about/sv // // Ideally, I would like the language code segment to always appear first. // // There is also the problem of keeping the language selected while // navigating around the site… class Pages extends CI_Controller { public function view ($page = 'home') { if (!file_exists('application/views/pages/'.$page.'.php')) show_404(); $uri = explode("/", $_SERVER['REQUEST_URI']); $lang_code = end($uri); $data['title'] = $lang_code; switch ($lang_code) { case "sv": $the_language = "swedish"; break; case "no": $the_language = "norwegian"; break; default: $the_language = "english"; } $this->lang->load('general',$the_language); $this->load->view('templates/header', $data); $this->load->view('pages/'.$page, $data); $this->load->view('templates/footer', $data); } } ?>
Am I going about this the wrong way? If so, why? Please avoid canned responses.
-
jippie about 12 yearsAlways copy exact error messages when asking questions, don't try telling about what you understood from them.
-
Jezen Thomas over 11 yearsYeah, for that reason I really want the language code to exist in the URI.
-
danneth over 11 yearsThere's surely a better way to do this (htaccess perhaps) but perhaps you could alter/extend the routing class to check the first URI segment is a language (pseudocode here)
if (in_array(uri_segment(1), array('sv', 'en')) { set_language_var; strip_first_segment_from_uri; } continue routing;
-
Jezen Thomas over 11 yearsMy solution is sort of half-way there now (code updated); I don't really understand how uri-routing works.
-
danneth over 11 yearsThere is a built in function
$this->uri->segment(n)
which gives you the segments of the URI without having to doexplode
. As for keeping the language selection you could set$data['lang_path'] = $lang_code . '/'
if a language is selected (and leave it as an empty string otherwise). Then you will have to prepend all your links with this variable. I again stand with the suggestion of just using a cookie. I think this path will be rather complex once you start passing data to your controller(s). -
Jezen Thomas over 11 years@Mudshark I don't understand how that works. This is why I'm asking the question.
-
-
danneth over 11 yearsAn alternative solution is to put the selection in a cookie, and then create your own extension to the CI_Controller which attempts to read the language selection (or set default), and place that in
$this->the_language
or similar. Of course having the language code in the URL makes it clear for users what language to expect, so it has it's benefits as well. -
Jezen Thomas over 11 yearsThat's great! It's beginning to work as I'd like it to. A couple of things though: 1) The language segment now displays the language name, instead of the language code, i.e.,
http://example.com/english/home
; How should I shorten it? 2) It needs a language segment, otherwise nothing works, i.e.,http://example.com/home
doesn't work. How can I default the site to English? It shouldn't display the language code in the URI if it's in the default language. -
Mudshark over 11 yearsBit pressed for time here, but in routes.php you could start off with
$route['default_controller'] = "pages/view/sv";
. As for english vs en: create an array in the constructor,$languages = array('en' => english', 'sv' => 'swedish', etc);
, then in your view function determine the language as$current_lang = $this->languages[$this->language]
-
Jezen Thomas over 11 yearsYour answer has helped considerably, so I'm upvoting and marking as correct. I'm not all the way there yet though, so I'm continuing in another question.