{"id":13396804,"url":"https://github.com/chai2010/gettext-go","last_synced_at":"2025-05-16T06:04:16.538Z","repository":{"id":15545842,"uuid":"18280785","full_name":"chai2010/gettext-go","owner":"chai2010","description":":ab: GNU gettext for Go (Imported By Kubernetes)","archived":false,"fork":false,"pushed_at":"2024-04-30T09:27:27.000Z","size":884,"stargazers_count":94,"open_issues_count":10,"forks_count":26,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-16T06:03:17.729Z","etag":null,"topics":["gettext","go","golang","i18n","k8s","kubernetes","language","mo-files","po-files","translation"],"latest_commit_sha":null,"homepage":"http://pkg.go.dev/github.com/chai2010/gettext-go","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chai2010.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":"2014-03-31T03:30:27.000Z","updated_at":"2025-03-06T00:29:49.000Z","dependencies_parsed_at":"2024-06-18T12:41:31.044Z","dependency_job_id":"1ffd0acc-ac91-475d-b7d3-75709a84367e","html_url":"https://github.com/chai2010/gettext-go","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chai2010%2Fgettext-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chai2010%2Fgettext-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chai2010%2Fgettext-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chai2010%2Fgettext-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chai2010","download_url":"https://codeload.github.com/chai2010/gettext-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254478186,"owners_count":22077675,"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":["gettext","go","golang","i18n","k8s","kubernetes","language","mo-files","po-files","translation"],"created_at":"2024-07-30T18:01:03.545Z","updated_at":"2025-05-16T06:04:16.513Z","avatar_url":"https://github.com/chai2010.png","language":"Go","funding_links":[],"categories":["Library"],"sub_categories":[],"readme":"- *Go语言QQ群: 102319854, 1055927514*\n- *凹语言(凹读音“Wa”)(The Wa Programming Language): https://github.com/wa-lang/wa*\n\n----\n\n# gettext-go: GNU gettext for Go ([Imported By Kubernetes](https://pkg.go.dev/github.com/chai2010/gettext-go@v0.1.0/gettext?tab=importedby))\n\n- PkgDoc: [http://godoc.org/github.com/chai2010/gettext-go](http://godoc.org/github.com/chai2010/gettext-go)\n- PkgDoc: [http://pkg.go.dev/github.com/chai2010/gettext-go](http://pkg.go.dev/github.com/chai2010/gettext-go)\n\n## Install\n\n1. `go get github.com/chai2010/gettext-go`\n2. `go run hello.go`\n\nThe godoc.org or go.dev has more information.\n\n## Examples\n\n```Go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/chai2010/gettext-go\"\n)\n\nfunc main() {\n\tgettext := gettext.New(\"hello\", \"./examples/locale\").SetLanguage(\"zh_CN\")\n\tfmt.Println(gettext.Gettext(\"Hello, world!\"))\n\n\t// Output: 你好, 世界!\n}\n```\n\n```Go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/chai2010/gettext-go\"\n)\n\nfunc main() {\n\tgettext.SetLanguage(\"zh_CN\")\n\tgettext.BindLocale(gettext.New(\"hello\", \"locale\"))\n\n\t// gettext.BindLocale(\"hello\", \"locale\")              // from locale dir\n\t// gettext.BindLocale(\"hello\", \"locale.zip\")          // from locale zip file\n\t// gettext.BindLocale(\"hello\", \"locale.zip\", zipData) // from embedded zip data\n\n\t// translate source text\n\tfmt.Println(gettext.Gettext(\"Hello, world!\"))\n\t// Output: 你好, 世界!\n\n\t// if no msgctxt in PO file (only msgid and msgstr),\n\t// specify context as \"\" by\n\tfmt.Println(gettext.PGettext(\"\", \"Hello, world!\"))\n\t// Output: 你好, 世界!\n\n\t// translate resource\n\tfmt.Println(string(gettext.Getdata(\"poems.txt\"))))\n\t// Output: ...\n}\n```\n\nGo file: [hello.go](https://github.com/chai2010/gettext-go/blob/master/examples/hello.go); PO file: [hello.po](https://github.com/chai2010/gettext-go/blob/master/examples/locale/default/LC_MESSAGES/hello.po);\n\n----\n\n## API Changes (v0.1.0 vs v1.0.0)\n\n### Renamed package path\n\n| v0.1.0 (old)                                    | v1.0.0 (new)                            |\n| ----------------------------------------------- | --------------------------------------- |\n| `github.com/chai2010/gettext-go/gettext`        | `github.com/chai2010/gettext-go`        |\n| `github.com/chai2010/gettext-go/gettext/po`     | `github.com/chai2010/gettext-go/po`     |\n| `github.com/chai2010/gettext-go/gettext/mo`     | `github.com/chai2010/gettext-go/mo`     |\n| `github.com/chai2010/gettext-go/gettext/plural` | `github.com/chai2010/gettext-go/plural` |\n\n### Renamed functions\n\n| v0.1.0 (old)                       | v1.0.0 (new)                |\n| ---------------------------------- | --------------------------- |\n| `gettext-go/gettext.*`             | `gettext-go.*`              |\n| `gettext-go/gettext.DefaultLocal`  | `gettext-go.DefaultLanguage`|\n| `gettext-go/gettext.BindTextdomain`| `gettext-go.BindLocale`     |\n| `gettext-go/gettext.Textdomain`    | `gettext-go.SetDomain`      |\n| `gettext-go/gettext.SetLocale`     | `gettext-go.SetLanguage`    |\n| `gettext-go/gettext/po.Load`       | `gettext-go/po.LoadFile`    |\n| `gettext-go/gettext/po.LoadData`   | `gettext-go/po.Load`        |\n| `gettext-go/gettext/mo.Load`       | `gettext-go/mo.LoadFile`    |\n| `gettext-go/gettext/mo.LoadData`   | `gettext-go/mo.Load`        |\n\n### Use empty string as the default context for `gettext.Gettext`\n\n```go\npackage main\n\n// v0.1.0\n// if the **context** missing, use `callerName(2)` as the context:\n\n// v1.0.0\n// if the **context** missing, use empty string as the context:\n\nfunc main() {\n\tgettext.Gettext(\"hello\")          \n\t// v0.1.0 =\u003e gettext.PGettext(\"main.main\", \"hello\")\n\t// v1.0.0 =\u003e gettext.PGettext(\"\", \"hello\")\n\n\tgettext.DGettext(\"domain\", \"hello\")\n\t// v0.1.0 =\u003e gettext.DPGettext(\"domain\", \"main.main\", \"hello\")\n\t// v1.0.0 =\u003e gettext.DPGettext(\"domain\", \"\", \"hello\")\n\n\tgettext.NGettext(\"domain\", \"hello\", \"hello2\", n)\n\t// v0.1.0 =\u003e gettext.PNGettext(\"domain\", \"main.main\", \"hello\", \"hello2\", n)\n\t// v1.0.0 =\u003e gettext.PNGettext(\"domain\", \"\", \"hello\", \"hello2\", n)\n\n\tgettext.DNGettext(\"domain\", \"hello\", \"hello2\", n)\n\t// v0.1.0 =\u003e gettext.DPNGettext(\"domain\", \"main.main\", \"hello\", \"hello2\", n)\n\t// v1.0.0 =\u003e gettext.DPNGettext(\"domain\", \"\", \"hello\", \"hello2\", n)\n}\n```\n\n### `BindLocale` support `FileSystem` interface\n\n```go\n// Use FileSystem:\n//\tBindLocale(New(\"poedit\", \"name\", OS(\"path/to/dir\"))) // bind \"poedit\" domain\n//\tBindLocale(New(\"poedit\", \"name\", OS(\"path/to.zip\"))) // bind \"poedit\" domain\n```\n\n## New API in v1.0.0\n\n`Gettexter` interface:\n\n```go\ntype Gettexter interface {\n\tFileSystem() FileSystem\n\n\tGetDomain() string\n\tSetDomain(domain string) Gettexter\n\n\tGetLanguage() string\n\tSetLanguage(lang string) Gettexter\n\n\tGettext(msgid string) string\n\tPGettext(msgctxt, msgid string) string\n\n\tNGettext(msgid, msgidPlural string, n int) string\n\tPNGettext(msgctxt, msgid, msgidPlural string, n int) string\n\n\tDGettext(domain, msgid string) string\n\tDPGettext(domain, msgctxt, msgid string) string\n\tDNGettext(domain, msgid, msgidPlural string, n int) string\n\tDPNGettext(domain, msgctxt, msgid, msgidPlural string, n int) string\n\n\tGetdata(name string) []byte\n\tDGetdata(domain, name string) []byte\n}\n\nfunc New(domain, path string, data ...interface{}) Gettexter\n```\n\n`FileSystem` interface:\n\n```go\ntype FileSystem interface {\n\tLocaleList() []string\n\tLoadMessagesFile(domain, lang, ext string) ([]byte, error)\n\tLoadResourceFile(domain, lang, name string) ([]byte, error)\n\tString() string\n}\n\nfunc NewFS(name string, x interface{}) FileSystem\nfunc OS(root string) FileSystem\nfunc ZipFS(r *zip.Reader, name string) FileSystem\nfunc NilFS(name string) FileSystem\n```\n\n----\n\n## BUGS\n\nPlease report bugs to \u003cchaishushan@gmail.com\u003e.\n\nThanks!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchai2010%2Fgettext-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchai2010%2Fgettext-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchai2010%2Fgettext-go/lists"}