Unleash the expressive power of the natural language in your Laravel application.

Overview

jrmajor/laravel-fluent

Latest Stable Version Required PHP Version

Unleash the expressive power of the natural language in your Laravel application. Read the Fluent Syntax Guide in order to learn more about syntax.

This package is a Laravel wrapper around jrmajor/fluent-php.

shared-photos =
    { $userName } { $photoCount ->
        [one] added a new photo
       *[other] added { $photoCount } new photos
    } to { $userGender ->
        [male] his stream
        [female] her stream
       *[other] their stream
    }.
__('stream.shared-photos', [
    'userName' => 'jrmajor',
    'photoCount' => 2,
    'userGender' => 'male',
]); // jrmajor added 2 new photos to his stream.

You may install it via Composer: composer require jrmajor/laravel-fluent. It requires PHP 8.0 and Laravel 8.0 or higher.

Usage

This package replaces default Laravel translator with Major\Fluent\Laravel\FluentTranslator.

app('translator') instanceof Major\Fluent\Laravel\FluentTranslator; // true

Fluent translations are stored in .ftl files. Place them among your .php translation files in your Laravel app:

/resources
  /lang
    /en
      menu.ftl
      validation.php
    /pl
      menu.ftl
      validation.php

If there is no Fluent message for given key, translator will fall back to .php file, which allows you to introduce Fluent translation format progressively.

Laravel validator uses custom logic for replacing :attribute variable and requires deeply nested keys, which are not supported in Fluent, so you should leave validation.php file in default Laravel format.

trans_choice() helper always falls back to default translator, as Fluent format eliminates the need for another function.

Installation

You may install the package via Composer:

composer require jrmajor/laravel-fluent

The package will automatically register itself.

Optionally, you can publish the configuration file with this command:

php artisan vendor:publish --tag fluent-config

This will publish the following file in config/fluent.php:

return [

    /*
     * In strict mode, exceptions will be thrown for syntax errors
     * in .ftl files, unknown variables in messages etc.
     * It's recommended to enable this setting in development
     * to make it easy to spot mistakes.
     */
    'strict' => ! app()->isProduction(),

    /*
     * Determines if it should use Unicode isolation marks (FSI, PDI)
     * for bidirectional interpolations. You may want to enable this
     * behaviour if your application uses right-to-left script.
     */
    'use_isolating' => false,

];

Testing

vendor/bin/phpunit --testdox  # Tests
vendor/bin/phpstan analyse    # Static analysis
vendor/bin/php-cs-fixer fix   # Formatting
You might also like...
Jetstrap is a lightweight laravel 8 package that focuses on the VIEW side of Jetstream / Breeze package installed in your Laravel application

A Laravel 8 package to easily switch TailwindCSS resources generated by Laravel Jetstream and Breeze to Bootstrap 4.

Laravel Larex lets you translate your whole Laravel application from a single CSV file.
Laravel Larex lets you translate your whole Laravel application from a single CSV file.

Laravel Larex Translate Laravel Apps from a CSV File Laravel Larex lets you translate your whole Laravel application from a single CSV file. You can i

Laravel package to find performance bottlenecks in your laravel application.
Laravel package to find performance bottlenecks in your laravel application.

Laravel Meter Laravel Meter monitors application performance for different things such as requests, commands, queries, events, etc and presents result

Laravel-tagmanager - An easier way to add Google Tag Manager to your Laravel application.

Laravel TagManager An easier way to add Google Tag Manager to your Laravel application. Including recommended GTM events support. Requirements Laravel

 Laravel Logable is a simple way to log http request in your Laravel application.
Laravel Logable is a simple way to log http request in your Laravel application.

Laravel Logable is a simple way to log http request in your Laravel application. Requirements php = 7.4 Laravel version = 6.0 Installation composer

Laravel comments - This package enables to easily associate comments to any Eloquent model in your Laravel application

Laravel comments - This package enables to easily associate comments to any Eloquent model in your Laravel application

Catch incoming emails in your Laravel application
Catch incoming emails in your Laravel application

Laravel Mailbox 📬 Handle incoming emails in your Laravel application. Mailbox::from('{username}@gmail.com', function (InboundEmail $email, $username)

Deploy and execute non-PHP AWS Lambda functions from your Laravel application.

Sidecar for Laravel Deploy and execute non-PHP AWS Lambda functions from your Laravel application. Read the full docs at hammerstone.dev/sidecar/docs.

Livewire component that brings Spotlight/Alfred-like functionality to your Laravel application.
Livewire component that brings Spotlight/Alfred-like functionality to your Laravel application.

About LivewireUI Spotlight LivewireUI Spotlight is a Livewire component that provides Spotlight/Alfred-like functionality to your Laravel application.

Comments
  • Add support for getting namespaced translations

    Add support for getting namespaced translations

    This PR adds support for loading translations from namespaced .ftl files, as in namespace::some.message. This is useful for Laravel package developers that wish to use Fluent for their package translations.

    # namespace/en/some.ftl
    message = Hello, world!
    
    $this->app['translator']->addNamespace('namespace', __DIR__.'/namespace');
    
    __('namespace::some.message'); // Hello, world!
    

    Overrides

    There is a new allow_overrides config option which corresponds to the allowOverrides option for FluentBundle. If enabled, it allows namespaced translations to be overridden by package consumers in the standard Laravel manner of creating a lang/vendor/{namespace}/{locale}/{group}.ftl file, which will be appended to the FluentBundle.

    A point for review is whether this option should be enabled by default.

    Stability

    Much of the code added in FluentTranslator is adapted from Laravel's FileLoader class, so it should be pretty solid. The tests I've added are far from comprehensive, but at least prove the basic functionality works.

    opened by tobyzerner 4
  • Expose a way to add functions to the FluentBundle

    Expose a way to add functions to the FluentBundle

    Currently the FluentBundle instances created inside the FluentTranslator class cannot be configured after construction, so it's impossible to call addFunction.

    Perhaps a method could be added to FluentTranslator to allow adding functions when new bundles are constructed? Something like:

    $translator = app('translator'); // instanceof FluentTranslator
    
    $translator->addFunction('MY_FUNCTION', Closure::fromCallable('my_function'));
    

    Then the FluentTranslator would pass these on whenever a bundle is created.

    The user would call this in their own service provider. I don't think config files are useful here as they cannot contain closures.

    opened by tobyzerner 1
Releases(v0.2.0)
Owner
Jeremiasz Major
Jeremiasz Major
Laravel Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.

Introduction Laravel Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services. It handles almost all of the b

The Laravel Framework 189 Jan 5, 2023
This project demonstrates the power of soketi's WebSocket functionality in Laravel.

Laravel + soketi = <3 This project demonstrates the power of soketi's WebSocket functionality in Laravel. Installing the project The server requires:

Soketi 35 Dec 24, 2022
Scout Extended: The Full Power of Algolia in Laravel

Documentation • Community Forum • Stack Overflow • Report a bug • FAQ • Support To dig right in, visit the Scout Extended documentation. Scout Extende

Algolia 378 Dec 1, 2022
Give the power of Twig to Laravel

Allows you to use Twig seamlessly in Laravel. Requirements TwigBridge >= 0.13 supports Twig 3. If you need Twig 1/2 support, use the 0.12 versions. In

Rob Crowe 866 Jan 30, 2022
This is a plugin written in the PHP programming language and running on the PocketMine platform that works stably on the API 3.25.0 platform. It helps to liven up your server with Tags!

General This is a plugin written in the PHP programming language and running on the PocketMine platform that works stably on the API 3.25.0 platform.

Thành Nhân 4 Oct 21, 2021
Searches for multilingual phrases in Laravel project and automatically generates language files for you.

Laravel Lang Generator Searches for multilingual phrases in a Laravel project and automatically generates language files for you. You can search for n

Gleb 5 Oct 19, 2022
Localization Helper - Package for convenient work with Laravel's localization features and fast language files generation

Localization Helper Package for convenient work with Laravel's localization features and fast language files generation. Installation Via Composer $ c

Galymzhan Begimov 0 Jul 13, 2019
GeoLocation-Package - This package helps you to know the current language of the user, the country from which he is browsing, the currency of his country, and also whether he is using it vpn

GeoLocation in PHP (API) ?? ?? ?? This package helps you to know a lot of information about the current user by his ip address ?? ?? ?? This package h

Abdullah Karam 4 Dec 8, 2022
Automatically load your helpers in your laravel application.

Laravel AutoHelpers Automatically load your helpers in your laravel application. Installation You can install the package via composer: composer requi

Florian Wartner 6 Jul 26, 2021
Laravel Segment is an opinionated, approach to integrating Segment into your Laravel application.

Laravel Segment Laravel Segment is an opinionated, approach to integrating Segment into your Laravel application. Installation You can install the pac

Octohook 13 May 16, 2022