Download the PHP package wufr/php-language-localizer without Composer

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

PHP Language Localizer

A small, dependency-free PHP library for translating and localizing applications: plain PHP locale files, parameter replacement with HTML escaping, CLDR plural rules, gender variants, fallback languages and layered locale directories.

Latest Version on Packagist PHP Version

Features

Installation

Requirements: PHP 8.1 or higher. ext-intl is optional and only used for locale-aware number and date placeholders.

Upgrading from 1.x? See UPGRADE.md.

Basic Usage

Setters are chainable:

Locale files

A locale file returns an array (or assigns it to $l, the format used by 1.x):

Locale files are PHP code and are fully trusted: only load files you ship yourself. Each file runs in an isolated scope and is loaded once per Translator instance.

Names. A file name is one or more segments separated by /, each made of letters, digits, _, - and . (not starting with a dot). A language is a directory name made of letters, digits, _ and -. Any other name, for example one containing .., \ or an absolute path, never touches the file system and is reported as a missing translation. This makes it safe to pass a language chosen by the visitor, although checking it against the languages you support is still the better choice.

Parameters

All placeholders are replaced in a single pass, so a value that contains {something} is never expanded again. A placeholder without a matching parameter is left as it is.

Values can be strings, numbers, null, bool, enums and Stringable objects. Other types (arrays, plain objects) trigger an E_USER_WARNING and render as an empty string.

Escaping

Parameter values are HTML-escaped by default, because translations usually end up in HTML and values often come from users. The translation text itself is trusted and may contain markup:

To insert trusted markup without escaping, pick the narrowest option:

Never mark user input as raw.

Numbers and dates

With ext-intl installed, typed placeholders format values for the current language:

Date values may be a DateTimeInterface, a Unix timestamp or a date string. Without ext-intl numbers are printed as plain digits and dates as Y-m-d, H:i or Y-m-d H:i.

Pluralization

Pass the number as _counter. It is also available as the {count} placeholder unless you pass count yourself.

CLDR plural categories (recommended)

Use the CLDR plural categories of the language: zero, one, two, few, many and other. The library knows the rules of 60+ languages, including the Slavic ones where 22 and 25 need different forms, and falls back to other when a category is not defined.

Fractions follow CLDR too: 1.5 is many in Czech and other in English. Visible decimals count, so pass '1.0' as a string to get "1.0 items" in English, while the integer 1 gives "1 item".

Languages without a built-in rule use the English one (one for exactly 1). Add or replace a rule with:

Numeric thresholds

Without category keys, integer keys are thresholds: the variant with the highest key that is less than or equal to the counter wins. The order of the keys does not matter, and a counter below every key uses the lowest one.

Thresholds are enough for languages like English or Czech with integer counts. Use categories for languages with more complex rules.

Gender

_gender accepts a Gender case (or any backed enum) or a string key; the keys are not limited to the four Gender values.

Gender and plural variants can be combined. The gender is selected first:

Fallback languages

When the current language lacks a file or a key, the fallback languages are tried in order:

Plural rules and number formats follow the language the text was found in.

Layered locale directories

Pass several directories, highest priority first. Each locale file is merged across every directory that has it, so the first directory can override single keys and leave the rest of the file to the others:

Missing translations

A missing file, key or variant never throws and never breaks the page. By default the translator returns the file.key identifier (escaped), for example common/general.welcome.

Set a handler to log, show something else or throw:

MissingTranslation has the reason (a MissingReason case: FileNotFound, KeyNotFound, InvalidName, SelectorMissing, VariantNotFound, InvalidCounter or InvalidValue), file, key, language and an optional detail. The handler's return value is output as it is, so escape anything you build from these values.

Check for a key without triggering the handler:

API Reference

wUFr\Translator

Reserved parameters: _counter (plural number), _gender (gender key or enum) and _raw (true or a list of parameter names to insert without escaping).

Translator implements wUFr\Localizer\TranslatorInterface (locale() and has()), which is the type to depend on in your own code.

wUFr\Gender

getPronoun(), getPossessivePronoun() and getObjectPronoun() still exist but are deprecated: they return English words only. Put pronouns into your locale files as gender variants instead.

Security

See SECURITY.md for what the library guarantees and how to report a vulnerability.

Contributing

Create a new branch from the release-candidate branch and submit a pull request. Run the checks before pushing:

Commit messages follow Conventional Commits, which drive the automatic releases.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.


All versions of php-language-localizer with dependencies

PHP Build Version
Package Version
Requires php Version ^8.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 wufr/php-language-localizer contains the following files

Loading the files please wait ...