{"id":19509559,"url":"https://github.com/raspi/tulkki","last_synced_at":"2025-10-29T08:06:45.738Z","repository":{"id":57538253,"uuid":"286966913","full_name":"raspi/tulkki","owner":"raspi","description":"Translated HTML templates for Go","archived":false,"fork":false,"pushed_at":"2023-03-06T09:27:25.000Z","size":294,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-25T22:46:28.264Z","etag":null,"topics":["go","golang","html","i18n","internationalization","localization","template"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/raspi.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":"2020-08-12T09:03:07.000Z","updated_at":"2023-03-06T09:27:25.000Z","dependencies_parsed_at":"2024-06-20T11:23:38.640Z","dependency_job_id":null,"html_url":"https://github.com/raspi/tulkki","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/raspi/tulkki","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raspi%2Ftulkki","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raspi%2Ftulkki/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raspi%2Ftulkki/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raspi%2Ftulkki/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/raspi","download_url":"https://codeload.github.com/raspi/tulkki/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raspi%2Ftulkki/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281584979,"owners_count":26526171,"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-10-29T02:00:06.901Z","response_time":59,"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","golang","html","i18n","internationalization","localization","template"],"created_at":"2024-11-10T23:12:28.546Z","updated_at":"2025-10-29T08:06:45.706Z","avatar_url":"https://github.com/raspi.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tulkki\n\n![GitHub All Releases](https://img.shields.io/github/downloads/raspi/tulkki/total?style=for-the-badge)\n![GitHub release (latest by date)](https://img.shields.io/github/v/release/raspi/tulkki?style=for-the-badge)\n![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/raspi/tulkki?style=for-the-badge)\n\n\nTranslated HTML templates for Go\n\nSee [example directory](_example) for example(s).\n\n```go\npackage main\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\t\"github.com/raspi/tulkki\"\n\t\"golang.org/x/text/language\"\n\t\"golang.org/x/text/message/catalog\"\n\t\"html/template\"\n\t\"time\"\n)\n\n// Base template for all pages\nvar baseHTML = `\n\u003chtml\u003e\n\u003chead\u003e\n\u003ctitle\u003e{{.Title}}\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\u003cmain\u003e\n{{- template \"content\" .C -}}\n\u003c/main\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n`\n\n// Example page\nvar testPageHTML = `\n\u003cp\u003e\n  \u003c!-- Translated within template itself: --\u003e\n  {{T \"test\"}}\n  {{T \"test_formatted\" \"Template\" \"right now\"}}\n  \u003c!-- Pre-translated to a template variable: --\u003e\n  {{.TranslatedToken}}\n\u003c/p\u003e\n`\n\n// example base struct which all pages will use\ntype exampleBase struct {\n\tTitle string\n\t// C (short for content) is used in the base HTML template as a per-page variables\n\t// It needs to be abstract interface because different pages have different variables\n\tC interface{}\n}\n\n// example page\ntype examplePage struct {\n\tTranslatedToken string\n}\n\nfunc main() {\n\tuseLanguage := language.English\n\tfallbackLanguage := language.English\n\n\tpagetranslations := catalog.NewBuilder(\n\t\tcatalog.Fallback(fallbackLanguage),\n\t)\n\n\t// Translations are per-page for collision reasons\n\tpagetranslations.SetString(language.English, `test`, `this is a test string`)\n\tpagetranslations.SetString(language.English, `test_formatted`, `%s is testing things on %s`)\n\n\t// Global template functions accessible to all pages\n\t// Add CSRF etc generators here\n\tfuncs := template.FuncMap{}\n\n\ttpl := tulkki.New(baseHTML, funcs)\n\ttpl.AddPage(`testpage`, testPageHTML, pagetranslations)\n\n\t// Generate a page template\n\tpage := exampleBase{\n\t\tTitle: \"Hello, world!\",\n\t\tC: examplePage{\n\t\t\tTranslatedToken: tpl.Translate(`testpage`, `test_formatted`, useLanguage, `Example`, time.Now().Truncate(time.Second)),\n\t\t},\n\t}\n\n\t// Render the HTML\n\tvar tmp bytes.Buffer\n\terr := tpl.Render(\u0026tmp, `testpage`, useLanguage, page)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Print(tmp.String())\n\n\tfmt.Println(`example: ` + tpl.Translate(`testpage`, `test_formatted`, useLanguage, `Direct translation`, template.HTML(`\u003ca href=\"#\"\u003ehere\u003c/a\u003e`)))\n}\n```\n\nOutputs:\n\n```html\n\u003chtml\u003e\n\u003chead\u003e\n\u003ctitle\u003eHello, world!\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\u003cmain\u003e\n\u003cp\u003e\n  \n  this is a test string\n  Template is testing things on right now\n  \n  Example is testing things on 2020-08-12 12:25:41 \u0026#43;0300 EEST\n\u003c/p\u003e\n\u003c/main\u003e\n\u003c/body\u003e\n\u003c/html\u003e\nexample: Direct translation is testing things on \u003ca href=\"#\"\u003ehere\u003c/a\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraspi%2Ftulkki","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraspi%2Ftulkki","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraspi%2Ftulkki/lists"}