1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 14:12:44 +01:00

Merge pull request #994 from codedge/#705-set-app-language-for-templates

Make app language available in templates
This commit is contained in:
Hillel Coren 2016-07-20 10:40:21 +03:00 committed by GitHub
commit a3271d6688
4 changed files with 44 additions and 1 deletions

View File

@ -0,0 +1,37 @@
<?php
namespace App\Http\ViewComposers;
use Illuminate\View\View;
class AppLanguageComposer
{
/**
* Bind data to the view.
*
* @param View $view
*
* @return void
*/
public function compose(View $view)
{
$view->with('appLanguage', $this->getLanguage());
}
/**
* Get the language from the current locale
*
* @return string
*/
private function getLanguage()
{
$code = app()->getLocale();
if(preg_match('/_/', $code)) {
$codes = explode('_', $code);
$code = $codes[0];
}
return $code;
}
}

View File

@ -17,6 +17,11 @@ class ComposerServiceProvider extends ServiceProvider
['accounts.details', 'clients.edit', 'payments.edit', 'invoices.edit', 'accounts.localization'], ['accounts.details', 'clients.edit', 'payments.edit', 'invoices.edit', 'accounts.localization'],
'App\Http\ViewComposers\TranslationComposer' 'App\Http\ViewComposers\TranslationComposer'
); );
view()->composer(
['header', 'tasks.edit'],
'App\Http\ViewComposers\AppLanguageComposer'
);
} }
/** /**

View File

@ -305,6 +305,7 @@
/* Set the defaults for Bootstrap datepicker */ /* Set the defaults for Bootstrap datepicker */
$.extend(true, $.fn.datepicker.defaults, { $.extend(true, $.fn.datepicker.defaults, {
language: '{{ $appLanguage }}',
weekStart: {{ Session::get('start_of_week') }} weekStart: {{ Session::get('start_of_week') }}
}); });

View File

@ -170,7 +170,7 @@
var value = ko.utils.unwrapObservable(valueAccessor()); var value = ko.utils.unwrapObservable(valueAccessor());
// http://xdsoft.net/jqplugins/datetimepicker/ // http://xdsoft.net/jqplugins/datetimepicker/
$(element).datetimepicker({ $(element).datetimepicker({
lang: '{{ Utils::getLocaleRegion() }}', lang: '{{ $appLanguage }}',
lazyInit: true, lazyInit: true,
validateOnBlur: false, validateOnBlur: false,
step: 30, step: 30,