Skip to content
Prev Previous commit
Next Next commit
Add a more automatic @section to head.blade.php that can be used when…
… exporting translations - @yield('js-localization.head.exported')
  • Loading branch information
carestad committed Apr 19, 2018
commit 2a76a2122700eca754ee539a332cec5280bc55df
21 changes: 21 additions & 0 deletions resources/views/head.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,24 @@
Lang.setLocale("{{ App::getLocale() }}");
</script>
@stop

@section('js-localization.head.exported')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that new @section actually a part of the file splitting changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, well, kind of. It allows you to use @yield('js-localization.head.exported'), which in turn will include the <script> tags for the exported files if they exist, and fallback to messages.js or just serving from the API endpoint instead if used incorrectly.

@if (file_exists(config('js-localization.storage_path') . '/js-localization.min.js'))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite hard to understand: Why do we check for ${storage_path}/js-localization.min.js and then set the URL to url('/vendor/js-localization/js-localization.min.js') / url('/js-localization/localization.js')?

It's not obvious how ${storage_path}/js-localization.min.js and the URLs relate to each other.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right of course. If someone would change the storage_path config, that would not work indeed. Maybe skip the @section altogether? Otherwise one would have to have a function that returns the correlation of storage_path and public_path (if that exists) to be able to figure out where the exported files actually go. And that might be a little bit out of scope for the plugin?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that would probably be the easiest solution now: Removing the section again and changing the Readme to tell the user how to use the locale-specific files.

Could still add a section like this in a follow-up PR.

<script src="{{ url('/vendor/js-localization/js-localization.min.js') }}"></script>
@else
<script src="{{ url('/js-localization/localization.js') }}"></script>
@endif

@if (Config::get('js-localization.config'))
<script src="{{ url('/vendor/js-localization/config.js') }}"></script>
@endif

@if (Config::get('js-localization.split_export_files') && file_exists(config('js-localization.storage_path') . '/lang-' . App::getLocale() . '.js'))
<script src="{{ url('/vendor/js-localization/lang-' . App::getLocale() . '.js') }}"></script>
@else
<script src="{{ url('/vendor/js-localization/messages.js') }}"></script>
@endif
<script>
Lang.setLocale("{{ App::getLocale() }}");
</script>
@stop