PHP code example of aewebsolutions / laravel-translator
1. Go to this page and download the library: Download aewebsolutions/laravel-translator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
aewebsolutions / laravel-translator example snippets
//Set a route
Route::get('apple', [
'locales' => ['en', 'es'],
'as' => 'apple_path',
'uses' => 'fruitsController@apple'
]);
//Get a URL from a route name
route('es.apple_path');
//Get a translated text
echo tt('fruits.apple');
//Get a title for current locale
$article = App\Article::find(1);
echo $article->title;
class Kernel extends HttpKernel
{
use \Translator\Traits\KernelRouterExtender;
//etc.
}
// Change the whole group name:
Translator::updateGroupNeedle('fruits', 'juicy_fruits');
// Change the needle, but not the group:
Translator::updateGroupNeedle('fruits.peach', 'fruits.yellow_peach');
//Change a single group.needle:
Translator::updateGroupNeedle('fruits.peach', 'juicy_fruits.peach');
//Delete the whole group
Translator::delete('fruits');
//Delete the group.needle for all locales
Translator::delete('fruits.apple');
//Delete a group.needle for a specific locale
Translator::delete('es.fruits.apple');
$article = App\Article::find(1);
echo $article->title;
// output would be 'My title' if locale were 'en',
// but 'Mi título' if locale were 'es';
//Modify an article
$article = App\Article::find(1);
$article->title = [
'es' => 'Mi título en español',
'en' => 'My Title in English'
];
$article->save();
//Insert an article
$article = new App\Article;
$article->fill([
'title' => [
'es' => 'Mi título en español',
'en' => 'My Title in English'
]
]);
$article->save();