{"id":13451446,"url":"https://github.com/m1/go-localize","last_synced_at":"2025-07-30T01:39:16.807Z","repository":{"id":36698829,"uuid":"229744288","full_name":"m1/go-localize","owner":"m1","description":"i18n (Internationalization and localization) engine written in Go, used for translating locale strings. ","archived":false,"fork":false,"pushed_at":"2023-11-11T10:07:14.000Z","size":34,"stargazers_count":62,"open_issues_count":3,"forks_count":14,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-01T08:44:32.989Z","etag":null,"topics":["go","go-generate","go-i18n","go-library","golang","hacktoberfest","i18n","internationalization","localization","translation"],"latest_commit_sha":null,"homepage":"","language":"Go","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/m1.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2019-12-23T12:02:51.000Z","updated_at":"2025-03-30T00:46:19.000Z","dependencies_parsed_at":"2024-01-08T15:34:46.816Z","dependency_job_id":null,"html_url":"https://github.com/m1/go-localize","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/m1/go-localize","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m1%2Fgo-localize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m1%2Fgo-localize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m1%2Fgo-localize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m1%2Fgo-localize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/m1","download_url":"https://codeload.github.com/m1/go-localize/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m1%2Fgo-localize/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267793577,"owners_count":24145063,"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-07-29T02:00:12.549Z","response_time":2574,"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":["go","go-generate","go-i18n","go-library","golang","hacktoberfest","i18n","internationalization","localization","translation"],"created_at":"2024-07-31T07:00:53.963Z","updated_at":"2025-07-30T01:39:16.780Z","avatar_url":"https://github.com/m1.png","language":"Go","funding_links":[],"categories":["Relational Databases","Natural Language Processing","自然语言处理","Bot Building"],"sub_categories":["Translation","翻译","暂未分类","暂未分类这些库被放在这里是因为其他类别似乎都不适合。","Uncategorized","Strings"],"readme":"# go-localize\n\n[![GoDoc](https://godoc.org/github.com/m1/go-localize?status.svg)](https://godoc.org/github.com/m1/go-localize)\n[![Build Status](https://travis-ci.org/m1/go-localize.svg?branch=master)](https://travis-ci.org/m1/go-localize)\n[![Go Report Card](https://goreportcard.com/badge/github.com/m1/go-localize)](https://goreportcard.com/report/github.com/m1/go-localize)\n[![Release](https://img.shields.io/github/release/m1/go-localize.svg)](https://github.com/m1/go-localize/releases/latest)\n[![codecov](https://codecov.io/gh/m1/go-localize/branch/master/graph/badge.svg)](https://codecov.io/gh/m1/go-localize)\n\n__Simple and easy to use i18n (Internationalization and localization) engine written in Go, used for translating locale strings. \nUse with [go generate](#go-generate) or on the [CLI](#cli). Currently supports JSON, YAML, TOML and CSV translation files__\n\n## Why another i18n library?\n\nThis package aims to be as simple and easy to use as possible. It also\ntakes inspiration from popular localization libraries/packages in other languages - \nso makes it easier to reason about coming from other languages and frameworks.\n\n## Usage\n\n### Go generate\n\nThe suggested way to use go-localize is to use `go generate`. For example, take the following directory structure:\n\n```\ngoapp\n└── localizations_src\n    ├── en\n    │   └── messages.yaml\n    └── es\n        ├── customer\n        │   └── messages.json\n        └── messages.json\n```\n\nExample of JSON translation file:\n\n```json\n{\n  \"hello\": \"Hola\",\n  \"how_are_you\": \"¿Cómo estás?\",\n  \"whats_your_name\": \"¿Cuál es tu nombre?\",\n  \"hello_my_name_is\": \"Hola, mi nombre es {{.name}}\"\n}\n```\n\nExample of YAML translation file:\n```yaml\nhello: hello\nhow_are_you: How are you?\nwhats_your_name: \"What's your name?\"\nhello_my_name_is: Hello my name is {{.name}}\nhello_firstname_lastname: Hello {{.firstname}} {{.lastname}}\n```\n\nExample of CSV translation file:\n```csv\nhello, hello\nhow_are_you, How are you?\n```\n\nExample of TOML translation file:\n```toml\nhello = \"hello\"\nhow_are_you = \"How are you?\"\n```\n\nTo then generate the localization package, add the following to your `main.go` or another one of your `.go` files:\n\n```go\n//go:generate go-localize -input localizations_src -output localizations\n```\n\nNow you'll be able to use the localization like so:\n```go\nl := localizations.New(\"en\", \"es\")\n\nprintln(l.Get(\"messages.how_are_you\")) // How are you?\n\nprintln(l.GetWithLocale(\"es\", \"messages.hello_my_name_is\", \u0026localizations.Replacements{\"name\":\"steve\"})) // \"Hola, mi nombre es steve\"\n```\n\nWith `en` being the locale and `es` being the fallback. The localization keys are worked out using folder structure, eg:\n\n`en/customer/messages.json` with the contents being:\n```json\n{\n  \"hello\": \"hello customer!\"\n}\n```\nYou'll be able to access this using the key: `customer.messages.hello`.\n\n#### Suggestions\n\nIt is suggested to instead of using hardcoded locale keys i.e. `en` to use the language keys included in key, i.e: `language.BritishEnglish.String()` \nwhich is `en-GB`\n\n\n#### Replacements\n\nTake this replacement string for example:\n```yaml\nhello_firstname_lastname: Hello {{.firstname}} {{.lastname}}\n```\n\nTo then replace `firstname` and the `lastname` variable, you can use \nsomething like this:\n\n\n```go\nl := localizations.New(\"en\", \"es\")\nprintln(l.Get(\"hello_firstname_lastname\", \u0026localizations.Replacements{\"firstname\": \"steve\", \"lastname\": \"steve\"}))\n```\n\nYou can also append numerous replacements if you have them like so:\n\n```go\nprintln(l.Get(\"hello_firstname_lastname\", \u0026localizations.Replacements{\"firstname\": \"steve\"}, \u0026localizations.Replacements{\"lastname\": \"steve\"}))\n```\n\n#### Locale defining and localization fallbacks\n\nYou can define the locale and fallbacks using:\n```go\nl := localizations.New(\"en\", \"es\")\n```\n\nWhere `en` is the locale and `es` is the fallback. If no translation key-value is\nfound then the key will be returned. For example\n\n```go\nprintln(l.Get(\"key_doesnt_exist\")) //\"key_doesnt_exist\" will be printed\n```\n\n#### Translation file support\n\nWe currently support JSON and YAML translation files. Please suggest\nmissing file type using issues or pull requests.\n\n### CLI\n\nInstead of using go generate you can just generate the localizations manually using `go-localize`:\n```\nUsage of go-localize:\n  -input string\n        input localizations folder\n  -output string\n        where to output the generated package\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm1%2Fgo-localize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fm1%2Fgo-localize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm1%2Fgo-localize/lists"}