Download the PHP package belphemur/laravel-gettext without Composer

On this page you can find all versions of the php package belphemur/laravel-gettext. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-gettext

Laravel Gettext

Laravel Gettext is a translation package compatible with the Laravel Framework. It provides a simple way to add localization support to Laravel applications. It is designed to work with GNU gettext and Poedit. Former versions of this package (before 4.x) works with the native php-gettext module. Current versions uses the Symfony translation package by default instead of native php extension.

Stable build Status laravel-gettext for Laravel 8

Stable build Status laravel-gettext for Laravel 6

Laravel Latest Long Term Support Version is Laravel 6, we do not recommend using Laravel version < 6

1. Requirements

1.1 Optional

1.1.1 APCU

APCU extension installed - http://php.net/manual/en/book.apcu.php

If the APCU php extension is installed, the library will use the memory to cache the loaded translation to avoid having to parse the translation file (mo/po) at each request.

The cache is automatically invalidated when there is a change in the translation file.

1.1.2 gettext

Optional requirements if you want to use the native php-gettext extension:

You will need to update the 'handler' option to 'gettext' in order to use the native php-gettext module.

2. Install

Once it's installed, Laravel will discover automatically the provider and load it. (Only for 5.5+)

Now you need to publish the configuration file in order to set your own application values:

This command creates the package configuration file in: .

You also need to register the LaravelGettext middleware in the file:

Be sure to add the line after , otherwise the locale won't be saved into the session.

3. Configuration

At this time your application has full gettext support. Now you need to set some configuration values in .

Ok, now it's configured. It's time to generate the directory structure and translation files for the first time.

Make sure you have write permissions on before you run this command

With this command the needed directories and files are created on resources/lang/i18n

4. Workflow

A. Write strings :D

By default LaravelGettext looks on app/Http/Controllers and resources/views recursively searching for translations. Translations are all texts printed with the _i() function. Let's look a simple view example:

Poedit doesn't "understand" blade syntax. When using blade views you must run in order to compile all blade views to plain php before update the translations in Poedit

B. Plural strings

The plural translations follow the same pattern above. Plural translations are all texts printed with the _n() function, and it follow the php ngettext. Let's look a simple view example:

The Poedit keywords are defined in configuration file with this default pattern:

See Plural forms used by Poedit to configure for your language.

With Symfony

If you're using Symfony as your translation backend, you have access to their plurals syntax with the _s method. In Poedit it will be considered as a single line instead of a plural.

With symfony complex syntax:

C. Translate with Poedit

Open the PO file for the language that you want to translate with Poedit. The PO files are located by default in resources/lang/i18n/[locale]/LC_MESSAGES/[domain].po. If you have multiple gettext domains, one file is generated by each domain.

Once Poedit is loaded press the Update button to load all localized strings. You can repeat this step anytime you add a new localized string.

Fill translation fields in Poedit and save the file. The first time that you do this the MO files will be generated for each locale.

C. Runtime methods

To change configuration on runtime you have these methods:

5. Features and examples:

A. Route and controller implementation example:

app/Http/routes.php

app/Http/Controllers/HomeController.php

B. A basic language selector example:

C. Built-in language selector:

You can use the built-in language selector in your views:

It also supports custom labels:

D. Adding source directories and domains

You can achieve this editing the source-paths configuration array. By default resources/views and app/Http/Controllers are set.

You may want your translations in different files. Translations in GNUGettext are separated by domains, domains are simply context names.

Laravel-Gettext set always a default domain that contains all paths that doesn't belong to any domain, its name is established by the 'domain' configuration option.

To add a new domain just wrap your paths in the desired domain name, like this example:

This configuration generates three translation files by each language: messages.po, frontend.po and backend.po

To change the current domain in runtime (a route-middleware would be a nice place for do this):

Remember: update your gettext files every time you change the 'source-paths' option, otherwise is not necessary.

This command will update your PO files and will keep the current translations intact. After this you can open Poedit and click on update button to add the new text strings in the new paths.

You can update only the files of a single domain with the same command:

E. About gettext cache (only applies to php-gettext native module)

Sometimes when you edit/add translations on PO files the changes does not appear instantly. This is because the gettext cache system holds content. The most quick fix is restart your web server.

6. Contributing

If you want to help with the development of this package, you can:

7. Upgrade from 4.*

If you're upgrading from the 4., the one for Laravel 5.3., you need to refactor your usage of the __ method.

Laravel now use this method for their own translation. You now need to use _i instead and add this keyword in the configuration file of Laravel-Gettext:

Also, if you're using Symfony as your backend, you can add the _s method. It's made to use the full feature set of Symfony plurals syntax.


All versions of laravel-gettext with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
laravel/framework Version ^6.0 || ^7.0 || ^8.0
laravel/helpers Version ^1.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package belphemur/laravel-gettext contains the following files

Loading the files please wait ....