Download the PHP package netson/l4gettext without Composer

On this page you can find all versions of the php package netson/l4gettext. 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 l4gettext

Gettext for Laravel 4

This package adds gettext functionality to the Laravel 4 framework which allows you to easily translate your application using tools such as PoEdit. Although Laravel 4 comes with a built-in translation engine, I prefer using tools like PoEdit, which takes away the need of maintaining arrays with text. This is my first Laravel experience/package, so if you come across any errors or have suggestions for improvements, let me know. This package works with Laravel 4.0. 4.1 and 4.2.

Written by: Rinck Sonnenberg (Netson)

Installation

Installation using composer:

Next, automatically detect which locales and encodings are installed and which is your default by executing the following command:

NOTE: only available on Linux/MacOS since this uses the command, which is not available on windows systems. This will automatically publish the config files if they haven't been published already.

By default, L4gettext comes with the en_US.utf-8 default, but by using the command it will check for your systems' default and use those instead.

Now, make sure you set the proper copyright holder, package name, package version and email address in the file

Alternatively, if you're on windows or prefer to take the manual route, publish the package config manually and edit the config files:

How does it work?

This package simply utilizes existing functionality to allow you to use gettext from within the Laravel Blade templates.

NOTE: Symfony contains a .po file reader; this is different from this implementation as this uses the actual gettext library on your system.

You can use the following functions in your templates:

If you have any custom functions you would like to use, check out the config.php file for more info! You can easily use these and any custom functions in your blade templates using the following syntax: or

The default configuration should be fine for most systems, but you should at least change the copyright holder, package name, package version and email address settings.

Aside from those, you are free to change all options according to your wishes. Make sure you publish the config for this package before changing options, using the following command:

See the comments in the config.php file for detailed documentation on each option.

When you are ready to start translating, use the commands provided by this package to compile your templates and extract the translation strings. See the section on Command line options for more information.

Getting started guide

To get started with this module and gettext, you can follow these basic steps:

If you run into any issues, check the troubleshooting section of this document and if that doesn't help, report any issues on GitHub! :)

Want to use translator comments in your source code?

Gettext supports usage of translator comments and so does L4gettext. If you wish to add comments for your translators in your source code, you can do so using the following syntax, assuming that you have set the variable "xgettext > comments" in your config file to TRANSLATORS:

or

Examples courtesy of loranger

Dependencies

Aside from some of the laravel 4 components, there are only logical dependencies:

NOTE: This package has only been thoroughly tested on linux (Ubuntu Server 12.04 LTS).

Command line options

There are 4 artisan commands for this package:

These commands use the options as set in the config file, but most can be overwritten at runtime by providing the appropriate parameters on the CLI. Check out the help for these commands for more info:

NOTE: Running the l4gettext:extract command extracts all language messages from compiled templates AND php files in the views folder.

The extract command creates a .pot file in the output directory if translatable strings are found. Please use the POEdit tool (link at bottom) to open this file. Once you enter your translation string(s) in poedit, hit the save button. This will automatically generate the compiled/indexed version of the translation file .mo. Place this compiled .mo file in the appropriate locale folder (ex: app/locale/en_GB/LC_MESSAGES/messages.mo). Note that gettext is extremely finicky when it comes to folder conventions!

IMPORTANT: Every time you run the extract command, a brand new .pot file is generated in the storage/l4gettext folder. So, if you already have translations entered for a few of the strings, DO NOT run extract again as this will create a fresh .pot file overwriting your edits. POEdit makes managing your .pot files very easy. For updating your pot file (in case you made last minute additions/changes to your templates), enter the paths to BOTH your "app/views" and "app/storage/gettext" folders in the POEdit "catalog properties"/"source paths" dialog. Then, click on the "Update" button on the (POEdit) toolbar to merge in the updates.

Supported locales

Gettext requires that the locales that you want to use are installed on your system. If you attempt to set a locale that is valid, but not installed, an exception will be thrown. You can check which locales are installed on your system by executing the following command on the (linux) CLI:

Or, use the following command to generate a new locale:

For locales available on Windows systems, check out this link. UTF-8 is not supported on Windows systems.

Laravel routes

The package registers 2 new routes:

These routes allow you to easily switch between locales/encodings by letting your users click on a link. The routes will automatically return the user to the address they came from (using the HTTP_REFERER), or, if that is unavailable, it will redirect to '/'. The input provided to {locale} and {encoding} is checked against an array of valid locales/encodings, which can be changed using the configuration files. The set locale/encoding is stored in a session.

So even if your system has 10 different locales installed, if your application only supports 3, simply keep only the selected 3 in the locales array.

NOTE: If you attempt to set a locale or encoding that is not installed on your system, an exception will be thrown.

Integration

If you would like to integrate this package into your own module/package, here is a list of the most important methods:

Troubleshooting

Gettext location

This package assumes that the xgettext library is in the path of your webserver user. If this is not the case, you may receive a "[127] Command not found found" error message. To fix this, you have two options:

Make sure you publish the config file first:

Then, edit the local config file in

You are now good to go!

Gettext caching

By design, gettext will cache the translated .mo file upon first usage. This sometimes leads to unwanted behavior where the changes to your .po/.mo file don't show up in your application. The easiest way to fix this is to give your webserver (ie. Apache) a restart. Other workarounds do exist (for example for development environments), but I suggest you Google those if you're interested.

Changelog

Version 1.5.0

Version 1.4.0

Version 1.3.0

Version 1.2.0

More information


All versions of l4gettext with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
illuminate/support Version >=4.0,<4.3
illuminate/foundation Version >=4.0,<4.3
illuminate/config Version >=4.0,<4.3
illuminate/session Version >=4.0,<4.3
illuminate/filesystem Version >=4.0,<4.3
illuminate/view Version >=4.0,<4.3
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 netson/l4gettext contains the following files

Loading the files please wait ....