Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
I18N: Using domain instead of culture code?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
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:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Felix E. Klee  
View profile  
 More options Oct 31 2012, 4:47 am
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?
Level 1
=======

We want to replace URLs such as:

    http://example.com/en_US/example/path
    http://example.com/de_DE/example/path

with:

    http://example.us/some/path
    http://example.de/some/path

In other words, we want to get rid of the culture code as culture is
already encoded in the domain. Currently routes looks like this:

   some_path:
     url: /:sf_culture/some/path
     param: { module: main, action: somePath, sf_format: html }

What's the Symfony 1.4 way of setting that up?

Level 2
=======

Now things get more complicated. We also want internationalized path
names ("beispiel" in German means example):

    http://example.us/example/path
    http://example.de/beispiel/path

What's the Symfony 1.4 way of setting that up?

Beware of false friends ("gift" in German means poison):

    http://example.us/gift
    http://example.de/gift


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Felix E. Klee  
View profile  
 More options Oct 31 2012, 5:35 am
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.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gabriel Petchesi  
View profile  
 More options Oct 31 2012, 8:29 am
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.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Felix E. Klee  
View profile  
 More options Oct 31 2012, 10:47 am
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.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Felix E. Klee  
View profile  
 More options Oct 31 2012, 10:49 am
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.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Felix E. Klee  
View profile  
 More options Oct 31 2012, 10:54 am
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.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »