Skip to content

Instantly share code, notes, and snippets.

@nonoesp
Last active August 29, 2015 14:21
Show Gist options
  • Save nonoesp/38712192bed2196624e8 to your computer and use it in GitHub Desktop.
Save nonoesp/38712192bed2196624e8 to your computer and use it in GitHub Desktop.
Partial translation fallback — to fallback_locale — using dimsav/translatable with Laravel.
$translatableFallbackLocale = Config::get('translatable::fallback_locale');
$project = Project::find($id);
$project_default = $project->translate($translatableFallbackLocale);
// Translations
if(!$project->title) {
$title = $project_default->title;
} else {
$title = $project->title;
}
if(!$project->abstract) {
$abstract = $project_default->abstract;
} else {
$abstract = $project->abstract;
}
if(!$project->text) {
$text = $project_default->text;
} else {
$text = $project->text;
}
// Render
echo '<h1>'.$title.'</h1>'
.Markdown::string($abstract)
.Markdown::string($text);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment