Download the PHP package genl/matice without Composer

On this page you can find all versions of the php package genl/matice. 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 matice

Use your Laravel translations in JavaScript

Latest Version on Packagist Latest Version on NPM Tests Total Downloads on packagist Downloads on NPM

Logo

https://github.com/genl/matice/actions/workflows/.github/workflows/tests.yml/badge.svg?event=push

Matice creates a Blade directive that you can include in your views. It will export a JavaScript object of your Laravel application's translations, keyed by their names (aliases, lang, filenames, folders name), as well as globals trans(), __() and transChoice() helper functions which you can use to access your translations in your JavaScript.

Installation

You can install the package via composer:

  1. Include our Blade directive (@translations) somewhere in your template before your main application JavaScript is loaded—likely in the header somewhere.
  2. Publish the vendor if you want to customize config:

Matice is available as an NPM matice package which exposes the trans() function for use in frontend applications that do not use Blade. You can install the NPM package with:

or load it from a CDN:

TypeScript support

Matice is fully written in TypeScript so, it's compatible with TypeScript projects.

Usage

Matice comes with almost the same localization concepts as Laravel. Read more about Laravel localization

This package uses the @translations directive to inject a JavaScript object containing all of your application's translations, keyed by their names. This collection is available globally on the client side in the window.Matice object. The @translations directive accepts a list of locales to be loaded under th form of an array or a comma seperated string. If no locales are given, all the translations will be loaded.

Examples

import the trans() function like follow:

The package also creates an optional trans() JavaScript helper which works like Laravel's PHP trans() helper to retrieve translation strings.

Examples

import the trans() function like follow:

Let's assume we have this translations file:

trans

Retrieve a text:

Update locale

Matice exposes setLocale function to change the locale that is used by the trans function.

Pluralization

On pluralization, the choice depends on the count argument. To activate pluralization pass the argument pluralize to true.

Trans Choice

Matice provides a helper function for pluralization

Underscore function

transChoice() always throws an error if the key is not found. To change this behaviour, use __(key, {pluralize: true})

Default values

Matice uses your current app locale app()->getLocale() as the default locale when generating the translation object with the blade directive @translations. Same applies when generating with command line.

When Matice does not find a key, it falls back to the default locale and search again. The fallback is the same you define in your config.app.fallback_locale.

Retrieve the current locale

Matice exposes the MaticeLocalizationConfig class :

Matice also provides helpers to deal with locales information:

Force locale

With the version 1.1.4, it is possible to force the locale for a specific translation WITHOUT changing the global local.

Filtering translations

Matice supports filtering the translations it makes available to your JavaScript, which is great to control the size of your data your translations become too large with thousands of lines.

Filtering namespaces

To set up namespace translations filtering, update in your config file either an only or except setting as an array of translations folders or files. Note: Setting the same namespace both 'only' and 'except' will result to 'except'. But in the other cases, 'only' takes precedence over 'except'

The base directory is the lang_directory defined in the config file: config('matice.lang_directory').

Use with SPA

Matice registers an Artisan console command to generate a matice_translations.js translations file, which can be used (or not) as part of an asset pipeline such as Laravel Mix.

You can run php artisan matice:generate --no-export in your project to generate a static translations file without the export statement in resources/assets/js/matice_translations.js. You can customize the generation path in the config/matice.php file.

An example of matice_translations.js, where auth translations exist in resources/lang/en/auth.php:

At this point you can use in javascript this translations file like usual, paste in your html as well.

This is useful if your laravel and js app are separated like with SPA or PWA. So you can link the generated translations file with your JS App. If you're not in the case of SPA, WPA... you might never have to generate the translations manually because @translations directive already does it for you when the app environment is 'production' to improve performance.

Whenever your translation messages change, run php artisan matice:generate again. Remember to disable browser cache, it may have cached the old translations file.

Using with Vue Components

Basically, Matice can be integrated to any Javascript projects. Event with some big framework like Vue.js React.js or Angular. Some frameworks like Vue re-renders the UI dynamically. In this section we show you how to bind Matice with Vue 2. Based on this example we assume you can take inspiration to do the same with the framework you use for your project. For example, with React, you should re-render the whole app after setLocale() is called for the changes to be visible.

Add this to your app.js file:

Then you can use the methods in your Vue components like so:

Dive Deeper

Matice extends the Laravel Translator class. Use Translator::list() to return an array representation of all of your app translations.

If you want to load only translations of a specific locale, use the matice facade:

Environment-based loading of minified matice helper file

When using the @translations Blade directive, Matice detects the current environment and minify the output if APP_ENV is production.

In development, @translations loops into the lang directory to generate the matice object each time the page reloads, and doesn't generatematice_translations.js file. In production, @translations generate the matice_translations.js file for you when your app is open for the first time then the generated file is used every time the page reloads. The Matice object is not generated every time, so it has no effect on performances in production. This behavior can be disabled in the config/matice.php file, set use_generated_translations_file_in_prod to false.

Note: Matice supports json translation files as well as php files.,

Testing

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

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.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.


All versions of matice with dependencies

PHP Build Version
Package Version
Requires laravel/framework Version >=6.0@dev
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 genl/matice contains the following files

Loading the files please wait ....