Download the PHP package lucinda/internationalization without Composer

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

Internationalization & Localization API

Table of contents:

About

This API is a very light weight platform that allows presentation logic (views) to be automatically translated based on user locale (see how are translations stored).

diagram

This way your HTML view becomes a web of units expected to be translated on compilation, as in example below:

Since the logic of view rendering/compilation is a MVC API's concern, instead of performing keyword replacement with translations based on detected locale in response to be rendered, API provides developers a platform able to automatically detect user locale as well as setting/getting translations based on following steps:

API is fully PSR-4 compliant, only requiring PHP 8.1+ interpreter and SimpleXML extension. To quickly see how it works, check:

  • installation: describes how to install API on your computer, in light of steps above
  • UnitTest API instead of PHPUnit for greater flexibility
  • example: shows a deep example of API functionality based on unit test for Lucinda\Internationalization\Wrapper

How are locales detected

A locale is understood by this API as a combination of a double digit lowercase ISO language code and a double digit uppercase ISO country code (eg: en_US) joined by underscore. API is able to detect user locale based on following mechanisms:

  • header: by value of Accept-Language request header (eg: $_SERVER["HTTP_ACCEPT_LANGUAGE"]= "fr-FR, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5");
  • request: by value of locale querystring parameter (eg: $_GET["locale"] = "fr_FR");
  • session: by value of locale session parameter (eg: $_SESSION["locale"] = "fr_FR");

If locale could not be detected, the default (specific to your application) will be used instead.

How are translations stored

Translations are expected by API to be stored in JSON files. Each JSON file is found on disk at folder/locale/domain.extension path where:

  • folder: folder in your application root where translations are placed. Default: "locale"
  • locale: locale/language in which translations will be looked after. Example: "fr_FR"
  • domain: name of translation file. Default: "messages"
  • extension: translation file extension. Default: "json"

Structure of that file is a dictionary where key is a short keyword that identifies each unit to be translated while value is translation text that will replace keyword when view is compiled. This means for each domain, JSON file must contain same keywords, only with different values specific to locale/language. If a keyword has no matching translation in JSON file, it will appear literally is when view is compiled (aligning with GETTEXT standards).

Examples:

  • locale/en_US/greetings.json:

  • locale/ro_RO/greetings.json:

Configuration

To configure this API you must have a XML with a internationalization tag whose syntax is:

Where:

  • method: (mandatory) identifies how locales are detected (see how are locales detected). Can be: header, request, session!
  • folder: (optional) folder in your application root where translations are placed (see how are translations stored). If not set, "locale" is assumed!
  • locale: (mandatory) default locale in which translations will be looked after (see how are translations stored). Eg: en_US
  • domain: (optional) name of translation file (see how are translations stored). If not set, "messages" is assumed!
  • extension: (optional) translation file extension (see how are translations stored). If not set, "json" is assumed!

Execution

Now that XML is configured, you can initialize API using Lucinda\Internationalization\Wrapper:

This class reads XML and user request, compiles internationalization settings and makes possible to set and get translations based on following public methods:

Method Arguments Returns Description
__construct \SimpleXMLElement $xml, array $requestParameters, array $requestHeaders void Compiles internationalization settings based on XML and user requests
getReader void Lucinda\Internationalization\Reader Gets instance to use in getting translations
getWriter void Lucinda\Internationalization\Writer Gets instance to use in setting translations

Once instance is made, unit translations can be operated using following methods:

Installation

First choose a folder, associate it to a domain then write this command in its folder using console:

Then create a configuration.xml file holding configuration settings (see configuration above) and a index.php file in project root with following code:

Then intervene before response is being rendered to replace unit keywords with translations. For example if your HTML is:

Then this regex will perform perform detected locale-specific translations replacement:

Unit Tests

For tests and examples, check following files/folders in API sources:

Reference Guide

Class Reader

Lucinda\Internationalization\Reader encapsulates retrieving unit translations from storage and defines following relevant public methods:

Method Arguments Returns Description
getTranslation string $key, string $domain=null string Gets value of translation based on locale. If none found, value of $key is returned!

Class Writer

Lucinda\Internationalization\Writer encapsulates adding/updating/deleting unit translations from storage and defines following relevant public methods:

Method Arguments Returns Description
setTranslation string $key, string $value void Sets a unit translation for detected locale based on its keyword and value.
unsetTranslation string $key void Deletes a unit translation for detected locale based on its keyword
save void void Persists changes to JSON translation file.

All versions of internationalization with dependencies

PHP Build Version
Package Version
Requires 0 Version __unset
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 lucinda/internationalization contains the following files

Loading the files please wait ....