eusonlito / laravel-Gettext

MIT License
9 stars 4 forks source link

How to use global __() function? #11

Open mexn opened 5 years ago

mexn commented 5 years ago

Hi!

I just found your plugin and was wondering, if you found a way to use Gettext's global __() function instead of Laravel's (setting config-option functions to true)? Because I struggled doing so, whether I'm trying my own solution or using your package.

vendor/gettext/gettext/src/translator_functions.php:
Cannot redeclare __() (previously declared in vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:907)
eusonlito commented 5 years ago

You should add the gettext functions file before load vendor autoload:

# public/index.php

require __DIR__.'/../vendor/gettext/gettext/src/translator_functions.php';
require __DIR__.'/../vendor/autoload.php';

and same into artisan.php:

require __DIR__.'/vendor/gettext/gettext/src/translator_functions.php';
require __DIR__.'/vendor/autoload.php';

$app = require_once __DIR__.'/bootstrap/app.php';
mexn commented 5 years ago

Thank you, I had hoped you have found a different way I'm not aware of yet. But this approach makes the functions config setting non-functional, or do i miss the point here?

eusonlito commented 5 years ago

Yes, using this approach the functions setting is not functional, but this way is needeed because laravel functions are load before any other package file.