{"id":19112546,"url":"https://github.com/xbyter/zt-i18n","last_synced_at":"2026-06-18T08:32:05.261Z","repository":{"id":198469058,"uuid":"687774538","full_name":"xbyter/zt-i18n","owner":"xbyter","description":null,"archived":false,"fork":false,"pushed_at":"2024-01-02T08:21:28.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-24T21:56:04.271Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xbyter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-09-06T01:28:30.000Z","updated_at":"2023-09-06T01:58:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"3ef2824a-cf00-4abc-ac12-915f2d86bf13","html_url":"https://github.com/xbyter/zt-i18n","commit_stats":null,"previous_names":["xbyter/zt-i18n"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/xbyter/zt-i18n","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xbyter%2Fzt-i18n","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xbyter%2Fzt-i18n/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xbyter%2Fzt-i18n/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xbyter%2Fzt-i18n/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xbyter","download_url":"https://codeload.github.com/xbyter/zt-i18n/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xbyter%2Fzt-i18n/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34483275,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-18T02:00:06.871Z","response_time":128,"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":[],"created_at":"2024-11-09T04:33:27.364Z","updated_at":"2026-06-18T08:32:05.238Z","avatar_url":"https://github.com/xbyter.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# I18n PHP客户端\n\n# 安装\n## 1. 从composer拉取包\n```php\ncomposer require ztphp/zt-i18n\n```\n## 2. 执行发布命令，注册artisan命令行和拷贝默认配置文件到config目录\n```php\nphp artisan vendor:publish --provider=\"ZtI18n\\Laravel\\Providers\\I18nServiceProvider\" --tag=config\n```\n## 3. 配置config/i18n.php文件\n```php\nreturn [\n    //服务端多语言存放目录，用于保存同步i18n服务端多语言\n    'server_resource_dir' =\u003e storage_path('i18n/json'),\n    //本地语言存放目录，用于保存本地的多语言，当服务端找不到key时会调用本地多语言\n    'local_resource_dir'  =\u003e resource_path('lang'),\n    //站点支持的语言\n    'languages'           =\u003e ['zh-CN', 'en-US'],\n    //阿波罗配置，用于从阿波罗里同步多语言\n    'apollo'              =\u003e [\n        //命名空间前缀, 完整的命名空间格式为namespace_prefix + '-' + lang，例如fbg-eld-api-zh-CN\n        'namespace_prefix'   =\u003e 'fbg-eld-api',\n        //阿波罗配置服务器地址\n        'config_server_url' =\u003e '',\n        //阿波罗AppID\n        'app_id'            =\u003e '',\n        //阿波罗集群配置\n        'cluster'           =\u003e 'default',\n        //阿波罗密钥\n        'secret'            =\u003e '',\n    ],\n];\n```\n## 4. 新增i18n服务感知路由（控制器I18nController返回本地新增的多语言）\n```php\n    Route::get('/i18n', 'ZtI18n\\Laravel\\Controllers\\I18nController@newData');\n```\n# 功能示例\n\n## 1. 从阿波罗同步数据到本地\n```php\n//只执行一次同步\nphp artisan zt-i18n:sync -O\n//常驻执行同步（配合supervisor使用）\nphp artisan zt-i18n:sync\n//常驻60秒执行同步（配合定时任务使用）\nphp artisan zt-i18n:sync 60\n```\n## 2. 根据Key进行翻译\n```php\n//可以使用{0},{1}等变量，如：product[{0}] not exists\napp(I18nClientInterface::class)-\u003eget('10101000', ['EL320-SKU001']);\n\n//也可以使用函数来替换上面语句\ni('10101000', ['EL320-SKU001']);\n```\n\n## 3. 替换接口实现\n\u003e 如果默认的加载器/存储器不符合项目的要求，可重新实现LoaderInterface, FallbackLoaderInterface等接口，示例可参考：I18nServiceProvider\n```php\n    /**\n     * 注册i18n加载器，用于加载多语言数据\n     * @return void\n     */\n    protected function registerLoader()\n    {\n        $this-\u003eapp-\u003esingleton(LoaderInterface::class, function ($app) {\n            $dir = $this-\u003egetConfig('i18n.server_resource_dir');\n            return new JsonFileLoader($dir);\n        });\n    }\n    /**\n     * 注册i18n备用加载器，当默认加载器找不到key时使用备用加载器\n     * @return void\n     */\n    public function registerFallbackLoader()\n    {\n        $this-\u003eapp-\u003esingleton(FallbackLoaderInterface::class, function () {\n            $dir = $this-\u003egetConfig('i18n.local_resource_dir');\n            return new JsonFileLoader($dir);\n        });\n    }\n\n    /**\n     * 注册i18n客户端\n     * @return void\n     */\n    protected function registerClient()\n    {\n        $this-\u003eapp-\u003esingleton(I18nClientInterface::class, function () {\n            $client = new I18nClient($this-\u003eapp-\u003emake(LoaderInterface::class));\n            $client-\u003esetFallbackLoader($this-\u003eapp-\u003emake(FallbackLoaderInterface::class));\n            $client-\u003esetLang($this-\u003eapp-\u003egetLocale());\n            return $client;\n        });\n    }\n\n    /**\n     * 注册i18n同步器，同步i18n服务器数据到本地\n     * @return void\n     */\n    protected function registerSync()\n    {\n        $this-\u003eapp-\u003esingleton(I18nSyncInterface::class, function () {\n            $languages = $this-\u003egetConfig('i18n.languages');\n            $apolloClient = $this-\u003egetApolloClient();\n            $dir = $this-\u003egetConfig('i18n.server_resource_dir');\n            $store = new JsonFileStore($dir);\n\n            $sync = new I18nApolloSync($apolloClient, $store);\n            $namespacePrefix = $this-\u003egetConfig('apollo.namespace_prefix');\n            foreach ($languages as $language) {\n                $sync-\u003eaddNamespace($language, \"{$namespacePrefix}-{$language}\");\n            }\n            return $sync;\n        });\n    }\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxbyter%2Fzt-i18n","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxbyter%2Fzt-i18n","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxbyter%2Fzt-i18n/lists"}