{"id":20031170,"url":"https://github.com/gohouse/i18n","last_synced_at":"2025-05-05T04:31:24.816Z","repository":{"id":112508743,"uuid":"218258918","full_name":"gohouse/i18n","owner":"gohouse","description":"golang i18n, golang实现的多语言解析使用","archived":false,"fork":false,"pushed_at":"2020-07-27T04:02:44.000Z","size":25,"stargazers_count":12,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-08T16:55:08.287Z","etag":null,"topics":["go-i18n","golang-i18n","i18n","language","multi-language"],"latest_commit_sha":null,"homepage":"","language":"Go","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/gohouse.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":"2019-10-29T10:16:11.000Z","updated_at":"2024-06-18T18:18:30.000Z","dependencies_parsed_at":"2023-06-18T11:03:29.498Z","dependency_job_id":null,"html_url":"https://github.com/gohouse/i18n","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gohouse%2Fi18n","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gohouse%2Fi18n/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gohouse%2Fi18n/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gohouse%2Fi18n/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gohouse","download_url":"https://codeload.github.com/gohouse/i18n/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252439623,"owners_count":21748045,"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","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":["go-i18n","golang-i18n","i18n","language","multi-language"],"created_at":"2024-11-13T09:31:23.031Z","updated_at":"2025-05-05T04:31:24.402Z","avatar_url":"https://github.com/gohouse.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# i18n\ngolang i18n, golang实现的多语言解析使用  \ninternationalization （国际化）简称：i18n，因为在i和n之间还有18个字符，localization（本地化 ），简称L10n。 一般用语言_地区的形式表示一种语言，如：zh_CN表示简体中文。\n\n## 安装\n- go mod\n```shell script\nrequire github.com/gohouse/i18n master\n```\n- go get\n```shell script\ngo get github.com/gohouse/i18n\n```\n\n## 使用\n可以查看包内的示例代码: [https://github.com/gohouse/i18n/blob/master/examples/demo.go](https://github.com/gohouse/i18n/blob/master/examples/demo.go)  \n\n添加语言文件\n```shell script\n# 创建文件夹\nmkdir -p /go/src/gopro/language/zh_cn /go/src/gopro/language/en-us\n\n# 编写中文语言文件\ncat \u003e\u003e~/go/src/gopro/language/zh_cn/error.json\u003c\u003cEOF\n{\n  \"test\": \"测试\",\n  \"params_format_error\": \"参数格式有误\",\n  \"params_missing\": \"参数缺失\",\n  \"err2\": {\n    \"aa\": \"aaxx\",\n    \"bb\": {\n      \"cc\": \"cc\"\n    }\n  }\n}\nEOF\n\n# 编写英文语言文件\ncat \u003e\u003e~/go/src/gopro/language/en-us/error.json\u003c\u003cEOF\n{\n  \"test\": \"just a test\",\n  \"params_format_error\": \"Incorrect parameters format\",\n  \"params_missing\": \"Missing parameters\",\n  \"err2\": {\n    \"aa\": \"aaxx\",\n    \"bb\": {\n      \"cc\": \"cc\"\n    }\n  }\n}\nEOF\n```\n编写go代码文件`~/go/src/gopro/demo.go`\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/gohouse/i18n\"\n\t// 这里不要忘记引入默认的json驱动\n\t_ \"github.com/gohouse/i18n/parser_json\"\n)\n\nfunc main() {\n\tlang := i18n.NewI18n(\n\t\t// 这里指定语言文件路径\n\t\ti18n.LangDirectory(\"/go/src/github.com/gohouse/i18n/examples/language\"),\n\n\t\t// 这里如果不i设置, 则默认使用zh_cn\n\t\t//i18n.DefaultLang(\"zh_cn\"),\n\n\t\t// 这里如果不i设置, 则默认使用 json,可以自定义解析器和配置文件格式\n\t\t//i18n.DefaultParser(\"json\"),\n\t)\n\n\t// 加载error.json文件内的具体配置项, 多级加载, 使用.连接\n\ttest := lang.LoadWithDefault(\"error.test\")\n\ttest2 := lang.LoadWithDefault(\"error.err2.bb.cc\")\n\n\tfmt.Println(test)\n\tfmt.Println(test2)\n}\n```\n结果\n```shell script\n测试\ncc\n```\n\n## 额外说明\ni18n默认提供了json解析器, 同时, 提供了解析器接口, 可以自由定制其他格式的解析器, 如yml,ini,toml等\n\n\n## 附件 - 国际化开发的各国语言标识\n语言标识|国家地区  \n---|:---  \nzh_CN  |  简体中文(中国)  \nzh_TW  |  繁体中文(台湾地区)  \nzh_HK  |  繁体中文(香港)  \nen_HK  |  英语(香港)  \nen_US  |  英语(美国)  \nen_GB  |  英语(英国)  \nen_WW  |  英语(全球)  \nen_CA  |  英语(加拿大)  \nen_AU  |  英语(澳大利亚)  \nen_IE  |  英语(爱尔兰)  \nen_FI  |  英语(芬兰)  \nfi_FI  |  芬兰语(芬兰)  \nen_DK  |  英语(丹麦)  \nda_DK  |  丹麦语(丹麦)  \nen_IL  |  英语(以色列)  \nhe_IL  |  希伯来语(以色列)  \nen_ZA  |  英语(南非)  \nen_IN  |  英语(印度)  \nen_NO  |  英语(挪威)  \nen_SG  |  英语(新加坡)  \nen_NZ  |  英语(新西兰)  \nen_ID  |  英语(印度尼西亚)  \nen_PH  |  英语(菲律宾)  \nen_TH  |  英语(泰国)  \nen_MY  |  英语(马来西亚)  \nen_XA  |  英语(阿拉伯)  \nko_KR  |  韩文(韩国)  \nja_JP  |  日语(日本)  \nnl_NL  |  荷兰语(荷兰)  \nnl_BE  |  荷兰语(比利时)  \npt_PT  |  葡萄牙语(葡萄牙)  \npt_BR  |  葡萄牙语(巴西)  \nfr_FR  |  法语(法国)  \nfr_LU  |  法语(卢森堡)  \nfr_CH  |  法语(瑞士)  \nfr_BE  |  法语(比利时)  \nfr_CA  |  法语(加拿大)  \nes_LA  |  西班牙语(拉丁美洲)  \nes_ES  |  西班牙语(西班牙)  \nes_AR  |  西班牙语(阿根廷)  \nes_US  |  西班牙语(美国)  \nes_MX  |  西班牙语(墨西哥)  \nes_CO  |  西班牙语(哥伦比亚)  \nes_PR  |  西班牙语(波多黎各)  \nde_DE  |  德语(德国)  \nde_AT  |  德语(奥地利)  \nde_CH  |  德语(瑞士)  \nru_RU  |  俄语(俄罗斯)  \nit_IT  |  意大利语(意大利)  \nel_GR  |  希腊语(希腊)  \nno_NO  |  挪威语(挪威)  \nhu_HU  |  匈牙利语(匈牙利)  \ntr_TR  |  土耳其语(土耳其)  \ncs_CZ  |  捷克语(捷克共和国)  \nsl_SL  |  斯洛文尼亚语   \npl_PL  |  波兰语(波兰)  \nsv_SE  |  瑞典语(瑞典)  \nes_CL  |  西班牙语 (智利)  ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgohouse%2Fi18n","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgohouse%2Fi18n","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgohouse%2Fi18n/lists"}