{"id":25605907,"url":"https://github.com/openscript/astro-loader-i18n","last_synced_at":"2025-06-21T10:06:56.329Z","repository":{"id":277809355,"uuid":"933556901","full_name":"openscript/astro-loader-i18n","owner":"openscript","description":"An Astro glob content loader for i18n files and folder structures. 🌐","archived":false,"fork":false,"pushed_at":"2025-06-20T14:42:22.000Z","size":1186,"stargazers_count":8,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-21T10:06:38.119Z","etag":null,"topics":["astro","content-loader","i18n"],"latest_commit_sha":null,"homepage":"","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/openscript.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}},"created_at":"2025-02-16T08:52:36.000Z","updated_at":"2025-06-20T14:42:08.000Z","dependencies_parsed_at":"2025-02-16T09:26:59.734Z","dependency_job_id":"d6959faf-dc29-4063-94e0-5c1a2e1a8d75","html_url":"https://github.com/openscript/astro-loader-i18n","commit_stats":null,"previous_names":["openscript/astro-loader-i18n"],"tags_count":28,"template":false,"template_full_name":null,"purl":"pkg:github/openscript/astro-loader-i18n","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openscript%2Fastro-loader-i18n","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openscript%2Fastro-loader-i18n/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openscript%2Fastro-loader-i18n/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openscript%2Fastro-loader-i18n/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openscript","download_url":"https://codeload.github.com/openscript/astro-loader-i18n/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openscript%2Fastro-loader-i18n/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261103453,"owners_count":23109932,"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":["astro","content-loader","i18n"],"created_at":"2025-02-21T18:20:13.311Z","updated_at":"2025-06-21T10:06:51.290Z","avatar_url":"https://github.com/openscript.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# astro-loader-i18n\n\nThis package is a simple content loader for i18n files and folder structures, partially built on top of the [`glob()` loader](https://docs.astro.build/en/reference/content-loader-reference/#glob-loader).\n\n```bash\nnpm install astro-loader-i18n\n```\n\n```bash\nyarn add astro-loader-i18n\n```\n\n```bash\npnpm add astro-loader-i18n\n```\n\n## Overview\n\nFor example, given the following i18n structure:\n\n```\n. (project root)\n├── README.md\n└── src\n    └── content\n        └── pages\n            ├── de-CH\n            │   ├── about.mdx\n            │   └── projects.mdx\n            └── zh-CN\n                ├── about.mdx\n                └── projects.mdx\n```\n\nDefine a collection in your `content.config.ts` using the `astro-loader-i18n` file:\n\n```typescript\nimport { i18nFolderLoader, z } from 'astro-loader-i18n';\nimport { defineCollection } from 'astro:content';\n\nconst pages = defineCollection({\n  loader: i18nFolderLoader({\n    pattern: \"**/*.mdx\",\n    base: \"src/content/pages\",\n    schema: z.object({\n      title: z.string(),\n    }),\n  }),\n  schema: /* USUALLY YOU DON'T WANT TO OVERRIDE THE LOADERS SCHEMA */\n});\n\nexport const collections = { pages };\n```\n\n\u003e [!CAUTION]\n\u003e The `schema` should be defined in the loader, not in the collection definition. This is because the loader is responsible for parsing the content and the collection is responsible for filtering and sorting the content.\n\nRetrieve the collection and filter by locale:\n\n```ts\nimport { getCollection } from \"astro:content\";\n\nconst pages = await getCollection(\"pages\", (entry) =\u003e { entry.locale === \"de-CH\"});\n```\n\n## Usage\n\nThis loader supports differently structured localized content:\n\n### Folder via `i18nFolderLoader`\n\nThe content is structured into locales by folders:\n\n```\n. (project root)\n├── README.md\n└── src\n    └── content\n        └── pages\n            ├── de-CH\n            │   ├── about.mdx\n            │   └── projects.mdx\n            └── zh-CN\n                ├── about.mdx\n                └── projects.mdx\n```\n\n- The locale is determined by the folder name.\n- Localized subfolders can be used to structure the content further.\n- Page translations need to be separately mapped.\n- Useful for:\n  - Individual pages with multiple translations\n  - Flat content structures\n\n### Files via `i18nFilesLoader`\n\n```\n. (project root)\n└── src\n    └── content\n        └── pages\n            ├── about.de-CH.mdx\n            ├── about.zh-CN.mdx\n            ├── projects.de-CH.mdx\n            └── projects.zh-CN.mdx\n```\n\n- The locale is determined by the file name suffix.\n- Subfolders can be used to structure the content further.\n- Subfolder names need to be separately translated.\n- Useful for:\n  - Blogs\n  - News\n  - Articles\n  - Notes\n  - ...\n\n### Infile via standard `glob()` loader\n\n```\n. (project root)\n└── src\n    └── content\n        └── navigation\n            ├── footer.yml\n            └── main.yml\n```\n\n```yaml\n# src/content/navigation/main.yml\nde-CH:\n  - path: /projekte\n    title: Projekte\n  - path: /ueber-mich\n    title: Über mich\nzh-CN:\n  - path: /zh/projects\n    title: 项目\n  - path: /zh/about-me\n    title: 关于我\n```\n\n- The locale is determined by the key in the YAML file.\n- The content is structured in a single file.\n- This allows sharing untranslated content across locales.\n- Useful for:\n  - Menus\n  - Galleries\n  - ...\n\n## Improvements\n\n- [ ] Export `GlobOptions` type from Astro\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenscript%2Fastro-loader-i18n","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenscript%2Fastro-loader-i18n","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenscript%2Fastro-loader-i18n/lists"}