Well, the site will be a multilanguage one, so let’s think about how would we go creating the infrastructure for this.
The easiest and also recommended way for SEO (https://support.google.com/webmasters/answer/182192?hl=en) is for the links to content to look like below:
http://example.com/ro/controller/method/params
http://example.com/fr/controller/method/params
Also, for default language, it should look as below:
http://example.com/controller/method/params
Inside the header of html pages we should have a hreflang attribute for every translation including itself (https://support.google.com/webmasters/answer/189077?hl=en):
<link rel=”alternate” hreflang=”en” href=”http://example.com/controller/method/params” />
<link rel=”alternate” hreflang=”ro” href=”http://example.com/ro/controller/method/params” />
<link rel=”alternate” hreflang=”fr” href=”http://example.com/fr/controller/method/params” />
Well… it gets a bit complicated, doesn’t it?
Let’s start by creating the admin area for languages.
Hi,
First of all, thank you for this tutorial.
You talk about “hreflang attribute for every translation” like:
I can’t find any information about this in your tutorial. Could you explain how two achieve this?
Thanks
Hello. Thank you for your kind words. Once you reach step 8, you will see that you can retrieve the id of a post and with that you should retrieve all the slugs for the languages of that particular post. From there on, I assume it’s easy to iterate through them so that you will output those hreflangs 🙂
Thanks for your fast answer. But what happens with methods that we have manage on routes files?
$controllers_methods = array(
‘en’ => array(
‘welcome/list’ => ‘welcome/list’,
‘welcome’ => ‘welcome’
),
‘fr’ => array(
‘bienvenu/list’ => ‘welcome/list’,
‘bienvenu’ => ‘welcome’
)
);
Those are for exemplification. They simply tell CodeIgniter what controllers and methods to serve when someone enters through a custom language url. What I mean by this is: If you are a spanish guy (as a visitor of a site), you wouldn’t like to go to a url like “site.com/users” and be served a page in your language. You would want the url to also be in spanish, like “site.com/usuarios”. So if a visitor receives content in their language, why not also make the URLs in their language? Now… as a developer, would that mean that you’d have to duplicate controllers and methods? No. You create ONE controller and its methods and serve the same logic in different languages. And in the views, instead of writing directly the strings, you would use the language files in order to serve the “static” content in the appropriate language.
Hello,
I have controller as http://localhost:90/nursery/plants and I want to rename it ashttp://localhost:90/nursery/products
Anyone tired this?