Download the PHP package initphp/translator without Composer

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

InitPHP Translator

A micro multi-language (i18n) translation library for PHP. Load language packs from plain PHP files, look up keys (including dot-delimited nested keys), interpolate {name} placeholders, and fall back to a default language when a translation is missing.

Designed & Maintained with Tan Latest Stable Version Total Downloads License PHP Version Require

Features

Requirements

Installation

Quick start

A language file simply returns an array:

File layout vs. directory layout

Choose how your language packs are stored. Pick the mode before loading a language (i.e. before setDefault() / change()); the default is file mode.

File mode — one file per language

Directory mode — one directory per language

Each *.php file becomes a namespace keyed by its (lower-cased) file name, and keys are addressed as filename.key:

How a key is resolved

translate() resolves a key in this order and returns the first hit:

  1. The active language (set by setDefault() or change()).
  2. The inline fallback string, if you passed one (it is interpolated too).
  3. The default language, when it differs from the active one.
  4. The key itself, returned verbatim, if nothing matched.

Note: a key that points to a nested array (a namespace) rather than a string is treated as a miss and falls through the chain — it never throws.

Placeholders

Markers are written {name} and replaced from the context map. Scalar values and objects implementing __toString() are stringified; arrays and other objects are ignored, and unmatched markers are left untouched.

Methods

Method Description
setDir(string $dir): self Sets the base directory of the language packs. Trailing slashes are trimmed. Throws if the path is not a directory.
useFile(): self Selects file mode (default). Call before loading a language.
useDirectory(): self Selects directory mode. Call before loading a language.
setDefault(string $default): self Sets and loads the default (fallback) language; becomes the active one if none is set.
change(string $current): self Switches the active language, loading it on first use.
translate(string $key, ?string $fallback = null, array $context = []): string Returns the resolved, interpolated translation.
render(string $key, ?string $fallback = null, array $context = []): void Echoes the value of translate().
_r(...) Deprecated alias of translate(), kept for backward compatibility.
_e(...) Deprecated alias of render(), kept for backward compatibility.

All configuration methods return $this, so calls can be chained.

Documentation

Full guides with examples live in docs/:

Getting help

If you have questions, bug reports, or feature requests, please open an issue in the issue tracker.

Contributing

All contributions to this project will be published under the MIT License. By submitting a pull request or filing a bug, issue, or feature request, you are agreeing to comply with this waiver of copyright interest.

Before opening a pull request, run the full local check bundle:

Credits

License

Copyright © 2022 InitPHP — released under the MIT License.


All versions of translator 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 initphp/translator contains the following files

Loading the files please wait ...