Skip to content

Commit

Permalink
v1.0.2
Browse files Browse the repository at this point in the history
Added new methods (getPath, getCode, setCode, getDefaultTranslation) to the Localizer.php
  • Loading branch information
nabeghe committed May 5, 2024
1 parent 89b7046 commit 5877b38
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 17 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nabeghe/light-localization",
"description": "A light weight, key-value & path-based PHP localization library that translations are loaded up when needed.",
"type": "library",
"version": "1.0.1",
"version": "1.0.2",
"homepage": "https://github.com/nabeghe/light-localization",
"license": "MIT",
"autoload": {
Expand Down
64 changes: 48 additions & 16 deletions src/Localizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,54 @@ class Localizer
protected array $translators = [];

/**
* Retrieves the lost of loaded translators.
* Retrieves the root path.
*/
public function getPath(): string
{
return $this->path;
}

/**
* Retrieves the current language code.
*/
public function getCode(): string
{
return $this->code;
}

/**
* Changes the localization code.
* @param string $code New code.
* @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.
*/
public function setCode(string $code, bool $refresh = false): void
{
$this->code = $code;
if ($refresh) {
$this->refresh();
} else {
$this->translators = [];
}
}

/**
* An alias for the {@see setcode}
*/
public function recode(string $code, bool $refresh = false): void
{
$this->setCode($code, $refresh);
}

/**
* Retrieves the default translation.
*/
public function getDefaultTranslation()
{
return $this->defaultTranslation;
}

/**
* Retrieves the list of loaded translators.
* @return array
*/
public function getTranslators(): array
Expand Down Expand Up @@ -137,21 +184,6 @@ public function unload(string $translator = self::DEFAULT_TRANSLATOR): bool
return false;
}

/**
* Changes the localization code.
* @param string $code New code.
* @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.
*/
public function recode(string $code, bool $refresh = false): void
{
$this->code = $code;
if ($refresh) {
$this->refresh();
} else {
$this->translators = [];
}
}

/**
* Checks whether a key exists in a translator or not.
* @param string $key
Expand Down

0 comments on commit 5877b38

Please sign in to comment.