Skip to content

Commit 5385114

Browse files
committed
v1.0.0
1 parent dd7ff1b commit 5385114

20 files changed

+1988
-161
lines changed

.phpunit.result.cache

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":1,"defects":{"ArrayBasedTranslators::testForDefaultTranslation":3,"ArrayBasedTranslators::testForDifferentTranslator":3,"ClassBasedTranslators::testForDefaultTranslation":3,"ClassBasedTranslators::testForDifferentTranslator":3},"times":{"ArrayBasedTranslators::testForGet":0.007,"ArrayBasedTranslators::testForDefaultTranslation":0.001,"ArrayBasedTranslators::testForDifferentTranslator":0,"ClassBasedTranslators::testDynamicMessage":0.156,"ClassBasedTranslators::testForGet":0.005,"ClassBasedTranslators::testForDefaultTranslation":0,"ClassBasedTranslators::testForDifferentTranslator":0}}

README.md

+33-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Light Localziation for PHP
22

3-
> A light weight and path-based PHP localization library that translations are loaded up when needed.
3+
> A light weight, key-value & path-based PHP localization library that translations are loaded up when needed.
44
55
## 🫡 Usage
66

@@ -18,9 +18,13 @@ composer require nabeghe/light-localization
1818
- In this directory, create new folders, each of these folders actually represent Localization codes.
1919
They can be language codes or anything else.
2020
- Inside each code directory, php files will be placed, each of these files has the role of a translator.
21-
These files can return an array or an object that implements the ArrayAccess interface. If it's an array, each key
22-
will represent a value, but if it's an object, each field or method is a translation key.
23-
The priority is with the method & it must return a value. With the method, you can have dynamic localization!
21+
22+
- These files can return an array or an object that inheritance from `Nabeghe\LightLocalization\Translator` class.
23+
- If it's an array, each key is a translation key & it will represent a value,
24+
but if it's an object, each field or method is a translation key.
25+
The priority is with the method & it must return a value.
26+
- With the method, you can have dynamic localization!
27+
- Objects can implement the `ArrayAccess` interface in addition to inheriting from the mentioned class.
2428

2529
### Examples
2630

@@ -29,27 +33,48 @@ Check the examples folder in the repositiry.
2933
```php
3034
use Nabeghe\LightLocalization\Localizer;
3135

32-
$localizer = new Localizer(__DIR__ . '/langs');
36+
/*
37+
* Example of Translations Directory:
38+
| /langs/
39+
| /en/
40+
| main.php
41+
| messages.php
42+
| /fa/
43+
| main.php
44+
| messages.php
45+
*/
46+
47+
$defaultLocalizer = new Localizer(__DIR__.'/langs', 'en');
48+
$localizer = new Localizer(__DIR__.'/langs', 'fa', $defaultLocalizer);
49+
50+
// value of `title` key, from `main.php` translation file (default value for second argument).
3351
echo $localizer->get('title');
52+
53+
// value of `hello` key, from `messages.php` translation file.
54+
echo $localizer->get('hello', 'messages');
3455
```
3556

3657
**Notice:** The localization code can be specified in the constructor method.
3758
Of course, it's possible to change it later via method `recode`.
3859

60+
**Notice:** "For each localizer, a default localizer can be specified in the constructor.
61+
Additionally, instead of specifying a default localizer, a string can be designated as the default translation."
62+
3963
## 🧩 Features
4064

41-
- Get the value using the key.
65+
- Get the value (translation) using the key.
4266
- Localization code (the second parameter of Localizer constructor).
43-
- Default translation value if the key doesn't exists,
67+
- Default translation that can be a string or another localizer.
4468
(the third parameter of Localizer constructor).
4569
- Create different translators in different files.
70+
- Dynamic translations using methods in the class-based translation files.
4671
- Reload the translator.
4772
- Remove the loaded translator.
4873
- Refreshing translators and reloading them.
4974
- Changing the localization code.
5075

5176
## 📖 License
5277

53-
Copyright (c) 2023 Hadi Akbarzadeh
78+
Copyright (c) 2024 Hadi Akbarzadeh
5479

5580
Licensed under the MIT license, see [LICENSE.md](LICENSE.md) for details.

composer.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "nabeghe/light-localization",
3-
"description": "A light weight and path-based PHP localization library that translations are loaded up when needed.",
3+
"description": "A light weight, key-value & path-based PHP localization library that translations are loaded up when needed.",
44
"type": "library",
5-
"version": "0.1.3",
5+
"version": "1.0.0",
66
"homepage": "https://github.com/nabeghe/light-localization",
77
"license": "MIT",
88
"autoload": {
@@ -18,7 +18,13 @@
1818
"role": "Developer"
1919
}
2020
],
21+
"scripts": {
22+
"test": "vendor/bin/phpunit tests"
23+
},
2124
"require": {
2225
"php": ">=7.4"
26+
},
27+
"require-dev": {
28+
"phpunit/phpunit": "^9.0"
2329
}
2430
}

0 commit comments

Comments
 (0)