forxer / generic-term-translations-for-laravel
A plugin for Laravel Lang that provides generic term translations for Laravel.
Installs: 1 098
Dependents: 3
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- ext-json: *
- laravel-lang/publisher: ^14.1 || ^15.0 || ^16.0
Requires (Dev)
- illuminate/filesystem: ^10.46 || ^11.27.2
- illuminate/support: ^10.46 || ^11.27.2
- laravel-lang/status-generator: ^1.19 || ^2.11.3
- laravel/pint: ^1.18.1
- phpunit/phpunit: ^10.5.36
- symfony/var-dumper: ^6.4.11
README
A plugin for Laravel Lang that provides generic term translations for Laravel project.
Consult the glossary to see all the terms available for translation.
Installation
Require the project using Composer:
composer require forxer/generic-term-translations-for-laravel --dev
Then use the locales publisher of Laravel Lang to add/update/reset or remove translations of this package:
- If you have never used Laravel Lang: add locales.
- If you are already using Laravel Lang: just update the locales.
Usage
This package provides translations for terms regularly used in projects.
You will find all the terms provided by this package in the glossary.
Terms are categorized into different sections by source files. For example there is an action.php
source file that defines the add_something
key, you can use it like this:
// "en" locale trans('action.add_something', [ 'something' => 'a post', ]); // return: "add a post" // "fr" locale trans('action.add_something', [ 'something' => 'un article', ]); // return: "ajouter un article"
Be careful to escape the data that you do not control:
trans('action.delete_something', [ 'something' => e($post->title), ]);
Feminine and masculine gender
Some languages distinguish between feminine and masculine genders, for the same term the feminine key will then be suffixed by _fem
. For example:
In English we use "all", while in French we use "toutes" in the feminine and "tous" in the masculine (see it on Google Translate).
// "en" locale trans('misc.all'); // return: "all" trans('misc.all_fem'); // return: "all" // "fr" locale trans('misc.all'); // return: "tous" trans('misc.all_fem'); // return: "toutes"
Development steps
- From the package directory, run
php composer update
- Update the sources as needed in
src/source
files - Run the console command
php vendor/bin/lang sync
- Translate modifications in
src/locales/{locale}/php.json
- Run
php generate-glossary
- Commit changes