I18N: Using domain instead of culture code?
The group you are posting to is a
Usenet group . Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
From:
"Felix E. Klee" <felix.k... @inka.de>
Date: Wed, 31 Oct 2012 09:46:38 +0100
Local: Wed, Oct 31 2012 4:46 am
Subject: I18N: Using domain instead of culture code?
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
"Felix E. Klee" <felix.k... @inka.de>
Date: Wed, 31 Oct 2012 10:34:38 +0100
Local: Wed, Oct 31 2012 5:34 am
Subject: Re: I18N: Using domain instead of culture code?
Just found [slides][1] of a talk by Thomas Rabaix, in which he touches
the subject of I18N URLs. On page 12, a solution with using a custom
`sfRouting` class is mentioned. Adapted to my needs:
class swCulturePatternRouting extends sfPatternRouting {
public function generate($name, $params = array(), $absolute = false) {
$culture = $this->getCultureFromDomain(); // adaption
$culture_route_name = $name.'_'.$culture;
if (array_key_exists($culture_route_name, $this->routes) {
$name = $culture_route_name;
}
return parent::generate($name, $params, $absolute);
}
}
Usage:
gift_en_US:
url: /gift
param: { module: main, action: gift, sf_culture: en_US }
gift_de_DE:
url: /geschenk
param: { module: main, action: gift, sf_culture: de_DE }
poison_en_US:
url: /poison
param: { module: main, action: poison, sf_culture: en_US }
poison_de_DE:
url: /gift
param: { module: main, action: poison, sf_culture: de_DE }
URLs:
http://example.us/gift
http://example.de/geschenk
http://example.us/poison
http://example.de/gift
[1]: http://www.slideshare.net/th0masr/internationalization-with-the-symfo...
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
Gabriel Petchesi <pghora... @gmail.com>
Date: Wed, 31 Oct 2012 05:29:17 -0700 (PDT)
Local: Wed, Oct 31 2012 8:29 am
Subject: Re: I18N: Using domain instead of culture code?
Had to do something similar to this in a project, trying to remember how it was done. Basically these two rules are handled by a special routing class:
http://example.us/example/path http://example.de/beispiel/path
placed at the bottom of routing.yml acting as a "catch all" rule, the rules are matched to the URL stored in the database.
At the database level this looks like: - domain (portal) - url - object type / object id
This solves only the "consumption" part, generating the URL from php code is a different issue that has to be treated separately (you will need to create your own function to generate the URL to the structure you want).
gabi
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
"Felix E. Klee" <felix.k... @inka.de>
Date: Wed, 31 Oct 2012 15:47:24 +0100
Local: Wed, Oct 31 2012 10:47 am
Subject: Re: I18N: Using domain instead of culture code?
Just found what looks like a beautiful solution on StackOverflow:
<http://stackoverflow.com/a/9963816/282729 >
Quote from that solution:
class myPatternRouting extends sfPatternRouting
{
public function getConfigFileName()
{
$domain_map = sfConfig::get('app_languages_domain_map');
$domain = $_SERVER['SERVER_NAME'];
$culture = isset($domain_map[$domain]) ?
$domain_map[$domain] : 'en';
$routing = sprintf('config/routing.%s.yml', $culture);
return
sfContext::getInstance()->getConfigCache()->checkConfig($routing,
true);
}
}
In the end you can have several routing files, based on culture. For our
purposes that seems perfect. We only have a few routes in the project.
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
"Felix E. Klee" <felix.k... @inka.de>
Date: Wed, 31 Oct 2012 15:49:17 +0100
Local: Wed, Oct 31 2012 10:49 am
Subject: Re: [symfony1] Re: I18N: Using domain instead of culture code?
On Wed, Oct 31, 2012 at 1:29 PM, Gabriel Petchesi <pghora... @gmail.com>
wrote:
> matched to the URL stored in the database.
Seems great for a project where you need many routes. In our project,
however, this is not necessary. There are only a few routes.
Anyway, thanks for the suggestion!
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
"Felix E. Klee" <felix.k... @inka.de>
Date: Wed, 31 Oct 2012 15:54:15 +0100
Local: Wed, Oct 31 2012 10:54 am
Subject: Re: I18N: Using domain instead of culture code?
On Wed, Oct 31, 2012 at 10:34 AM, Felix E. Klee <felix.k... @inka.de>
wrote:
> class swCulturePatternRouting extends sfPatternRouting {
To follow up on this: It looks like it's only for generation of URLs
from routes. So, it's just 50% of a solution.
You must
Sign in before you can post messages.
You do not have the permission required to post.