duanbo7517 2011-01-12 20:55
浏览 28

如何在CakePHP中为多语言网站获取翻译的URI和控制器

Hello all and thanks in advance for taking a look and I appreciate any help possible. I'm an SEO guy and have inherited a CakePHP site that will serve content in three languages. I'd like to get a canonical (seo friendly) way to get a good multilingual URL architecture without making my developer too upset.

The end solution of what we want:

Nice URLs with three distinct URLs (translated) for each language. For example:

www.domain.com/L1/language-1-parent/language-1-child/ www.domain.com/L2/language-2-parent/language-2-child/ www.domain.com/L3/language-3-parent/language-3-child/

Here, we have one content piece. This content will be the same in all three languages, but it will be translated. Accordingly, we want the corresponding subdirectories and URIs to be translated as well, where:

L{1-3} are subdirectories indicating the language

language-{1-3} are 'controllers' for the content. Currently we only have one controller, regardless whether the language subdirectories are in a different language).

langauge-{1-3}-child are dependent content items or subdirectries that must also be translated based upon the language subdirectories


The Assumed Problem:

My developer is telling me that because Cake has controllers that serve the content up and as such having translations is a bit messy. In the example above: I assume that 'language-1,' language-2,' and 'language-3' are the controllers.

Also, I'm assuming that because we're trying to serve up three content versions from one controller (with different URLs), we're running into a problem.

Currently we have URLs as such:

www.domain.com/L1/language-1-parent/language-1-child/ www.domain.com/L2/language-1-parent/language-1-child/ www.domain.com/L3/language-1-parent/language-1-child/

The problem here is that regardless whether a user selects a different language, we have the URLs that do not correspond and are not translated. Also, we do have some content items that do not have other language translations. As such, I want to put in a rel=canonical meta tag on the pages without translations and/or noindex these pages whilst we{re working on translations.

Again, your help is MASSIVELY appreciated and I look forward to your responses. I'm happy to clarify anything.

  • 写回答

1条回答 默认 最新

  • dsnhalq37505 2011-01-12 21:31
    关注

    With standard cakephp configuration you can easily achieve these kind of URLs using cakephp internationlization

    /eng/users/account
    /fre/users/account
    

    If you need these king of URLs

    /eng/users/account
    /fre/utilisateurs/compte
    

    Then you should play with your AppController.php

    // pseudo code, you need to rewrite this section as you need.
    var lang getUrlParams['language'];
    var controller getUrlParams['controller'];
    var action getUrlParams['action'];
    
    if (controller[lang] != controller || action[lang] != action) :
        redirect to `/lang/controller[lang]/action[lang]`;
    endif;
    

    In view's all links should be called like

    $this->Html->link(__('My Link'), array('controller' => __('users'), 'controller' => __('account')))
    
    评论

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序