{"id":13826902,"url":"https://github.com/kirschbaum-development/laravel-translations-loader","last_synced_at":"2025-04-09T23:18:22.477Z","repository":{"id":31495008,"uuid":"123590032","full_name":"kirschbaum-development/laravel-translations-loader","owner":"kirschbaum-development","description":"Webpack loader to import Laravel translation files (PHP or JSON) into your JS bundle as JSON.","archived":false,"fork":false,"pushed_at":"2024-04-10T11:14:40.000Z","size":346,"stargazers_count":187,"open_issues_count":5,"forks_count":15,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-04-09T23:18:17.534Z","etag":null,"topics":["hacktoberfest","laravel","translations"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kirschbaum-development.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-02T14:36:15.000Z","updated_at":"2025-03-26T03:59:24.000Z","dependencies_parsed_at":"2025-01-02T22:11:00.325Z","dependency_job_id":"579acd45-fa94-4fad-88f5-272de45bfce9","html_url":"https://github.com/kirschbaum-development/laravel-translations-loader","commit_stats":{"total_commits":88,"total_committers":12,"mean_commits":7.333333333333333,"dds":"0.19318181818181823","last_synced_commit":"241f008470e910e0892d8cacf03727ea4f9e7196"},"previous_names":["kirschbaum-development/laravel-i18n-loader"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirschbaum-development%2Flaravel-translations-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirschbaum-development%2Flaravel-translations-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirschbaum-development%2Flaravel-translations-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kirschbaum-development%2Flaravel-translations-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kirschbaum-development","download_url":"https://codeload.github.com/kirschbaum-development/laravel-translations-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125593,"owners_count":21051771,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","laravel","translations"],"created_at":"2024-08-04T09:01:46.367Z","updated_at":"2025-04-09T23:18:22.424Z","avatar_url":"https://github.com/kirschbaum-development.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"## :warning: No Longer Supported\n\nPlease note that since the standard Laravel front-end tools have moved away from webpack, this package is no longer maintained. You are free to fork and maintain a copy of this package.\n\n![](https://raw.githubusercontent.com/kirschbaum-development/laravel-translations-loader/master/banner.jpg)\n\n![Laravel Supported Versions](https://img.shields.io/badge/laravel-5.x/6.x/7.x/8.x-green.svg)\n[![npm](https://img.shields.io/npm/v/@kirschbaum-development/laravel-translations-loader.svg)](https://www.npmjs.com/package/@kirschbaum-development/laravel-translations-loader)\n[![npm](https://img.shields.io/npm/dt/@kirschbaum-development/laravel-translations-loader.svg)](https://www.npmjs.com/package/@kirschbaum-development/laravel-translations-loader)\n[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://www.npmjs.com/package/@kirschbaum-development/laravel-translations-loader)\n[![Actions Status](https://github.com/kirschbaum-development/laravel-translations-loader/workflows/CI/badge.svg)](https://github.com/kirschbaum-development/laravel-translations-loader/actions)\n\nThis package is a webpack loader to import your laravel translation files (PHP or JSON) into your JS bundle as JSON so you can use packages like [i18next](https://www.i18next.com/).\n\n### Requirements\n\nThis package works with any version of laravel, as long as you are using [Laravel Mix](https://laravel.com/docs/5.6/mix) or any custom [webpack](https://webpack.js.org/) configuration, since this package is essentially a webpack loader.\n\n### Installation\n\n```bash\n$ yarn add @kirschbaum-development/laravel-translations-loader --dev\n```\n\nor\n\n```bash\n$ npm install @kirschbaum-development/laravel-translations-loader --save-dev\n```\n\n### Usage\n\nIf you prefer, we have a [demo project](https://github.com/kirschbaum-development/laravel-translations-loader-demo) showing how to use it on laravel.\n\nIn your `app.js` file, just add the following import.\n\n```js\nimport languageBundle from '@kirschbaum-development/laravel-translations-loader!@kirschbaum-development/laravel-translations-loader';\n```\n\nThis will load and parse all your language files, including PHP and JSON translations. The `languageBundle` will look something like this:\n\n```json\n{\n    \"en\": {\n        \"auth\": {\n            \"failed\": \"These credentials do not match our records.\"\n        }\n    },\n    \"es\": {\n        \"auth\": {\n            \"failed\": \"Estas credenciales no coinciden con nuestros registros.\"\n        }\n    }\n}\n```\n\nAnd so on, with all your languages and all your translation strings.\n\n#### Namespacing\n\nSome packages like [i18next](https://www.i18next.com) require a \"namespace\" before your actual translations. When this happens, you can import your files like this:\n\n```js\nimport languageBundle from '@kirschbaum-development/laravel-translations-loader?namespace=translation!@kirschbaum-development/laravel-translations-loader';\n```\n\nAnd your translations will be loaded with the specified namespace in front of the translations:\n\n```json\n{\n    \"en\": {\n        \"translation\": {\n            \"auth\": {\n                \"failed\": \"These credentials do not match our records.\"\n            }\n        }\n    },\n    \"es\": {\n        \"translation\": {\n            \"auth\": {\n                \"failed\": \"Estas credenciales no coinciden con nuestros registros.\"\n            }\n        }\n    }\n}\n```\n\n#### Load only JSON translations\n\n```js\nimport languageBundle from '@kirschbaum-development/laravel-translations-loader/json!@kirschbaum-development/laravel-translations-loader';\n```\n\n#### Load only PHP translation files\n\n```js\nimport languageBundle from '@kirschbaum-development/laravel-translations-loader/php!@kirschbaum-development/laravel-translations-loader';\n```\n\n#### Replacing Laravel Parameters\n\nSometines your javascript library may need to use a parameter syntax different than the one Laravel ships (e.g. `:input`). For that, you can just pass an additional parameter when importing the bundle. Let's say you want to change from `:input` to `{{ input }}`. You just need to add the `parameters` option:\n\n```js\nimport languageBundle from '@kirschbaum-development/laravel-translations-loader/php?parameters={{ $1 }}!@kirschbaum-development/laravel-translations-loader';\n```\n\nAnd that's it. Your parameters will be replaced by your new syntax. **Important:** Don't forget to use the `$1` or the parameter name will not be populated.\n\n#### Using a different folder\n\nIf you are developing a package or for some reason have a different location for your translations, you can configure that by creating a `.js` file on your translations folder. For example, let's say you want to load translations on the language vendor folder.\n\nFirst thing you need is to create a `index.js` file (empty, no content needed) on the `resources/lang/vendor/{package-name}`.\n\nThen, you just need to reference this file when importing the translations:\n\n```js\n'@kirschbaum-development/laravel-translations-loader/php!resources/lang/vendor/{package-name}';\n```\n\nThis will make the package loads your translations from `resources/lang/vendor/{package-name}` instead of `resources/lang`.\n\n### Configuring in webpack.config.js\n\nYou can also apply the same configurations showed above directly on `webpack.config.js` to make this more readable. For that, follow these steps:\n\n1. Create an empty `index.js` file on the `resources/lang/index.js` path.\n\n2. Include the following rules in your config file:\n\n```js\nrules: [\n    {\n        test: path.resolve(__dirname, 'resources/lang/index.js'), // path to your index.js file\n        loader: '@kirschbaum-development/laravel-translations-loader/php?parameters={$1}'\n    }\n]\n```\n\nThen, you just need to import the recently created `index.js` file on your `app.js` (or whatever other) file:\n\n```js\nimport languageBundle from 'resources/lang/index.js';\n```\n\nFor Laravel Mix, just apply the same configuration in the following way:\n\n**Laravel Mix 3:**\n\n```js\nmix.webpackConfig({\n    rules: [\n        {\n            test: path.resolve(__dirname, 'resources/lang/index.js'), // path to your index.js file\n            loader: '@kirschbaum-development/laravel-translations-loader/php?parameters={$1}'\n        }\n    ]\n});\n```\n\n**Laravel Mix 4:**\n\n```js\nmix.extend('translations', new class {\n    webpackRules() {\n        return {\n            test: path.resolve(__dirname, '../resources/lang/index.js'),\n            loader: '@kirschbaum-development/laravel-translations-loader/php?parameters={$1}'\n        }\n    }\n});\n\nmix.translations();\n```\n\n**Laravel Mix 6:**\n\n```js\nmix.extend('translations', new class {\n    webpackRules() {\n        return {\n            test: path.resolve(__dirname, './resources/lang/index.js'),\n            loader: '@kirschbaum-development/laravel-translations-loader/php',\n            options: {\n                parameters: \"$1\",\n                includeOnly: ['auth', 'validation'],\n                exclude: [],\n            }\n        }\n    }\n});\n\nmix.translations();\n```\n\n***\n\n### Useful packages to use with laravel-translations-loader\n\n* [i18next](https://www.i18next.com/)\n* [vue-i18next](https://github.com/panter/vue-i18next)\n* [vue-i18n](https://github.com/kazupon/vue-i18n)\n* [react-i18next](https://github.com/i18next/react-i18next)\n\n***\n\n### Example using [vue-i18n](https://github.com/kazupon/vue-i18n)\n\nNotice you can directly pass the `languageBundle` object as a parameter into the `VueI18n` constructor.\n\n```js\nimport languageBundle from '@kirschbaum-development/laravel-translations-loader?parameters={$1}!@kirschbaum-development/laravel-translations-loader';\nimport VueI18n from 'vue-i18n';\nVue.use(VueI18n);\n\nconst i18n = new VueI18n({\n    locale: window.Locale,\n    messages: languageBundle,\n})\n```\n\n### Security\n\nIf you discover any security related issues, please email luis@kirschbaumdevelopment.com or nathan@kirschbaumdevelopment.com instead of using the issue tracker.\n\n## Credits\n\n- [Luis Dalmolin](https://github.com/luisdalmolin)\n- [Our contributors](https://github.com/kirschbaum-development/laravel-translations-loader/graphs/contributors)\n\n## Sponsorship\n\nDevelopment of this package is sponsored by Kirschbaum Development Group, a developer driven company focused on problem solving, team building, and community. Learn more [about us](https://kirschbaumdevelopment.com) or [join us](https://careers.kirschbaumdevelopment.com)!\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkirschbaum-development%2Flaravel-translations-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkirschbaum-development%2Flaravel-translations-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkirschbaum-development%2Flaravel-translations-loader/lists"}