How big are the articles? Could you set the DB like this:
eng_slug | pol_slug | eng_title | pol_title | eng_content | pol_content | eng_seo_title | pol_seo_title
You could the query based on segment(1) - eng or pol etc and pull out the correct data.
This approach makes it a little harder to add additional languages harder, but could be OK if you have a limited list. Probably not the right way to go.
Another approach - Which will probably be a bit of a pain - is to have a DB for each language and change the connection to the DB based on the segment(1).
http://laravel.com/docs/4.2/database#accessing-connections
$users = DB::connection(Request::segment(1))->select(...);
Or, you could use segment(1) to query the correct table:
Articles::where(Request::segment(1) . "_articles", $slug)->first();
As a side note, you might be better off using ISO standard slugs to define your locales. Search engines will like you for you.
eng = en or en-gb or en-us pol = pl
http://www.spoonfork.org/isocodes.html
Hope that helps a little.
With 16 languages in mind i would end with 48 columns there (minimal version with title
, seo_title
and content
) so thats not the best way imho.
Thanks for the comments with ISO standards I wasnt sure if search engines prioretize such convention. That will come in handy for sure.
This is what im testing right now: What do You think?
(the code below does not handle empty language yet, I know that)
Route::get(
'{languageCode?}/{category}/{title?}',
function ($languageCode = 'pl', $category, $title = '') {
$languageId = DB::table('languages')->where('abbreviation', $languageCode)->lists(
'language_id',
'abbreviation'
);
if (isset($languageId[$languageCode])) {
Session::put('languageId', $languageId[$languageCode]);
App::setlocale($languageId[$languageCode]);
}
$categoryId = DB::table('categories_translations')->where('language_id', App::getLocale())->where(
'url',
$category
)->lists('category_id', 'url');
$articleId = DB::table('articles_translations')->where('language_id', App::getLocale())->where(
'url',
$title
)->lists('article_id', 'url');
if ($categoryId && $articleId) {
return App::make("CategoryController")->viewArticle($categoryId, $articleId);
} elseif ($categoryId && !$title) {
return App::make("CategoryController")->listArticles($categoryId);
} elseif ($categoryId && $title && !$articleId) {
//We can just throw error that there is no such article
} else {
//We can just throw error that there is no such category
}
}
)
I'm using this package https://github.com/Anahkiasen/polyglot works great. Create a translatable model for your pages, posts, etc and look them up in the router:
Route::get('{slug?}', array('uses' => 'SomeController@index'))->where('slug', '.*');
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community