mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-21 03:15:45 -08:00
Merge remote-tracking branch 'origin/develop'
This commit is contained in:
commit
9136415bb2
35
app/Providers/SnipeTranslationServiceProvider.php
Normal file
35
app/Providers/SnipeTranslationServiceProvider.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Services\SnipeTranslator;
|
||||
use Illuminate\Translation\TranslationServiceProvider;
|
||||
|
||||
class SnipeTranslationServiceProvider extends TranslationServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//This is almost an *EXACT* carbon-copy of the TranslationServiceProvider, except with a modified Translator
|
||||
$this->registerLoader();
|
||||
|
||||
$this->app->singleton('translator', function ($app) {
|
||||
$loader = $app['translation.loader'];
|
||||
|
||||
// When registering the translator component, we'll need to set the default
|
||||
// locale as well as the fallback locale. So, we'll grab the application
|
||||
// configuration so we can easily get both of these values from there.
|
||||
$locale = $app['config']['app.locale'];
|
||||
|
||||
$trans = new SnipeTranslator($loader, $locale); //the ONLY changed line
|
||||
|
||||
$trans->setFallback($app['config']['app.fallback_locale']);
|
||||
|
||||
return $trans;
|
||||
});
|
||||
}
|
||||
}
|
42
app/Services/SnipeTranslator.php
Normal file
42
app/Services/SnipeTranslator.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Translation\Translator;
|
||||
|
||||
/***************************************************************
|
||||
* This is just a very, very light modification to the default Laravel Translator.
|
||||
* The only difference it has is that it modifies the $locale
|
||||
* value when the pluralizations are done so we can switch over from en-US to en_US (for example).
|
||||
*
|
||||
* This means our translation directories can stay where they are (en-US), but the
|
||||
* pluralization code can get executed against a locale of en_US
|
||||
* (Which is required by Symfony, for some inexplicable reason)
|
||||
*
|
||||
* This method is called by the trans_choice() helper, which we *do* use a lot.
|
||||
***************************************************************/
|
||||
class SnipeTranslator extends Translator {
|
||||
|
||||
//This is copied-and-pasted (almost) verbatim from Illuminate\Translation\Translator
|
||||
public function choice($key, $number, array $replace = [], $locale = null)
|
||||
{
|
||||
$line = $this->get(
|
||||
$key, $replace, $locale = $this->localeForChoice($locale)
|
||||
);
|
||||
|
||||
// If the given "number" is actually an array or countable we will simply count the
|
||||
// number of elements in an instance. This allows developers to pass an array of
|
||||
// items without having to count it on their end first which gives bad syntax.
|
||||
if (is_array($number) || $number instanceof Countable) {
|
||||
$number = count($number);
|
||||
}
|
||||
|
||||
$replace['count'] = $number;
|
||||
|
||||
$underscored_locale = str_replace("-","_",$locale); // OUR CHANGE.
|
||||
return $this->makeReplacements( // BELOW - that $underscored_locale is the *ONLY* modified part
|
||||
$this->getSelector()->choose($line, $number, $underscored_locale), $replace
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -277,7 +277,8 @@ return [
|
|||
Illuminate\Redis\RedisServiceProvider::class,
|
||||
Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
|
||||
Illuminate\Session\SessionServiceProvider::class,
|
||||
Illuminate\Translation\TranslationServiceProvider::class,
|
||||
// Illuminate\Translation\TranslationServiceProvider::class, //replaced on next line
|
||||
App\Providers\SnipeTranslationServiceProvider::class, //we REPLACE the default Laravel translator with our own
|
||||
Illuminate\Validation\ValidationServiceProvider::class,
|
||||
Illuminate\View\ViewServiceProvider::class,
|
||||
Barryvdh\DomPDF\ServiceProvider::class,
|
||||
|
|
|
@ -34,7 +34,7 @@ return array(
|
|||
'bulkedit' => array(
|
||||
'error' => 'No fields were changed, so nothing was updated.',
|
||||
'success' => 'Model successfully updated. |:model_count models successfully updated.',
|
||||
'warn' => 'You are about to update the properies of the following model: |You are about to edit the properties of the following :model_count models:',
|
||||
'warn' => 'You are about to update the properties of the following model:|You are about to edit the properties of the following :model_count models:',
|
||||
|
||||
),
|
||||
|
||||
|
|
Loading…
Reference in a new issue