Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

Choosing the language

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


orasnita at gmail

Oct 12, 2009, 2:30 PM

Post #1 of 8 (1445 views)
Permalink
Choosing the language

Hi,

Is there a recommendation for storing the language ID in the URL in order to
be as easy to get it from there?

I want to have unique links for each URL, so I can't just put it in the
cookies. Using ?lang=EN seems to be the easiest way, although it doesn't
look nice.

Putting it as the first element in the path info looks nice, but I don't
know how to get it from there in a single controller/action and not in every
action separately.

I was also thinking to chain dispatching, but I don't know how I could set a
chain for the entire application that just gets the language and stores it
in the stash.

Please tell me how you use to do this.

Thank you.

Octavian


_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


larryl at emailplus

Oct 12, 2009, 2:37 PM

Post #2 of 8 (1365 views)
Permalink
Re: Choosing the language [In reply to]

Hi (again) Octavian -

> Is there a recommendation for storing the language ID in the URL in order
> to
> be as easy to get it from there?
>
> I want to have unique links for each URL, so I can't just put it in the
> cookies. Using ?lang=EN seems to be the easiest way, although it doesn't
> look nice.
>
> Putting it as the first element in the path info looks nice, but I don't
> know how to get it from there in a single controller/action and not in
> every
> action separately.

Here is one way to have it in the URL without all controllers needing to
be aware:

http://dev.catalyst.perl.org/wiki/wikicookbook/urlpathprefixing


HTH,
Larry

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


bobtfish at bobtfish

Oct 12, 2009, 2:57 PM

Post #3 of 8 (1364 views)
Permalink
Re: Choosing the language [In reply to]

On 12 Oct 2009, at 22:30, Octavian Râşniţă wrote:
> Is there a recommendation for storing the language ID in the URL in
> order to be as easy to get it from there?

Catalyst::TraitFor::Request::PerLanguageDomains

Cheers
t0m


_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


moseley at hank

Oct 12, 2009, 5:49 PM

Post #4 of 8 (1363 views)
Permalink
Re: Choosing the language [In reply to]

2009/10/12 Octavian Râşniţă <orasnita [at] gmail>

> Hi,
>
> Is there a recommendation for storing the language ID in the URL in order
> to be as easy to get it from there?
>
> I want to have unique links for each URL, so I can't just put it in the
> cookies. Using ?lang=EN seems to be the easiest way, although it doesn't
> look nice.
>

My other post about passing around query parameters is related. Happens
that one of the parameters is a lang setting. I've always preferred using a
path prefix instead of a query parameter. For one things it make relative
urls work. Another is that, IIRC, there were proxies that would not cache
content with query parameters. I'm not sure if that's a real concern any
more -- or if there's any other reasons to avod the query parameter
approach.

Another parameter that might be passed, in my case, is a session id. I'm
not a fan of that, but apparently there's some cases where it's needed (site
in an iframe??). At one time I also put that into a path prefix.


> Putting it as the first element in the path info looks nice, but I don't
> know how to get it from there in a single controller/action and not in every
> action separately.
>

The wiki article Larry posted is very close to what I do.



--
Bill Moseley
moseley [at] hank


orasnita at gmail

Oct 13, 2009, 6:16 AM

Post #5 of 8 (1329 views)
Permalink
Re: Choosing the language [In reply to]

From: "Larry Leszczynski" <larryl [at] emailplus>
> Hi (again) Octavian -
>
>> Is there a recommendation for storing the language ID in the URL in order
>> to
>> be as easy to get it from there?
>>
>> I want to have unique links for each URL, so I can't just put it in the
>> cookies. Using ?lang=EN seems to be the easiest way, although it doesn't
>> look nice.
>>
>> Putting it as the first element in the path info looks nice, but I don't
>> know how to get it from there in a single controller/action and not in
>> every
>> action separately.
>
> Here is one way to have it in the URL without all controllers needing to
> be aware:
>
> http://dev.catalyst.perl.org/wiki/wikicookbook/urlpathprefixing
>
>
> HTH,
> Larry

Thank you Larry. It seems to be what I need.

I've seen some uses of $self which were not defined in that example.
Shouldn't be __PACKAGE__ instead?

Unfortunately I don't know how to make it work in some cases:

1. If I use the test Catalyst server the static URLS that begin with /static
don't work because I can't configure that server to not handle /static URLS.
(But this is not so important).

2. Most important, if I need to use
[% c.uri_for('/static', 'css', 'layout.css') %]
for making it work even if I need to change the base location the app
handles, then the static files are not served by Apache directly but by the
app.

If the app listens to the / location, the request is in this case:

GET /en/static/css/layout.css HTTP/1.1



I think I could make a hack somehow and configure Apache to do a request to
/static whenever the user tries to access /en/static or /fr/static... but I
guess this could be done with mod_rewrite which I don't know how to use yet.



Is there a more simple method to make the web server serve the static files
directly?



Thank you.



Octavian






_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


hippich at gmail

Oct 13, 2009, 6:35 AM

Post #6 of 8 (1337 views)
Permalink
Re: Choosing the language [In reply to]

On Tue, Oct 13, 2009 at 4:16 PM, Octavian Râsnita <orasnita [at] gmail> wrote:
> From: "Larry Leszczynski" <larryl [at] emailplus>
>>
>> Hi (again) Octavian -
>>
>>> Is there a recommendation for storing the language ID in the URL in order
>>> to
>>> be as easy to get it from there?
>>>
>>> I want to have unique links for each URL, so I can't just put it in the
>>> cookies. Using ?lang=EN seems to be the easiest way, although it doesn't
>>> look nice.
>>>
>>> Putting it as the first element in the path info looks nice, but I don't
>>> know how to get it from there in a single controller/action and not in
>>> every
>>> action separately.
>>
>> Here is one way to have it in the URL without all controllers needing to
>> be aware:
>>
>>   http://dev.catalyst.perl.org/wiki/wikicookbook/urlpathprefixing
>>
>>
>> HTH,
>> Larry
>
> Thank you Larry. It seems to be what I need.
>
> I've seen some uses of $self which were not defined in that example.
> Shouldn't be __PACKAGE__ instead?
>
> Unfortunately I don't know how to make it work in some cases:
>
> 1. If I use the test Catalyst server the static URLS that begin with /static
> don't work because I can't configure that server to not handle /static URLS.
> (But this is not so important).
>
> 2. Most important, if I need to use
> [% c.uri_for('/static', 'css', 'layout.css') %]
> for making it work even if I need to change the base location the app
> handles, then the static files are not served by Apache directly but by the
> app.
>
> If the app listens to the / location, the request is in this case:
>
> GET /en/static/css/layout.css HTTP/1.1
>
>
>
> I think I could make a hack somehow and configure Apache to do a request to
> /static whenever the user tries to access /en/static or /fr/static... but I
> guess this could be done with mod_rewrite which I don't know how to use yet.
>
>
>
> Is there a more simple method to make the web server serve the static files
> directly?
>
>
>

Octavian,

I think it's a "feature". Think about it if you will need different
images for different languages, for example. Or RTL stylesheets for
rtl languages. And you can use symlinks for now while you do not need
these "features", or mod_rewrite to rewrite path to /static/ if there
is no /en/static/ yet =)

Regards,
Pavel Karoukin

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


larryl at emailplus

Oct 13, 2009, 12:59 PM

Post #7 of 8 (1343 views)
Permalink
Re: Choosing the language [In reply to]

> > http://dev.catalyst.perl.org/wiki/wikicookbook/urlpathprefixing
>
> Thank you Larry. It seems to be what I need.
>
> I've seen some uses of $self which were not defined in that example.
> Shouldn't be __PACKAGE__ instead?

Sorry, copy/paste error - $self should not be in there. I've tweaked
the wiki page.

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


wbs at grepit

Oct 14, 2009, 9:05 AM

Post #8 of 8 (1313 views)
Permalink
Re: Choosing the language [In reply to]

On Tue, Oct 13, 2009 at 9:35 AM, Pavel O. Korovkin <hippich [at] gmail>wrote:

> On Tue, Oct 13, 2009 at 4:16 PM, Octavian Râsnita <orasnita [at] gmail>
> wrote:
> > From: "Larry Leszczynski" <larryl [at] emailplus>
> >>
> >> Hi (again) Octavian -
> >>
> >>> Is there a recommendation for storing the language ID in the URL in
> order
> >>> to
> >>> be as easy to get it from there?
> >>>
> >>> I want to have unique links for each URL, so I can't just put it in the
> >>> cookies. Using ?lang=EN seems to be the easiest way, although it
> doesn't
> >>> look nice.
> >>>
> >>> Putting it as the first element in the path info looks nice, but I
> don't
> >>> know how to get it from there in a single controller/action and not in
> >>> every
> >>> action separately.
> >>
> >> Here is one way to have it in the URL without all controllers needing to
> >> be aware:
> >>
> >> http://dev.catalyst.perl.org/wiki/wikicookbook/urlpathprefixing
> >>
> >>
> >> HTH,
> >> Larry
> >
> > Thank you Larry. It seems to be what I need.
> >
> > I've seen some uses of $self which were not defined in that example.
> > Shouldn't be __PACKAGE__ instead?
> >
> > Unfortunately I don't know how to make it work in some cases:
> >
> > 1. If I use the test Catalyst server the static URLS that begin with
> /static
> > don't work because I can't configure that server to not handle /static
> URLS.
> > (But this is not so important).
> >
> > 2. Most important, if I need to use
> > [% c.uri_for('/static', 'css', 'layout.css') %]
> > for making it work even if I need to change the base location the app
> > handles, then the static files are not served by Apache directly but by
> the
> > app.
> >
> > If the app listens to the / location, the request is in this case:
> >
> > GET /en/static/css/layout.css HTTP/1.1
> >
> >
> >
> > I think I could make a hack somehow and configure Apache to do a request
> to
> > /static whenever the user tries to access /en/static or /fr/static... but
> I
> > guess this could be done with mod_rewrite which I don't know how to use
> yet.
> >
> >
> >
> > Is there a more simple method to make the web server serve the static
> files
> > directly?
> >
> >
> >
>
> Octavian,
>
> I think it's a "feature". Think about it if you will need different
> images for different languages, for example. Or RTL stylesheets for
> rtl languages. And you can use symlinks for now while you do not need
> these "features", or mod_rewrite to rewrite path to /static/ if there
> is no /en/static/ yet =)
>
>
Might I also suggest splitting out Location from Language and treating
them as a key pair. For instance, http://example.com/us/en/foo/bar/.

Just because two countries may speak Spanish does not mean their content
(and static assets like images!) would be the same -- they may very well
differ because of legal, cultural differences or local services/products.
Even if a site starts out with 100% translated/mirrored content, it is
advisable to build flexibility into the url structure.

Also, depending on your roll out and domain plan, take into
consideration that country specific domains should be able to publish the
country and language default content. http://example*.co.ae*/en/ serves ~
http://example.com/ae/en/.

-Wade



--
Thanks!

Wade Stuart

Phone: 917-363-6164
IM: SpaceMuscles

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.