{"id":22719078,"url":"https://github.com/carry0987/php-i18n","last_synced_at":"2025-08-17T10:38:51.716Z","repository":{"id":206333997,"uuid":"716388020","full_name":"carry0987/PHP-I18n","owner":"carry0987","description":"A modern internationalization system featuring JSON-format language files and efficient PHP-based caching. Supports dynamic language switching and real-time cache updates, ideal for rapid development and deployment of multilingual websites and applications.","archived":false,"fork":false,"pushed_at":"2024-09-19T19:06:20.000Z","size":64,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-06T17:58:13.819Z","etag":null,"topics":["cache","cookie","i18n","json","php8"],"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/carry0987.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}},"created_at":"2023-11-09T03:01:44.000Z","updated_at":"2024-09-19T19:05:45.000Z","dependencies_parsed_at":"2024-05-13T14:48:51.677Z","dependency_job_id":null,"html_url":"https://github.com/carry0987/PHP-I18n","commit_stats":null,"previous_names":["carry0987/php-i18n"],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/carry0987/PHP-I18n","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carry0987%2FPHP-I18n","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carry0987%2FPHP-I18n/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carry0987%2FPHP-I18n/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carry0987%2FPHP-I18n/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/carry0987","download_url":"https://codeload.github.com/carry0987/PHP-I18n/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carry0987%2FPHP-I18n/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269228565,"owners_count":24381856,"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-08-07T02:00:09.698Z","response_time":73,"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":["cache","cookie","i18n","json","php8"],"created_at":"2024-12-10T14:11:27.377Z","updated_at":"2025-08-17T10:38:51.650Z","avatar_url":"https://github.com/carry0987.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP-I18n\n[![Packgist](https://img.shields.io/packagist/v/carry0987/i18n.svg?style=flat-square)](https://packagist.org/packages/carry0987/i18n)  \nA modern internationalization system featuring JSON-format language files and efficient PHP-based caching. Supports dynamic language switching and real-time cache updates, ideal for rapid development and deployment of multilingual websites and applications.\n\n## Features\n- Supports multiple language files\n- Automatic caching of translation data for improved performance\n- Supports organization of translation keys by namespaces\n- Configurable translation file directory and cache directory\n\n## Requirements\n- Composer\n\n## File Structure\nHere's an example of the expected file structure:\n```\n.\n├── cache\n├── lang\n│   ├── en_US\n│   │   ├── general.json\n│   │   └── greeting.json\n│   └── zh_TW\n│       ├── general.json\n│       └── greeting.json\n├── src\n│   ├── /...\n│   └── I18n.php\n└── vendor\n```\n\n## Installation\nUse Composer to install the I18n class library into your project:\n\n``` bash\ncomposer require carry0987/i18n\n```\n\n## Usage\nAfter installation, you can include the `I18n` class in your project with Composer's autoloading:\n```php\nrequire_once 'vendor/autoload.php';\n\nuse carry0987\\I18n\\I18n;\n\n$i18n = new I18n([\n    'useAutoDetect' =\u003e true, // By default, the language is automatically detected\n    'langFilePath' =\u003e 'path/to/lang', \n    'cachePath' =\u003e 'path/to/cache'\n]);\n```\n\nFetch translations:\n```php\n// Use file name and key to get the translation value\necho $i18n-\u003efetch('greeting.hello'); // Outputs: \"Hello\"\n```\n\nFetch multiple translations:\n```php\n// Get multiple translations in the current language\n$translations = $i18n-\u003efetchList(); // Empty parameter returns all translations\n```\n\n## Note\nWhen accessing translations, the keys used must follow the format: `filename.key`, which ensures that each translation value is extracted from the specified file.\n\n## Advanced Usage\nIf set `useAutoDetect` to `true`, the language will be automatically detected from the browser's `Accept-Language` header. If the language is not supported, the default language will be used. Also, if you want to change cookie settings, you can set the `cookie` option:\n```php\n$config = array(\n    'useAutoDetect' =\u003e true,\n    //...\n    'cookie' =\u003e array(\n        'name' =\u003e 'lang',\n        'expire' =\u003e time()+864000,\n        'path' =\u003e '/',\n        'domain' =\u003e '',\n        'secure' =\u003e true,\n        'httponly' =\u003e true\n    )\n);\n```\n\nYou can set the language code manually:\n```php\n$i18n = new I18n([\n    'useAutoDetect' =\u003e false, // Set useAutoDetect to false to disable automatic language detection\n    //...\n]);\n// Initialize the language settings\n$i18n-\u003einitialize('en_US'); // 'en_US' is the language code\n```\n\nLoad specific language files:\n```php\n$i18n = new I18n([\n    'allowedFiles' =\u003e ['general', 'greeting'], // Set the list of language files to be loaded\n    //...\n]);\n```\n\nSet language aliases:\n```php\n// Define aliases for languages\n$i18n-\u003esetLangAlias(array('en_US' =\u003e 'English', 'zh_TW' =\u003e '繁體中文'));\n\n// Fetch the list of languages with their aliases\n$aliasedLangList = $i18n-\u003efetchLangList();\n// Outputs: array('en_US' =\u003e 'English', 'zh_TW' =\u003e '繁體中文')\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarry0987%2Fphp-i18n","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcarry0987%2Fphp-i18n","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarry0987%2Fphp-i18n/lists"}