Laravel's __(), trans() and trans_choice() for JavaScript, with the same arguments and the same output. It works with React, Vue, jQuery and vanilla JS, finds the locale from the page, knows RTL, and loads Laravel JS Localization, JSON, gettext, XLIFF, properties and ARB translations.
<Forms.Text name="message" :label="__('Message')" />You'll find the documentation on https://docs.javaabu.com/i18n, and in the docs folder.
AI coding assistants can start from llms.txt. The package ships a Laravel Boost skill and guideline, which Boost finds by itself. See AI assistants.
pnpm add @javaabu/i18nimport { __, trans_choice, configure } from "@javaabu/i18n"
configure({ loader: (locale) => import(`../../lang/${locale}.json`) })
__("Welcome, :name!", { name: "Ali" })
trans_choice("messages.apples", 3)Without a bundler:
<script src="https://unpkg.com/@javaabu/i18n/dist/i18n.iife.js"></script>| Using | Read | Example |
|---|---|---|
| React | React | examples/react.tsx |
| Vue | Vue | examples/App.vue |
| jQuery | jQuery | examples/jquery.ts |
| Vanilla JS | Vanilla JS | examples/vanilla.ts |
| Script tag | Installation | examples/script-tag.html |
Run the examples with pnpm install && pnpm examples. Each one switches between Dhivehi and English.
pnpm test # includes the comparison against test/parity/golden.json
pnpm test:coverage
pnpm build && pnpm test:browser
pnpm parity:generate # refreshes that file from the real Laravel translator (needs PHP and Composer)Please see CHANGELOG for what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email info@javaabu.com instead of using the issue tracker.
MIT. See LICENSE.md.