{"id":20846639,"url":"https://github.com/yohn/lang","last_synced_at":"2026-01-28T05:23:36.680Z","repository":{"id":259837826,"uuid":"879463159","full_name":"Yohn/Lang","owner":"Yohn","description":"Simple Language PHP Class","archived":false,"fork":false,"pushed_at":"2025-06-06T07:14:21.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-16T04:17:13.533Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/Yohn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2024-10-28T00:28:43.000Z","updated_at":"2025-06-06T07:03:40.000Z","dependencies_parsed_at":"2024-10-28T09:27:29.338Z","dependency_job_id":"042cce27-90cf-4bf8-96a8-d938a351e99e","html_url":"https://github.com/Yohn/Lang","commit_stats":null,"previous_names":["yohn/lang"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Yohn/Lang","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yohn%2FLang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yohn%2FLang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yohn%2FLang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yohn%2FLang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Yohn","download_url":"https://codeload.github.com/Yohn/Lang/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yohn%2FLang/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28840089,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T02:10:51.810Z","status":"ssl_error","status_checked_at":"2026-01-28T02:10:50.806Z","response_time":57,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2024-11-18T02:17:15.666Z","updated_at":"2026-01-28T05:23:36.673Z","avatar_url":"https://github.com/Yohn.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Yohns\\Lang\\Text\n\nSimple and easy PHP translation library with auto-generation support, dot notation, and seamless integration with `yohns/config`.\n\n## Installation\n\n```bash\ncomposer require yohns/lang\n```\n\n## Quick Start\n\n```php\nuse Yohns\\Core\\Config;\nuse Yohns\\Lang\\Text;\n\n// Initialize Config for your application\nnew Config(__DIR__ . '/lib/Config');\n\n// Initialize Text with language directory\n$langDir = __DIR__ . '/lib/Lang';\n$text = new Text($langDir, 'en'); // 'en' for English\n\n// Basic usage\necho Text::L('welcome', 'Welcome to our site');\n// Output: \"Welcome to our site\" (or translation if found)\n\n// With placeholders\necho Text::L('hello_user', 'Hello, [name]!', ['[name]' =\u003e 'John']);\n// Output: \"Hello, John!\"\n\n// Dot notation for nested translations\necho Text::L('pages.about', 'About Us');\n// Output: \"About Us\" (or translation if found)\n```\n\n## Features\n\n- **Auto-generation**: Missing translations are automatically added to the default language file\n- **Dot notation**: Organize translations hierarchically (e.g., `pages.about`, `messages.success.saved`)\n- **Placeholder support**: Replace `[placeholders]` with dynamic values\n- **Fallback system**: Falls back to default language, then to provided default text\n- **Config integration**: Uses `yohns/config` for file management and configuration\n- **Multiple languages**: Easy switching between languages\n\n## Overview\n\nClass `Text`\n\nThis class is responsible for handling language translations.\nIt loads language files from a specified directory using the Config class\nand provides functionality to retrieve phrases in the specified language.\nIt supports dynamic addition of phrases to the default language file\nif they do not already exist, and supports dot notation for nested keys.\n\n\n\n\n\n## Methods\n\n| Name | Description |\n|------|-------------|\n|[L](#textl)|Retrieves the translated phrase for the given phrase key.|\n|[__construct](#text__construct)|Text constructor.|\n|[getAll](#textgetall)|Retrieves all loaded texts for the current language.|\n|[reload](#textreload)|Reloads the language files from the language directory.|\n|[set](#textset)|Sets a new phrase or updates an existing one in the current language.|\n\n\n\n\n\n### Text::L\n\n**Description**\n\n```php\npublic static L (string $key, string $default, array $replacements)\n```\n\nRetrieves the translated phrase for the given phrase key.\n\nSupports dot notation for nested keys (e.g., 'pages.about').\nIf the phrase does not exist in the loaded language text,\nit adds the default text to the default language file.\n\n**Parameters**\n\n* `(string) $key`\n: The key of the phrase to retrieve (supports dot notation).\n* `(string) $default`\n: The default text to use and store if the key is not found.\n* `(array) $replacements`\n: Optional replacements for placeholders in the phrase.\n\n**Return Values**\n\n`string`\n\n\u003e The translated phrase with optional replacements.\n\n\n\u003chr /\u003e\n\n\n### Text::__construct\n\n**Description**\n\n```php\npublic __construct (string $dir, string $lingo)\n```\n\nText constructor.\n\n\n\n**Parameters**\n\n* `(string) $dir`\n: The directory where translations are located.\n* `(string) $lingo`\n: The language identifier, default is 'en'.\n\n**Return Values**\n\n`void`\n\n\n**Throws Exceptions**\n\n\n`\\Exception`\n\u003e if the specified language directory is not readable\nor the specified language file does not exist.\n\n\u003chr /\u003e\n\n\n### Text::getAll\n\n**Description**\n\n```php\npublic static getAll (void)\n```\n\nRetrieves all loaded texts for the current language.\n\n\n\n**Parameters**\n\n`This function has no parameters.`\n\n**Return Values**\n\n`mixed`\n\n\u003e An array containing all loaded texts or null if not loaded.\n\n\n\u003chr /\u003e\n\n\n### Text::reload\n\n**Description**\n\n```php\npublic static reload (void)\n```\n\nReloads the language files from the language directory.\n\n\n\n**Parameters**\n\n`This function has no parameters.`\n\n**Return Values**\n\n`void`\n\n\n\u003chr /\u003e\n\n\n### Text::set\n\n**Description**\n\n```php\npublic static set (string $key, mixed $value)\n```\n\nSets a new phrase or updates an existing one in the current language.\n\nThis is useful for runtime customization of language strings.\n\n**Parameters**\n\n* `(string) $key`\n: The key of the text to set.\n* `(mixed) $value`\n: The value to associate with the key.\n\n**Return Values**\n\n`void`\n\n\n\u003chr /\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyohn%2Flang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyohn%2Flang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyohn%2Flang/lists"}