PHP code example of bernardomacedo / laravel-db-translator
1. Go to this page and download the library: Download bernardomacedo/laravel-db-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/ */
bernardomacedo / laravel-db-translator example snippets
{{ lang('some text to translate') }}
{{ lang(':count apple named :name|:count apples named :name', ['name' => 'Bernardo'], 2) }}
{{ lang('{0} There are no apples (:count) named :name|[1,19] There are some (:count) apples named :name|[20,Inf] There are many (:count) apples named :name', ['name' => 'Bernardo'], 2) }}
{{ lang('some text to translate') }} // returns 'algum texto para traduzir'
{{ lang('some text to translate', null, null, null, 'ru') }} // returns 'какой-нибудь текст' bypassing the current language forcing a locale.
{{ lang('this text does not exists on the database') }} // returns 'this text does not exists on the database' and will be added for future translation
{{ lang('participations') }} /* general group assumed */
{{ lang('participations', null, null, 'some_group') }} /* some_group group assumed */
{{ lang($language_name, null, null, 'dynamic_language') }} /* language group assumed with dynamic flag on database */
{{ lang($SomeDynamicVar, null, null, 'dynamic_some_group') }} /* some_group group assumed with dynamic flag on database */
DBTranslator::doTranslation('This is cool', 'Isto é cool', 'pt');
use bernardomacedo\DBTranslator\DBTranslator;
class SomeControllerName extends BaseController
{
public function generate_translations()
{
/**
* This will generate the language translations for all
* translated texts in the database, and will assume
* the original language by default.
* This will work on all languages active by default.
*/
DBTranslator::generate(); /* will generate all translations */
DBTranslator::generate('pt'); /* will generate the Portuguese translations */
DBTranslator::generate(64); /* will generate the Portuguese translations based on ID */
/**
* Redirect or do whatever you wish after generation
*/
return redirect()->route('home');
}
}
use bernardomacedo\DBTranslator\Models\Intl;
class SomeControllerName extends BaseController
{
public function some_function()
{
$all = Intl::all();
$group = Intl::group('general')->get();
}
}
use bernardomacedo\DBTranslator\Models\Translated;
class SomeControllerName extends BaseController
{
public function some_function()
{
/**
* Gets all available translations
*/
$all = Translated::all();
/**
* Gets all available translations
*/
$portuguese = Translated::language('pt')->get(); // using string ISO
$portuguese = Translated::language(64)->get(); // using ID for the language
}
}
lang($php_var) /* is not supported so they will be ignored */