Laravel Translations Loader

News

January 15th, 2019

laravel-translations-loader.png

Laravel Translations Loader is a webpack loader to import your Laravel translation files (PHP or JSON) by Luís Dalmolin and Kirschbaum Development Group.

You install this package as an NPM dependency with NPM or Yarn:

1npm install @kirschbaum-development/laravel-translations-loader --save-dev
2
3# Or...
4
5yarn add @kirschbaum-development/laravel-translations-loader --dev

Kirschbaum also has a demo project you can reference to see how it works. Here’s an example of how it works from the demo project’s ExampleComponent component:

1<template>
2 <div class="container">
3 <p><strong>Translation for "auth.php" (PHP file):</strong><br>
4 {{ $t('auth.failed') }}</p>
5
6 <p><strong>Translation for "Hello World" (JSON file):</strong><br>
7 {{ $t('Hello World') }}</p>
8 </div>
9</template>

And here’s an example of how you might use this package with vue-i18n:

1import languageBundle from '@kirschbaum-development/laravel-translations-loader!@kirschbaum-development/laravel-translations-loader';
2import VueI18n from 'vue-i18n';
3Vue.use(VueI18n);
4
5const i18n = new VueI18n({
6 locale: window.Locale,
7 messages: languageBundle,
8})

To learn more about this project, installation, and usage instructions, check out the project’s GitHub repo: laravel-translations-loader. The readme also has useful packages you can use with the Laravel Translations Loader project if you’re using React, Vue, and i18next in your projects with this package.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.