{"id":16410608,"url":"https://github.com/acro5piano/astro-gettext","last_synced_at":"2026-05-15T17:39:58.047Z","repository":{"id":193633369,"uuid":"689208438","full_name":"acro5piano/astro-gettext","owner":"acro5piano","description":"Fast gettext i18n in Node that supports Astro","archived":false,"fork":false,"pushed_at":"2024-01-11T16:15:50.000Z","size":170,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-04-30T18:32:08.541Z","etag":null,"topics":["astro","astrojs","cli","gettext","i18n","internationalization","static-site","tanslation","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/astro-gettext","language":"TypeScript","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/acro5piano.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-09-09T05:09:37.000Z","updated_at":"2026-02-28T20:25:21.000Z","dependencies_parsed_at":"2023-09-09T08:25:23.071Z","dependency_job_id":null,"html_url":"https://github.com/acro5piano/astro-gettext","commit_stats":null,"previous_names":["acro5piano/fast-ttag","acro5piano/astro-gettext"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/acro5piano/astro-gettext","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acro5piano%2Fastro-gettext","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acro5piano%2Fastro-gettext/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acro5piano%2Fastro-gettext/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acro5piano%2Fastro-gettext/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/acro5piano","download_url":"https://codeload.github.com/acro5piano/astro-gettext/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acro5piano%2Fastro-gettext/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33073429,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-15T11:35:32.926Z","status":"ssl_error","status_checked_at":"2026-05-15T11:35:31.362Z","response_time":103,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["astro","astrojs","cli","gettext","i18n","internationalization","static-site","tanslation","typescript"],"created_at":"2024-10-11T06:43:24.091Z","updated_at":"2026-05-15T17:39:58.026Z","avatar_url":"https://github.com/acro5piano.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"An Astro i18n library in GNU gettext style. Inspired by [ttag](https://ttag.js.org/)\n\n# Project Status\n\nastro-gettext is still experimental, but covers most of use-cases for simple static websites build with Astro.\n\n# Why\n\n- Astro is awesome. It brings simpler syntax for the static website era.\n- I'm a big fan of i18n using GNU gettext pattern.\n- There's no such library to combine them. [Lingui still don't support Astro](https://github.com/lingui/js-lingui/issues/1640) (on Sep, 2023)\n\n# Getting Started\n\n## Install\n\n```\nnpm install --save astro-gettext\n```\n\nOr if you use Yarn:\n\n```\nyarn add astro-gettext\n```\n\n## Implementation\n\n**1. Setup translation**\n\nBy creating a translation instance, you can declare your supported languages:\n\n```ts\n// src/locale.ts\nimport { Trans } from 'astro-gettext'\n\nexport const trans = new Trans\u003c'en' | 'ja'\u003e()\n```\n\n**2. Wrap strings with `t` tag**\n\n```astro\n---\n// src/pages/index.astro\nimport { trans } from '../locale'\n\n// You need to implement a logic to retrieve the current language.\n// `Astro.url` is a recommended way, but it depends on your environment.\nconst t = trans.get(Astro.url.includes('ja') ? 'ja' : 'en')\n---\n\u003cdiv\u003e\n  \u003ch1\u003e{t`Hello World!`}\u003c/h1\u003e\n\u003c/div\u003e\n```\n\n**3. Setup localization**\n\n```sh\nnpm run astro-gettext extract --po ja.po\n```\n\nThis will create a new `ja.po` file with all appropriate translation templates for the Japanese language:\n\n```po\n# ja.po\n#: src/pages/index.astro:8\nmsgid \"Hello World!\"\nmsgstr \"\"\n```\n\nLet's add your translation by filling `msgstr`:\n\n```po\n# ja.po\n#: src/pages/index.astro:8\nmsgid \"Hello World!\"\nmsgstr \"こんにちは！\"\n```\n\n**4. Load translations**\n\nConvert the `.po` into JSON file so that Astro can load them in runtime:\n\n```sh\nnpm run astro-gettext po2json --po locales/ja.po --output src/ja.json --pretty\n```\n\nIt will produce a json file like this:\n\n```json\n{\n  \"charset\": \"utf-8\",\n  \"translations\": {\n    \"\": {\n      \"Hello World!\": {\n        \"msgid\": \"Hello World!\",\n        \"msgstr\": [\"こんにちは！\"]\n      }\n    }\n  }\n}\n```\n\nFinally, update the translation instance:\n\n```ts\n// src/locale.ts\nimport { Trans } from 'astro-gettext'\nimport ja from './ja.json' // \u003c--- This\n\nexport const trans = new Trans\u003c'en' | 'ja'\u003e()\ntrans.addLocale('ja', ja) // \u003c--- This\n```\n\nWell Done! Then you will see your Astro app is translated, in a manner of gettext.\n\n# TODO\n\n- [ ] Support i18n in the gray-matter TS code area using [ts-morph](https://github.com/dsherret/ts-morph)\n- [ ] Variable support\n- [ ] Context support\n- [ ] `ngettext` support\n- [ ] Covers `.ts` files using TypeScript compiler API - meaning this library truly become `ttag` replacement.\n- [ ] Astro frontend integrations?\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facro5piano%2Fastro-gettext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Facro5piano%2Fastro-gettext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facro5piano%2Fastro-gettext/lists"}