{"id":16350454,"url":"https://github.com/eusonlito/laravel-gettext","last_synced_at":"2025-06-20T14:36:43.689Z","repository":{"id":31012210,"uuid":"34570670","full_name":"eusonlito/laravel-Gettext","owner":"eusonlito","description":null,"archived":false,"fork":false,"pushed_at":"2019-09-05T17:48:08.000Z","size":43,"stargazers_count":9,"open_issues_count":1,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-19T12:56:29.464Z","etag":null,"topics":["gettext","gettext-library","laravel","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eusonlito.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-25T14:04:38.000Z","updated_at":"2019-09-05T17:47:22.000Z","dependencies_parsed_at":"2022-09-01T11:52:10.770Z","dependency_job_id":null,"html_url":"https://github.com/eusonlito/laravel-Gettext","commit_stats":null,"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"purl":"pkg:github/eusonlito/laravel-Gettext","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eusonlito%2Flaravel-Gettext","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eusonlito%2Flaravel-Gettext/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eusonlito%2Flaravel-Gettext/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eusonlito%2Flaravel-Gettext/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eusonlito","download_url":"https://codeload.github.com/eusonlito/laravel-Gettext/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eusonlito%2Flaravel-Gettext/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260963121,"owners_count":23089549,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gettext","gettext-library","laravel","php"],"created_at":"2024-10-11T01:05:01.675Z","updated_at":"2025-06-20T14:36:38.642Z","avatar_url":"https://github.com/eusonlito.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel 5.4 Gettext\n\nWith this package you can load/parse/store gettext strings\n\n## Installation\n\nBegin by installing this package through Composer.\n\n```js\n{\n    \"require\": {\n        \"eusonlito/laravel-gettext\": \"2.0.*\"\n    }\n}\n```\n\n### Laravel installation\n\n\u003e Note: If you are using Laravel 5.5 or above, the next steps for providers and aliases are unnecessaries. laravel-Gettext supports Laravel new [Package Discovery](https://laravel.com/docs/master/packages#package-discovery).\n\n```php\n\n// config/app.php\n\n'providers' =\u003e [\n    '...',\n    'Eusonlito\\LaravelGettext\\GettextServiceProvider',\n];\n\n'aliases' =\u003e [\n    '...',\n    'Gettext'    =\u003e 'Eusonlito\\LaravelGettext\\Facade',\n];\n```\n\nNow you have a ```Gettext``` facade available.\n\nPublish the config file:\n\n```bash\nphp artisan vendor:publish\n```\n\n### Usage\n\n```php\n__('Here your text');\n__('Here your text with %s parameters', 1);\n__('Here your text with parameters %s and %s', 1, 2);\n```\n\n# Gettext Files\n\nBy default, gettext .po and .mo files are stored in resources/gettext/xx_XX/LC_MESSAGES/messages.XX\n\nxx_XX is language code like `en_US`, `es_ES`, etc...\n\n# Using your own Gettext function/helper\n\nIf you want to create your alternative gettext function:\n\n```php\n\n// config/app.php\n\n'providers' =\u003e [\n    '...',\n    'Eusonlito\\LaravelGettext\\GettextServiceProvider',\n    'App\\Providers\\GettextServiceProvider',\n];\n```\n\nCreate the file:\n\n```php\n\n// app/Providers/GettextServiceProvider.php\n\n\u003c?php\nnamespace App\\Providers {\n    use Illuminate\\Support\\ServiceProvider;\n\n    class GettextServiceProvider extends ServiceProvider\n    {\n        public function register()\n        {\n        }\n    }\n}\n\nnamespace {\n    function txt($original)\n    {\n        static $translator;\n\n        if (empty($translator)) {\n            $translator = app('gettext')-\u003egetTranslator();\n        }\n\n        $text = $translator-\u003egettext($original);\n\n        if (func_num_args() === 1) {\n            return $text;\n        }\n\n        $args = array_slice(func_get_args(), 1);\n\n        return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args);\n    }\n}\n```\n\n# Configuration\n\n#### app/config/gettext.php\n\n```php\nreturn array(\n    /*\n    |--------------------------------------------------------------------------\n    | Available locales\n    |--------------------------------------------------------------------------\n    |\n    | A array list with available locales to load\n    |\n    | Default locale will the first in array list\n    |\n    */\n\n    'locales' =\u003e ['en_US', 'es_ES', 'it_IT', 'fr_FR'],\n\n    /*\n    |--------------------------------------------------------------------------\n    | Directories to scan\n    |--------------------------------------------------------------------------\n    |\n    | Set directories to scan to find gettext strings (starting with __)\n    |\n    */\n\n    'directories' =\u003e ['app', 'resources'],\n\n    /*\n    |--------------------------------------------------------------------------\n    | Where the translations are stored\n    |--------------------------------------------------------------------------\n    |\n    | Full path is $storage/xx_XX/LC_MESSAGES/$domain.XX\n    |\n    */\n\n    'storage' =\u003e 'storage/gettext',\n\n    /*\n    |--------------------------------------------------------------------------\n    | Store files as domain name\n    |--------------------------------------------------------------------------\n    |\n    | Full path is $storage/xx_XX/LC_MESSAGES/$domain.XX\n    |\n    */\n\n    'domain' =\u003e 'messages',\n\n    /*\n    |--------------------------------------------------------------------------\n    | Use native gettext functions\n    |--------------------------------------------------------------------------\n    |\n    | Are faster than open files from PHP. If you have enabled the php-gettext\n    | module, is recommended to enable.\n    |\n    */\n\n    'native' =\u003e true,\n\n    /*\n    |--------------------------------------------------------------------------\n    | Use package gettext methods\n    |--------------------------------------------------------------------------\n    |\n    | Enable gettext methods: __, noop__, n__, p__, d__, dp__, np__, dnp__\n    |\n    | Reference: https://github.com/oscarotero/Gettext/blob/master/src/translator_functions.php\n    |\n    */\n\n    'functions' =\u003e false,\n\n    /*\n    |--------------------------------------------------------------------------\n    | Preference to load translations from format\n    |--------------------------------------------------------------------------\n    |\n    | Some systems and formats are fatest than others (low RAM or CPU usage)\n    | Available options are mo, po, php\n    |\n    */\n\n    'formats' =\u003e ['mo', 'php', 'po'],\n\n    /*\n    |--------------------------------------------------------------------------\n    | Cookie name\n    |--------------------------------------------------------------------------\n    |\n    | Locale cookie name. Cookie are stored as plain, without Laravel manager\n    |\n    */\n\n    'cookie' =\u003e 'locale'\n);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feusonlito%2Flaravel-gettext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feusonlito%2Flaravel-gettext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feusonlito%2Flaravel-gettext/lists"}