Skip to content

Commit 5877b38

Browse files
committed
v1.0.2
Added new methods (getPath, getCode, setCode, getDefaultTranslation) to the Localizer.php
1 parent 89b7046 commit 5877b38

File tree

2 files changed

+49
-17
lines changed

2 files changed

+49
-17
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "nabeghe/light-localization",
33
"description": "A light weight, key-value & path-based PHP localization library that translations are loaded up when needed.",
44
"type": "library",
5-
"version": "1.0.1",
5+
"version": "1.0.2",
66
"homepage": "https://github.com/nabeghe/light-localization",
77
"license": "MIT",
88
"autoload": {

src/Localizer.php

+48-16
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,54 @@ class Localizer
4040
protected array $translators = [];
4141

4242
/**
43-
* Retrieves the lost of loaded translators.
43+
* Retrieves the root path.
44+
*/
45+
public function getPath(): string
46+
{
47+
return $this->path;
48+
}
49+
50+
/**
51+
* Retrieves the current language code.
52+
*/
53+
public function getCode(): string
54+
{
55+
return $this->code;
56+
}
57+
58+
/**
59+
* Changes the localization code.
60+
* @param string $code New code.
61+
* @param bool $refresh Optional. After changing the code, should it reload the loaded translators or remove all of them from the loaded state? Default false.
62+
*/
63+
public function setCode(string $code, bool $refresh = false): void
64+
{
65+
$this->code = $code;
66+
if ($refresh) {
67+
$this->refresh();
68+
} else {
69+
$this->translators = [];
70+
}
71+
}
72+
73+
/**
74+
* An alias for the {@see setcode}
75+
*/
76+
public function recode(string $code, bool $refresh = false): void
77+
{
78+
$this->setCode($code, $refresh);
79+
}
80+
81+
/**
82+
* Retrieves the default translation.
83+
*/
84+
public function getDefaultTranslation()
85+
{
86+
return $this->defaultTranslation;
87+
}
88+
89+
/**
90+
* Retrieves the list of loaded translators.
4491
* @return array
4592
*/
4693
public function getTranslators(): array
@@ -137,21 +184,6 @@ public function unload(string $translator = self::DEFAULT_TRANSLATOR): bool
137184
return false;
138185
}
139186

140-
/**
141-
* Changes the localization code.
142-
* @param string $code New code.
143-
* @param bool $refresh Optional. After changing the code, should it reload the loaded translators or remove all of them from the loaded state? Default false.
144-
*/
145-
public function recode(string $code, bool $refresh = false): void
146-
{
147-
$this->code = $code;
148-
if ($refresh) {
149-
$this->refresh();
150-
} else {
151-
$this->translators = [];
152-
}
153-
}
154-
155187
/**
156188
* Checks whether a key exists in a translator or not.
157189
* @param string $key

0 commit comments

Comments
 (0)