codiliateur / trans-helpers
Useful translation extensions
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:package
Requires
- php: ^8.0
- laravel/framework: ^8.0|^9.0|^10.0
This package is not auto-updated.
Last update: 2025-04-21 16:11:07 UTC
README
To install run command
composer require codiliateur/trans-helpers
Package provides next helper functions
function trans_r
trans_r($key, $replaces, $locale)
All parameters are the same as in the standard trans()
If you have a translation key that assigned to array of translations, this function guarantees to get missing translations from the fallback locale for all missing end-keys.
Example
./lang/en/models/person.php
return [
"attributes" => [
"id" => "ID",
"first_name" => "First Name",
"last_name" => "Last Name",
"age" => "Age",
]
];
./lang/fr/models/person.php
return [
"attributes" => [
"first_name" => "Prénome",
"last_name" => "Nom de famille",
]
];
If you call standard function trans
then you obtain just key translations from fr lang-file.
Call
trans('models/person.attributes', [], 'fr')
returns
[
"first_name" => "Prénome", // 'fr'
"last_name" => "Nom de famille", // 'fr'
];
But call trans_r
`trans_r('models/person.attributes', [], 'fr')`
returns all keys
[
"id" => "ID", // 'en' - fallback locale
"first_name" => "Prénome", // 'fr'
"last_name" => "Nom de famille", // 'fr'
"age" => "Age", // 'en' - fallback locale
];