Download the PHP package nabeghe/light-localization without Composer
On this page you can find all versions of the php package nabeghe/light-localization. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download nabeghe/light-localization
More information about nabeghe/light-localization
Files in nabeghe/light-localization
Download nabeghe/light-localization
More information about nabeghe/light-localization
Files in nabeghe/light-localization
Vendor nabeghe
Package light-localization
Short Description A light weight, key-value & path-based PHP localization library that translations are loaded up when needed.
License MIT
Homepage https://github.com/nabeghe/light-localization
Package light-localization
Short Description A light weight, key-value & path-based PHP localization library that translations are loaded up when needed.
License MIT
Homepage https://github.com/nabeghe/light-localization
Please rate this library. Is it a good library?
Informations about the package light-localization
Light Localization
A lightweight, key-value & path-based PHP localization library.
Translation groups are loaded lazily — only when first accessed.
Requirements
- PHP >= 7.4
- nabeghe/atlin
Installation
Directory Structure
Organize your translations like this:
- Each sub-directory represents a locale code.
- Each file inside is a translation group (identified by filename without extension).
- Files can be
.php(returning an array) or.atlinformat. .atlinfiles take precedence over.phpwhen both exist for the same group name.
Quick Start
Constructor
| Parameter | Description |
|---|---|
$path |
Absolute path to the translations root directory |
$locale |
Active locale code |
$fallback |
Another Localizer to chain, or a plain string used as default |
$defaultTranslationText |
Returned when no translation is found anywhere in the chain |
$atlin |
Custom Atlin instance; created automatically if null |
Translation Files
PHP
Return a plain associative array. Values can be strings or arrays of strings (for rnd()).
Atlin
Standard key-value .atlin format:
API Reference
Locale
| Method | Description |
|---|---|
getLocale(): string |
Returns the current locale |
setLocale(string $locale): void |
Changes the locale and clears all loaded groups |
getLastLocale(): ?string |
Locale used in the most recent successful lookup |
Lookup
| Method | Description |
|---|---|
get(string $key, string $group = 'main', bool $deep = true): ?string |
Returns the translation for a key |
rnd(string $key, string $group = 'main', bool $deep = true): ?string |
Like get(), but picks a random item when the value is an array |
has(string $key, string $group = 'main', bool $deep = true): bool |
Checks whether a key exists |
Group Management
| Method | Description |
|---|---|
load(string $group): bool |
Loads a translation group from disk |
refresh(): void |
Reloads all currently loaded groups |
reset(): void |
Clears all loaded groups from memory |
resetTranslation(string $group): bool |
Removes a specific group from memory |
hasTranslation(string $group): bool |
Checks whether a group is loaded in memory |
hasTranslationFile(string $group): bool |
Checks whether a group file exists on disk |
Fallback & Default Text
| Method | Description |
|---|---|
getFallback() |
Returns the current fallback (Localizer or string) |
setFallback(Localizer\|string\|null $fallback): void |
Sets a new fallback |
getDefaultTranslationText(): ?string |
Returns the static default text |
setDefaultTranslationText(?string $text): void |
Sets the static default text |
Fallback Chain
When a key is not found in the active locale, the library resolves it in this order:
- Current locale group (lazy-loaded from disk)
- Fallback
Localizer(if provided), recursively - Fallback string (if provided instead of a Localizer)
defaultTranslationText(constructor parameter / setter)null
Running Tests
License
Licensed under the MIT License.
All versions of light-localization with dependencies
PHP Build Version
Package Version
The package nabeghe/light-localization contains the following files
Loading the files please wait ...