https://github.com/davidlienhard/i18n
🐘 php library to use for internationalization
https://github.com/davidlienhard/i18n
Last synced: 5 months ago
JSON representation
🐘 php library to use for internationalization
- Host: GitHub
- URL: https://github.com/davidlienhard/i18n
- Owner: davidlienhard
- License: mit
- Created: 2020-11-12T06:02:36.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-12-13T08:01:45.000Z (7 months ago)
- Last Synced: 2025-12-14T22:12:56.436Z (7 months ago)
- Language: PHP
- Homepage:
- Size: 209 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# davidlienhard/i18n
🐘 php library to use for internationalization
[](https://packagist.org/packages/davidlienhard/i18n)
[](https://github.com/davidlienhard/i18n)
[](https://github.com/davidlienhard/i18n/blob/master/LICENSE)
[](https://php.net/)
[](https://github.com/davidlienhard/i18n/actions/workflows/check.yml)
## Setup
You can install through `composer` with:
```
composer require davidlienhard/i18n:^2
```
*Note: davidlienhard/i18n requires PHP 8.0*
## How to use
### 1. Create language files
Create at least one language file. Supported filetypes are `json`, `yaml`, `yml` or `ini`.
`./lang/en.yml` (English)
```yml
save: Save
greeting: Hi %1
```
`./lang/de.yml` (German)
```yml
save: Speichern
greeting: Hallo %1
```
### 2. Load the class
Use composer autoloader if possible or include the files in the `src` folders manually
### 3. Create the object
```php
setNamespace("YourApp\Translations");
```
The following setter methods are available:
- `setFilePath(string $filePath)`: Sets the path to the language files
- `setCachePath(string $cachePath)`: Sets the path to the cache directory
- `setFallbackLang(string $fallbackLang)`: sets a fallback language
- `setMergeFallback(bool $mergeFallback)`: whether or not to merge the fallback language
- `setPrefix(string $prefix)`: Sets the prefix/name of the class to contain the translations
- `setForcedLang(string $forcedLang)`: a language that is forced to be used
- `setSectionSeparator(string $sectionSeparator)`: the character to use to concatenate sections
### 5. Initialize the class / create cache-files
```php
$i18n->init();
```
Thss will then create the cache file if required and load the new translation data with the given namespace & prefix/class-name.
### 6. Use the translation data
```php
use YourApp\Translations\L;
echo L::save; // Save / Speichern
echo L::get("save"); // Save / Speichern
echo L::greeting("David"); // Hi David // Hallo David
echo L::get("greeting", "David"); // Hi David // Hallo David
```
## License
The MIT License (MIT). Please see [LICENSE](https://github.com/davidlienhard/i18n/blob/master/LICENSE) for more information.