简体   繁体   English

带有laravel4的多语言数据库驱动的网站

[英]multilanguage database driven website with laravel4

im messing around with laravel to do a multilanguage website. 我和laravel搞了个多语言的网站。

I am trying to implement this: 我正在尝试实现这一点:

$languages = array('en','fr');
$locale = Request::segment(1);
if(in_array($locale, $languages)){
    \App::setLocale($locale);
}else{
    $locale = null;
}
Route::group(array('prefix' => $locale), function()
{

    Route::get('/', 'Homecontroller@index');
    Route::get('contact', 'Homecontroller@contact');

});

for what i can see, everythings works fine, I understand, Laravel take locale from my url segment, check if it's in languages, if is not null he change the routing adding the prefix. 对于我所看到的,一切正常,我理解,Laravel从我的url段中获取语言环境,检查它是否为语言,如果不为null,则更改添加前缀的路由。 I have 2 question: 我有2个问题:

1) Why all my images now is not showed properly anymore, when i go to en/contact, while when i go to en/ I can see them. 1)为什么当我去en / contact时,我的所有图像现在都不能正确显示,而当我去en / contact时,我可以看到它们。

2) to use a database to pick up languages, i don't necessarly have to change App:setLocale, but i need to do a model to extract language to database and put in the right place? 2)要使用数据库来选择语言,我不必更改App:setLocale,但是我需要做一个模型来将语言提取到数据库中并放在正确的位置?

3) how to pass the variable languages to blade, so i can change the description of the product?? 3)如何将可变语言传递给刀片,以便我可以更改产品说明? (I used to do ?lang=en and then take it with a $_GET (我曾经做过?lang = en,然后用$ _GET接受它

Sorry i know maybe this is just a basic question, but i come from pure php and pure mysql background. 对不起,我知道这可能只是一个基本问题,但是我来自纯php和纯mysql背景。

EDIT: 1) I need to use the HTML:: image facade like {{HTML::image('path')}} 编辑:1)我需要使用HTML ::图像外观,例如{{HTML :: image('path')}}

  1. To me it seems like you are linking to your images with relative paths which will break when you start to have a different structure in your URL. 在我看来,您似乎正在使用相对路径链接到图像,当您的URL开始具有不同的结构时,这些路径会中断。 So try having absolute URL:s in your image src tags or make them start with a slash (/). 因此,请尝试在图片src标记中使用绝对URL:,或使它们以斜杠(/)开头。 Eg {{ HTML::image('/absolute/path/to/image.jpg') }} 例如{{ HTML::image('/absolute/path/to/image.jpg') }}

  2. I'm not sure if I understand your question, but you want to store your translations in the database instead of in files which is the default? 我不确定是否理解您的问题,但是您想将翻译存储在数据库中而不是默认存储在文件中吗? Maybe this could be something for you: https://github.com/Waavi/translation 也许这可能适合您: https : //github.com/Waavi/translation

  3. This is doable in a lot of different ways. 这可以通过许多不同的方式来实现。 For example you could just call {{{ Request::segment(1) }}} in your blade template and get your language (assuming it's segment number 1). 例如,您可以只在刀片模板中调用{{{ Request::segment(1) }}}并获取您的语言(假设它是段号1)。 But the neatest way would probably be to wrap it in a function and put it in an appropriate place according to your application's structure. 但是最巧妙的方法可能是将其包装在一个函数中,然后根据应用程序的结构将其放置在适当的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM