1. Go to this page and download the library: Download deepskylog/laravel-gettext 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/ */
/**
* Default locale: this will be the default for your application all
* localized strings. Is to be supposed that all strings are written
* on this language.
*/
'locale' => 'es_ES',
/**
* Supported locales: An array containing all allowed languages
*/
'supported-locales' => array(
'es_ES',
'en_US',
'it_IT',
'es_AR',
),
echo _s('{0} There are no apples|{1} There is one apple|]1,Inf[ There are %count% apples', $n);
// with parameter
$str = 'red';
echo _s('{0} There are no %s apples|{1} There is one %s apple|]1,Inf[ There are %count% %s apples', 2, $str);
/**
* Sets the Current locale.
* Example param value: 'es_ES'
*
* @param mixed $locale the locale
* @return LaravelGettext
*/
LaravelGettext::setLocale($locale);
/**
* Gets the Current locale.
* Example returned value: 'es_ES'
*
* @return String
*/
LaravelGettext::getLocale();
/**
* Gets the language portion of the locale.
* Eg from en_GB, returns en
*
* @return mixed
*/
LaravelGettext::getLocaleLanguage()
/**
* Sets the Current encoding.
* Example param value: 'UTF-8'
*
* @param mixed $encoding the encoding
* @return LaravelGettext
*/
LaravelGettext::setEncoding($encoding);
/**
* Gets the Current encoding.
* Example returned value: 'UTF-8'
*
* @return String
*/
LaravelGettext::getEncoding();
/**
* Sets the current domain
*
* @param String $domain
*/
LaravelGettext::setDomain($domain);
/**
* Returns the current domain
*
* @return String
*/
LaravelGettext::getDomain();
/**
* Returns the language selector object
*
* @param Array $labels
* @return LanguageSelector
*/
LaravelGettext::getSelector($labels = []);
/**
* Changes the current language and returns to previous page
* @return Redirect
*/
public function changeLang($locale=null)
{
LaravelGettext::setLocale($locale);
return Redirect::to(URL::previous());
}
<ul>
@foreach(Config::get('laravel-gettext.supported-locales') as $locale)
<li><a href="/lang/{{$locale}}">{{$locale}}</a></li>
@endforeach
</ul>
/**
* Paths where Poedit will search recursively for strings to translate.
* All paths are relative to app/ (don't use trailing slash).
*
* Remember to call artisan gettext:update after change this.
*/
'source-paths' => array(
'Http/Controllers',
'../resources/views',
'foo/bar', // app/foo/bar
),
/**
* The keywords list used by poedit to search the strings to be translated
*
* The "_", "__" and "gettext" are singular translation functions
* The "_n" and "ngettext" are plural translation functions
* The "dgettext" function allows a translation domain to be explicitly specified
*
* "__" and "_n" and "_i" and "_s" are helpers functions @see \deepskylog\LaravelGettext\Support\helpers.php
*/
'keywords-list' => ['_', '__', '_i', '_s', 'gettext', '_n:1,2', 'ngettext:1,2', 'dgettext:2'],;
bash
php artisan vendor:publish
config/laravel-gettext.php
app/Http/Kernel.php
config/laravel-gettext.php
bash
php artisan gettext:create
bash
php artisan gettext:update
bash
php artisan gettext:update --domain backend
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.