简体   繁体   中英

multilanguage database driven website with laravel4

im messing around with laravel to do a multilanguage website.

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. I have 2 question:

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.

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?

3) how to pass the variable languages to blade, so i can change the description of the product?? (I used to do ?lang=en and then take it with a $_GET

Sorry i know maybe this is just a basic question, but i come from pure php and pure mysql background.

EDIT: 1) I need to use the HTML:: image facade like {{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. So try having absolute URL:s in your image src tags or make them start with a slash (/). Eg {{ 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

  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). 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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