Download the PHP package admad/cakephp-i18n without Composer

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

CakePHP plugin for I18n related tools.

Build Status Coverage Status Total Downloads

Intro

This plugins provides:

Installation

Usage

Load the plugin by running command:

The plugin contains multiple classes useful for internationalization. You can pick and chose the ones you require.

I18nRoute

The I18nRoutes helps generating language prefixed routes of style /{lang}/{controller}/{action}.

For e.g. you can add routes to your routes.php similar to the ones shown below:

Fragment /{lang} will be auto prefixed to the routes which allows matching URLs like /en/posts, /en/posts/add etc. The lang element is persisted so that when generating URLs if you don't provide the lang key in URL array it will be automatically added based on current URL.

When connecting the routes you can use lang key in options to provide regular expression to match only languages which your app supports. Or your can set config value I18n.languages which the route class will use to auto generate regex for lang element matching:

Note: I18nRoute extends core's DashedRoute so the URL fragments will be inflected accordingly.

I18nMiddleware

While not necessary, one would generally use the I18nMiddleware too when using language prefixed routes with the help of I18nRoute.

You can setup the I18nMiddleware in your src/Application::middleware() as shown:

The keys of languages array are the language prefixes you use in your URL.

To ensure that the lang router param is available, you must add this middleware after adding CakePHP's default routing middleware (i.e. after ->add(new RoutingMiddleware($this))).

The middleware does basically two things:

  1. When accessing site root / it redirects the user to a language prefixed URL, for e.g. /en. The langauge is redirects to depends on the configuration keys detectLanguage and defaultLanguage shown above.

    Now in order to prevent CakePHP from complaining about missing route for /, you must connect a route for / to a controller action. That controller action will never be actually called as the middleware will intercept and redirect the request.

    For e.g. $routes->connect('/', ['controller' => 'Foo']);

  2. When accesing any URL with language prefix it set's the app's locale based on the prefix. For that it checks the value of lang route element in current request's params. This route element would be available if the matched route has been connects using the I18nRoute.

    Using the array provided for the languages key it sets the App.language config to language prefix through Configure::write() and the value of locale is for I18n::setLocale() call.

DbMessagesLoader

By default CakePHP using .po files to store static string translations. If for whatever reason you don't want to use .po files you can use the DbMessagesLoader class to store the translation messaged in database instead. Personally I belive having the messages in a table instead of .po files make it much easier to make a web interface for managing translations.

To use this class first create database table using sql file provided in the plugin's config folder.

Add code similar to what's shown below in your app's config/bootstrap.php:

You can use admad/i18n extract command to extract the translation message from your code files and populate the translations table. Updating the db records with translations for each language is upto you.

Now you can use the translation funtions like __() etc. as you normally would. The I18n class will fetch the required translations from the database instead of .po files.

TimezoneWidget

In your AppView::initialize() configure the FormHelper to use TimezoneWidget.

You can generate a select box with timezone identifiers like:

As shown in example above note that unlike normal select box, options is now an associative array of valid timezone regions where the key will be used as optgroup in the select box.


All versions of cakephp-i18n with dependencies

PHP Build Version
Package Version
Requires cakephp/cakephp Version ^5.0
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 admad/cakephp-i18n contains the following files

Loading the files please wait ....