{"id":19493356,"url":"https://github.com/i18next/i18next-fs-backend","last_synced_at":"2025-04-04T16:14:17.432Z","repository":{"id":46126981,"uuid":"256835197","full_name":"i18next/i18next-fs-backend","owner":"i18next","description":"i18next-fs-backend is a backend layer for i18next using in Node.js and for Deno to load translations from the filesystem.","archived":false,"fork":false,"pushed_at":"2024-03-27T05:58:48.000Z","size":141,"stargazers_count":87,"open_issues_count":1,"forks_count":17,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-05-22T03:44:44.361Z","etag":null,"topics":["backend","deno","fs","i18next","javascript","nodejs","plugin"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/i18next.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-04-18T19:23:58.000Z","updated_at":"2024-06-18T12:41:52.343Z","dependencies_parsed_at":"2024-06-18T12:41:48.655Z","dependency_job_id":"e4b988fb-c11f-473a-a0ee-4fada0985032","html_url":"https://github.com/i18next/i18next-fs-backend","commit_stats":{"total_commits":116,"total_committers":7,"mean_commits":"16.571428571428573","dds":0.07758620689655171,"last_synced_commit":"d7dc3529081cc529d19027be049ee2db9fc3d233"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i18next%2Fi18next-fs-backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i18next%2Fi18next-fs-backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i18next%2Fi18next-fs-backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/i18next%2Fi18next-fs-backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/i18next","download_url":"https://codeload.github.com/i18next/i18next-fs-backend/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247208145,"owners_count":20901570,"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":["backend","deno","fs","i18next","javascript","nodejs","plugin"],"created_at":"2024-11-10T21:25:28.729Z","updated_at":"2025-04-04T16:14:17.408Z","avatar_url":"https://github.com/i18next.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Introduction\n\n[![Actions](https://github.com/i18next/i18next-fs-backend/workflows/node/badge.svg)](https://github.com/i18next/i18next-fs-backend/actions?query=workflow%3Anode)\n[![Actions deno](https://github.com/i18next/i18next-fs-backend/workflows/deno/badge.svg)](https://github.com/i18next/i18next-fs-backend/actions?query=workflow%3Adeno)\n[![npm version](https://img.shields.io/npm/v/i18next-fs-backend.svg?style=flat-square)](https://www.npmjs.com/package/i18next-fs-backend)\n\nThis is an i18next backend to be used in Node.js and Deno. It will load resources from the file system.\n\nIt's based on the deprecated [i18next-node-fs-backend](https://github.com/i18next/i18next-node-fs-backend) and can mostly be used as a drop-in replacement.\n\nIt will load resources from filesystem. Right now it supports following filetypes:\n\n- .json\n- .json5\n- .jsonc\n- .yml/.yaml\n- .js (very limited, checks for `exports` or `export default`)\n\n# Getting started\n\n```bash\n# npm package\n$ npm install i18next-fs-backend\n```\n\nWiring up:\n\n```js\nimport i18next from 'i18next';\nimport Backend from 'i18next-fs-backend';\n\ni18next.use(Backend).init(i18nextOptions);\n```\n\nfor Deno:\n\n```js\nimport i18next from 'https://deno.land/x/i18next/index.js'\nimport Backend from 'https://deno.land/x/i18next_fs_backend/index.js'\n\ni18next.use(Backend).init(i18nextOptions);\n```\n\n- As with all modules you can either pass the constructor function (class) to the i18next.use or a concrete instance.\n\n## Backend Options\n\n```js\n{\n  // path where resources get loaded from, or a function\n  // returning a path:\n  // function(lngs, namespaces) { return customPath; }\n  // the returned path will interpolate lng, ns if provided like giving a static path\n  loadPath: '/locales/{{lng}}/{{ns}}.json',\n\n  // path to post missing resources\n  addPath: '/locales/{{lng}}/{{ns}}.missing.json',\n\n  // if you use i18next-fs-backend as caching layer in combination with i18next-chained-backend, you can optionally set an expiration time\n  // an example on how to use it as cache layer can be found here: https://github.com/i18next/i18next-fs-backend/blob/master/example/caching/app.js\n  // expirationTime: 60 * 60 * 1000\n}\n```\n\nOptions can be passed in:\n\n**preferred** - by setting options.backend in i18next.init:\n\n```js\nimport i18next from 'i18next';\nimport Backend from 'i18next-fs-backend';\n\ni18next.use(Backend).init({\n  backend: options,\n});\n```\n\non construction:\n\n```js\nimport Backend from 'i18next-fs-backend';\nconst Backend = new Backend(null, options);\n```\n\nvia calling init:\n\n```js\nimport Backend from 'i18next-fs-backend';\nconst Backend = new Backend();\nBackend.init(null, options);\n```\n\n## TypeScript\n\nTo properly type the backend options, you can import the `FsBackendOptions` interface and use it as a generic type parameter to the i18next's `init` method, e.g.:\n\n```ts\nimport i18n from 'i18next'\nimport FsBackend, { FsBackendOptions } from 'i18next-fs-backend'\n\ni18n\n  .use(FsBackend)\n  .init\u003cFsBackendOptions\u003e({\n    backend: {\n      // fs backend options\n    },\n\n    // other i18next options\n  })\n```\n\n# If set i18next initAsync option to false it will load the files synchronously\n\n```js\n// i18n.js\nconst { join } = require('path')\nconst { readdirSync, lstatSync } = require('fs')\nconst i18next = require('i18next')\nconst Backend = require('i18next-fs-backend')\ni18next\n  .use(Backend)\n  .init({\n    // debug: true,\n    initAsync: false,\n    fallbackLng: 'en',\n    lng: 'en',\n    preload: readdirSync(join(__dirname, '../locales')).filter((fileName) =\u003e {\n      const joinedPath = join(join(__dirname, '../locales'), fileName)\n      const isDirectory = lstatSync(joinedPath).isDirectory()\n      return isDirectory\n    }),\n    ns: 'backend-app',\n    defaultNS: 'backend-app',\n    backend: {\n      loadPath: join(__dirname, '../locales/{{lng}}/{{ns}}.json')\n    }\n  })\n```\n\n---\n\n\u003ch3 align=\"center\"\u003eGold Sponsors\u003c/h3\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://locize.com/\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/i18next/i18next/master/assets/locize_sponsor_240.gif\" width=\"240px\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fi18next%2Fi18next-fs-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fi18next%2Fi18next-fs-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fi18next%2Fi18next-fs-backend/lists"}