douliao8760 2015-05-12 20:18
浏览 52

使用Laravel中的Pretty URL翻译网站

I'm trying to learn how to develop my website using Laravel 5.

Now i'm working on the languages of the site, but I have some questions that I hope you guys might know how to solve.

I know that the Location service helps a lot when translating the site, but I want something a little more complicated. I want to put a <select></select> tag at the top of my header where the user will have the option to change to another language.

Right now, I have already created the following folders that will have all the information to be translated.

-resources
    -lang
        -en
            messages.php
        -es
            messages.php

Each messages.php file has the complete directory of the information to be translated.

I know how to do this using pure php ($_SESSION) and jQuery, but I have no idea how to do this with laravel.

I would like that the website has will look like this:

/[about] 
/[contact] 
/en 
/en/[about] 
/en/[contact] 
/fr 
/fr/[about]
/fr/[contact]

Hope you guys help. Thanks.

EDIT

I just found a laravel package which can help to manage this kind specific issue in the proper way.

The package name is Laravel Localization and it's pretty easy to use.

Link here

  • 写回答

1条回答 默认 最新

  • 普通网友 2015-05-12 21:01
    关注

    Use the directions from here: http://laravel.com/docs/master/localization

    Route::get('{locale}/{page?}', function ($locale, $page == '') {
        App::setLocale($locale);    
        // your code
    });
    

    And as for the change of the language from a drop down, just redirect the users based on their choice with java script.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题