最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Laravel use trans() in jQ added elements - Stack Overflow

programmeradmin1浏览0评论

I wrote a little Laravel web page and I modify often some inputs with jQuery, now I want to implement a multilanguage support. But I dont know how to realize it in jQ.

An example: I have a unsorted list with n items. If the user click on every item I want to display "No more items available" and in German "Keine weiteren Einträge verfügbar". Does somebody have any ideas to realize it?

I using Laravel Blade, the JS content is in a seperated javascript.js file located.

I wrote a little Laravel web page and I modify often some inputs with jQuery, now I want to implement a multilanguage support. But I dont know how to realize it in jQ.

An example: I have a unsorted list with n items. If the user click on every item I want to display "No more items available" and in German "Keine weiteren Einträge verfügbar". Does somebody have any ideas to realize it?

I using Laravel Blade, the JS content is in a seperated javascript.js file located.

Share Improve this question asked Mar 30, 2016 at 7:40 Philipp NiesPhilipp Nies 9694 gold badges21 silver badges40 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

You could add the translations in your html page. Example:

<!-- Somewhere in your blade template -->
<script>
    window.translations = {
        noMoreItems: '{{ trans('get.your.translation.here') }}',
        somethingElse: '{{ trans('get.your.other.translation.here') }}',
    };
</script>

Then use those from your script. You might want to provide some defaults when using. Example:

// jQuery script 
var translations = {
    noMoreItems: window.translations.noMoreItems || 'My default translation',
    somethingElse: window.translations.somethingElse || 'My default translation',
};
发布评论

评论列表(0)

  1. 暂无评论