Download the PHP package bambamboole/laravel-i18next without Composer

On this page you can find all versions of the php package bambamboole/laravel-i18next. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-i18next

Laravel i18next

Latest Version on Packagist Total Downloads GitHub Actions

If you are using i18next in your frontend and Laravel in your backend, this package is for you.

Requirements

How does it work?

The package provides the routes to fetch the translations and to save missing translations when using i18next-http-backend.
it supports Laravels JSON and PHP translation files and converts them on the fly to be compatible with i18next.

PHP files in sub directories are namespaced by their path, so lang/en/entities/salesOrder.php is exposed under the entities.salesOrder.* keys.

Pluralization

Laravel plural strings are converted to i18next plurals:

Laravel i18next
one apple\|:count apples key_one, key_other
{0} no files\|{1} one file\|[2,*] :count files key_interval (see below)

Simple one\|other strings become standard i18next _one/_other plurals.

Explicit count/range forms ({0}, {1}, [2,*], …) are converted to the i18next-intervalplural-postprocessor format, e.g. (0)[no files];(1)[one file];(2-inf)[{{count}} files];. Add that postprocessor on the frontend to resolve them.

Installation

You can install the package via composer.

Configuration

Publish the config to customise routing, the missing-translation endpoint and caching:

Set 'output' => 'nested' if you'd rather receive a nested JSON tree and keep i18next's default dot key separator (no keySeparator: false needed).

Namespaces

Set 'namespaces' => true to load translations as i18next namespaces, where the namespace is the path of the group file under lang/{locale}:

Request Source i18next
/locales/en/translation.json lang/en.json (root strings) t('key')
/locales/en/auth.json lang/en/auth.php t('auth:key')
/locales/en/entities/salesOrder.json lang/en/entities/salesOrder.php t('entities/salesOrder:title')
/locales/en/lattice.json packages/lattice/lang/en/messages.php useTranslation('lattice'), then t('messages.key')

Keys are returned unprefixed (the namespace is the prefix). Configure the backend with loadPath: '/locales/{{lng}}/{{ns}}.json' and list your namespaces in ns. For Laravel package translations, use the Laravel package namespace as the i18next namespace, for example lattice. Package group files are exposed below it as dotted keys, for example messages.key. The package must register the path with loadTranslationsFrom($path, 'lattice').

When namespaces are disabled, package translations are exposed with their full Laravel keys, for example lattice::messages.key. Keys without a :: namespace continue to target normal app translations.

Saving missing keys for a slashed namespace reconstructs the full dotted key (entities.salesOrder.subtitle). With a laravel-translation-dumper version that supports writing into existing nested files, it lands back in entities/salesOrder.php; otherwise it falls into a flat entities.php.

Saving missing keys for a Laravel package namespace writes back into the registered package lang path, for example messages.subtitle in the lattice i18next namespace is written as lattice::messages.subtitle and lands in packages/lattice/lang/en/messages.php.

Security: the store route writes translation files. Disable it in production (I18NEXT_SAVE_MISSING=false) or put it behind auth via save_missing.middleware.

Usage

The package is still in its early development and therefor pretty opinionated and not very flexible.

It provides two routes. One is for fetching the translations and the other one is for saving missing translations.

Fetching translations

GET /locales/{locale}/translation.json returns all translations for the locale, converted to the i18next format. Point i18next-http-backend's loadPath at it.

Saving missing translations

POST /locales/add/{locale}/translation persists the keys reported by i18next's saveMissing. Point i18next-http-backend's addPath at it (and send the CSRF token, see below).

With Vue.js

To use the translations in your Vue.js components you can use the i18next-vue package.

To configure i18next-vue you can use the following code snippet:

With React (Inertia v3)

Install i18next and the React bindings alongside your Inertia app:

Initialise i18next in your Inertia entry point (resources/js/app.tsx) and wrap the app with I18nextProvider. Resolving the init() promise before createInertiaApp avoids a flash of untranslated keys on first paint:

Then translate inside your pages with the useTranslation hook:

Set keySeparator: false so i18next looks up the flat, dotted keys the package emits (test.greeting) verbatim instead of treating the dots as nesting.

A t / tp helper

Interval plurals need the _interval suffix and postProcess: 'interval' on every call. A tiny wrapper hides that — t for everything (including standard plurals), tp for interval plurals:

Outside of React, bind the same two functions to the i18next instance directly:

Testing

Demo

Run a live demo page that drives i18next in the browser against the package routes:

Contributing

Ideas/Roadmap

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-i18next with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
bambamboole/laravel-translation-dumper Version ^2.2
illuminate/cache Version ^11.0 || ^12.0 || ^13.0
illuminate/filesystem Version ^11.0 || ^12.0 || ^13.0
illuminate/http Version ^11.0 || ^12.0 || ^13.0
illuminate/support Version ^11.0 || ^12.0 || ^13.0
illuminate/translation Version ^11.0 || ^12.0 || ^13.0
spatie/laravel-package-tools Version ^1.16 || ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package bambamboole/laravel-i18next contains the following files

Loading the files please wait ...