{"id":18546767,"url":"https://github.com/nabeghe/light-localization","last_synced_at":"2026-02-28T01:20:03.009Z","repository":{"id":217971768,"uuid":"745257784","full_name":"nabeghe/light-localization","owner":"nabeghe","description":"A light weight and path-based PHP localization library that translations are loaded up when needed.","archived":false,"fork":false,"pushed_at":"2025-07-03T12:36:24.000Z","size":32,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-14T14:34:29.860Z","etag":null,"topics":["library","localization","localizer","php","php-library","php-localization","php-translation"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nabeghe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-19T00:17:14.000Z","updated_at":"2025-07-03T12:36:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"61009de8-844d-4827-a8b0-d7d999d9a81d","html_url":"https://github.com/nabeghe/light-localization","commit_stats":null,"previous_names":["nabeghe/light-localization"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/nabeghe/light-localization","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nabeghe%2Flight-localization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nabeghe%2Flight-localization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nabeghe%2Flight-localization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nabeghe%2Flight-localization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nabeghe","download_url":"https://codeload.github.com/nabeghe/light-localization/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nabeghe%2Flight-localization/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279013999,"owners_count":26085345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["library","localization","localizer","php","php-library","php-localization","php-translation"],"created_at":"2024-11-06T20:26:54.224Z","updated_at":"2026-02-28T01:20:03.003Z","avatar_url":"https://github.com/nabeghe.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Light Localization\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/user-attachments/assets/b14ef73b-a458-4d7f-84f8-8ce6b8d84740\" width=\"400\"/\u003e\n\u003c/p\u003e\n\n\u003e A lightweight, key-value \u0026 path-based PHP localization library.  \n\u003e Translation groups are loaded lazily — only when first accessed.\n\n## Requirements\n\n- PHP \u003e= 7.4\n- [nabeghe/atlin](https://github.com/nabeghe/atlin-php)\n\n## Installation\n\n```bash\ncomposer require nabeghe/light-localization\n```\n\n## Directory Structure\n\nOrganize your translations like this:\n\n```\n/langs/\n  /en/\n      main.php\n      messages.php\n      extra.atlin\n  /fa/\n      main.php\n      extra.atlin\n```\n\n- Each sub-directory represents a **locale code**.\n- Each file inside is a **translation group** (identified by filename without extension).\n- Files can be `.php` (returning an array) or `.atlin` format.\n- `.atlin` files take precedence over `.php` when both exist for the same group name.\n\n## Quick Start\n\n```php\nuse Nabeghe\\LightLocalization\\Localizer;\n\n$en = new Localizer(__DIR__ . '/langs', 'en');\n$fa = new Localizer(__DIR__ . '/langs', 'fa', $en); // $en is the fallback\n\n// Reads from main.php (default group)\necho $fa-\u003eget('title');\n\n// Reads from messages.php\necho $fa-\u003eget('success', 'messages');\n\n// Returns a random item when the value is an array\necho $fa-\u003ernd('greet');\n```\n\n## Constructor\n\n```php\nnew Localizer(\n    string $path,\n    string $locale = 'en',\n    Localizer|string|null $fallback = null,\n    ?string $defaultTranslationText = null,\n    ?Atlin $atlin = null\n);\n```\n\n| Parameter | Description |\n|---|---|\n| `$path` | Absolute path to the translations root directory |\n| `$locale` | Active locale code |\n| `$fallback` | Another `Localizer` to chain, or a plain string used as default |\n| `$defaultTranslationText` | Returned when no translation is found anywhere in the chain |\n| `$atlin` | Custom `Atlin` instance; created automatically if `null` |\n\n## Translation Files\n\n### PHP\n\nReturn a plain associative array. Values can be strings or arrays of strings (for `rnd()`).\n\n```php\n\u003c?php\n// langs/en/main.php\nreturn [\n    'title'   =\u003e 'Hello World',\n    'greet'   =\u003e ['Hi!', 'Hey!', 'Hello!'],\n];\n```\n\n### Atlin\n\nStandard key-value `.atlin` format:\n\n```\n@title\nHello Atlin World\n\n@description\nA lightweight localization library\n```\n\n## API Reference\n\n### Locale\n\n| Method | Description |\n|---|---|\n| `getLocale(): string` | Returns the current locale |\n| `setLocale(string $locale): void` | Changes the locale and clears all loaded groups |\n| `getLastLocale(): ?string` | Locale used in the most recent successful lookup |\n\n### Lookup\n\n| Method | Description |\n|---|---|\n| `get(string $key, string $group = 'main', bool $deep = true): ?string` | Returns the translation for a key |\n| `rnd(string $key, string $group = 'main', bool $deep = true): ?string` | Like `get()`, but picks a random item when the value is an array |\n| `has(string $key, string $group = 'main', bool $deep = true): bool` | Checks whether a key exists |\n\n### Group Management\n\n| Method | Description |\n|---|---|\n| `load(string $group): bool` | Loads a translation group from disk |\n| `refresh(): void` | Reloads all currently loaded groups |\n| `reset(): void` | Clears all loaded groups from memory |\n| `resetTranslation(string $group): bool` | Removes a specific group from memory |\n| `hasTranslation(string $group): bool` | Checks whether a group is loaded in memory |\n| `hasTranslationFile(string $group): bool` | Checks whether a group file exists on disk |\n\n### Fallback \u0026 Default Text\n\n| Method | Description |\n|---|---|\n| `getFallback()` | Returns the current fallback (Localizer or string) |\n| `setFallback(Localizer\\|string\\|null $fallback): void` | Sets a new fallback |\n| `getDefaultTranslationText(): ?string` | Returns the static default text |\n| `setDefaultTranslationText(?string $text): void` | Sets the static default text |\n\n## Fallback Chain\n\nWhen a key is not found in the active locale, the library resolves it in this order:\n\n1. Current locale group (lazy-loaded from disk)\n2. Fallback `Localizer` (if provided), recursively\n3. Fallback string (if provided instead of a Localizer)\n4. `defaultTranslationText` (constructor parameter / setter)\n5. `null`\n\n## Running Tests\n\n```bash\ncomposer test\n```\n\n## License\n\nLicensed under the [MIT License](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnabeghe%2Flight-localization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnabeghe%2Flight-localization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnabeghe%2Flight-localization/lists"}