diff --git a/.github/ISSUE_TEMPLATE/1-bug-report.md b/.github/ISSUE_TEMPLATE/1-bug-report.md
index 0680726..4ebf531 100644
--- a/.github/ISSUE_TEMPLATE/1-bug-report.md
+++ b/.github/ISSUE_TEMPLATE/1-bug-report.md
@@ -25,4 +25,4 @@ about: Something is not working as it should
- [ ] I'm willing to submit a pull request
- [ ] I have read the documentation.
-- [ ] I have tried my code with the latest version of npm and [fasti18n](https://github.com/fzn0x/fasti18n).
+- [ ] I have tried my code with the latest version of npm and [yoi18n](https://github.com/fzn0x/yoi18n).
diff --git a/.github/ISSUE_TEMPLATE/2-feature-request.md b/.github/ISSUE_TEMPLATE/2-feature-request.md
index 058cd19..21b77c7 100644
--- a/.github/ISSUE_TEMPLATE/2-feature-request.md
+++ b/.github/ISSUE_TEMPLATE/2-feature-request.md
@@ -1,6 +1,6 @@
---
name: '⭐ Feature request'
-about: Suggest a feature for fasti18n
+about: Suggest a feature for yoi18n
---
#### What feature are you want to add?
diff --git a/README.md b/README.md
index 1901b6f..fd46d9b 100644
--- a/README.md
+++ b/README.md
@@ -2,15 +2,15 @@
-[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/fzn0x/fasti18n/ci.yml?branch=main)](https://github.com/fzn0x/fasti18n/actions)
-[![GitHub](https://img.shields.io/github/license/fzn0x/fasti18n)](https://github.com/fzn0x/fasti18n/blob/main/LICENSE)
-[![npm](https://img.shields.io/npm/v/fasti18n)](https://www.npmjs.com/package/fasti18n)
-[![npm](https://img.shields.io/npm/dm/fasti18n)](https://www.npmjs.com/package/fasti18n)
-[![JSR](https://jsr.io/badges/@fzn0x/fasti18n)](https://jsr.io/@fzn0x/fasti18n)
-[![Bundle Size](https://img.shields.io/bundlephobia/min/fasti18n)](https://bundlephobia.com/result?p=fasti18n)
-[![Bundle Size](https://img.shields.io/bundlephobia/minzip/fasti18n)](https://bundlephobia.com/result?p=fasti18n)
-[![GitHub commit activity](https://img.shields.io/github/commit-activity/m/fzn0x/fasti18n)](https://github.com/fzn0x/fasti18n/pulse)
-[![GitHub last commit](https://img.shields.io/github/last-commit/fzn0x/fasti18n)](https://github.com/fzn0x/fasti18n/commits/main)
+[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/fzn0x/yoi18n/ci.yml?branch=main)](https://github.com/fzn0x/yoi18n/actions)
+[![GitHub](https://img.shields.io/github/license/fzn0x/yoi18n)](https://github.com/fzn0x/yoi18n/blob/main/LICENSE)
+[![npm](https://img.shields.io/npm/v/yoi18n)](https://www.npmjs.com/package/yoi18n)
+[![npm](https://img.shields.io/npm/dm/yoi18n)](https://www.npmjs.com/package/yoi18n)
+[![JSR](https://jsr.io/badges/@fzn0x/yoi18n)](https://jsr.io/@fzn0x/yoi18n)
+[![Bundle Size](https://img.shields.io/bundlephobia/min/yoi18n)](https://bundlephobia.com/result?p=yoi18n)
+[![Bundle Size](https://img.shields.io/bundlephobia/minzip/yoi18n)](https://bundlephobia.com/result?p=yoi18n)
+[![GitHub commit activity](https://img.shields.io/github/commit-activity/m/fzn0x/yoi18n)](https://github.com/fzn0x/yoi18n/pulse)
+[![GitHub last commit](https://img.shields.io/github/last-commit/fzn0x/yoi18n)](https://github.com/fzn0x/yoi18n/commits/main)
@@ -28,10 +28,10 @@
## Installation
```bash
-bun install fasti18n
-npm install fasti18n
-yarn add fasti18n
-pnpm install fasti18n
+bun install yoi18n
+npm install yoi18n
+yarn add yoi18n
+pnpm install yoi18n
```
## Usage
@@ -74,7 +74,7 @@ Creates `lang.json` and `lang-admin.json` files:
```js
// lang.js
-const i18n = require('fasti18n')
+const i18n = require('yoi18n')
const t = i18n.init({
namespace: {
@@ -120,7 +120,7 @@ console.log(t('admin.hello')) // "hello" from admin namespace,
```js
// lang.ts
-import i18n from 'fasti18n'
+import i18n from 'yoi18n'
const t = i18n.init({
namespace: {
@@ -157,7 +157,7 @@ console.log(t('admin.hello')) // "hello" from admin namespace,
### React
```jsx
-import i18n from 'fasti18n'
+import i18n from 'yoi18n'
const t = i18n.init({
namespace: {
@@ -196,4 +196,4 @@ export default function LanguageSwitch({ lang, ns }) {
## License
-fasti18n is [MIT Licensed](./LICENSE) and Open Source Software by [@fzn0x](https://github.com/fzn0x)
+yoi18n is [MIT Licensed](./LICENSE) and Open Source Software by [@fzn0x](https://github.com/fzn0x)
diff --git a/browser/fasti18n-browser.min.js b/browser/fasti18n-browser.min.js
index 9fef8e4..24d3ea6 100644
--- a/browser/fasti18n-browser.min.js
+++ b/browser/fasti18n-browser.min.js
@@ -1,2 +1,138 @@
-!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n(require("{}")):"function"==typeof define&&define.amd?define("fasti18n",["{}"],n):"object"==typeof exports?exports.fasti18n=n(require("{}")):e.fasti18n=n(e["{}"])}(self,(e=>(()=>{"use strict";var n={324:n=>{n.exports=e}},t={};function o(e){var r=t[e];if(void 0!==r)return r.exports;var i=t[e]={exports:{}};return n[e](i,i.exports,o),i.exports}o.n=e=>{var n=e&&e.__esModule?()=>e.default:()=>e;return o.d(n,{a:n}),n},o.d=(e,n)=>{for(var t in n)o.o(n,t)&&!o.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:n[t]})},o.o=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};o.r(r),o.d(r,{default:()=>c});var i=o(324);function a(e){const n=function(e){const n={};return e?(e.split(";").forEach((e=>{const[t,...o]=e.split("=");t&&(n[t.trim()]=decodeURIComponent(o.join("=")))})),n):n}(e);return n.lang||null}function u(e){const n=function(e){const n={};return e?(e.replace(/^\?/,"").split("&").forEach((e=>{const[t,o]=e.split("=");t&&o&&(n[t]=decodeURIComponent(o))})),n):n}(e);return n.lang||null}const c={init:function(e){const n={};for(const o in e.namespace){const r=e.namespace[o];if(!r)throw new Error("Invalid namespace configuration");n[o]=(t=r.load,JSON.parse(function(e){return(0,i.readFileSync)(e,"utf-8")}(t)))}var t;const o=function(e){const{order:n,defaultLang:t}=e;return e=>{for(const t of n){let n=null;if("cookie"===t?n=a(e.headers.cookie):"path"===t?n=e.url.split("/").find((e=>/^[a-z]{2}$/.test(e)))||null:"query"===t&&(n=u(e.url)),n)return n}return t}}(e.detection);function r(t,r){var i,a;const[u,c]=t.split("."),l=r&&Object.keys(r).length?o(r):u&&(null===(a=null===(i=null==e?void 0:e.namespace)||void 0===i?void 0:i[u])||void 0===a?void 0:a.defaultLang)||e.detection.defaultLang;return u&&c&&u in n&&l in n[u]?n[u][l][c]||t:n.default[l][t]||t}return r.switch=(n,t)=>{var o;if(!e)throw new Error("Config is undefined");if(e.detection.defaultLang=n,t){const r=null===(o=e.namespace)||void 0===o?void 0:o[t];if(!r)throw new Error(`Namespace ${t} not found`);r.defaultLang=n}},r}};return r})()));
-//# sourceMappingURL=fasti18n-browser.min.js.map
\ No newline at end of file
+!(function (e, n) {
+ 'object' == typeof exports && 'object' == typeof module
+ ? (module.exports = n(require('{}')))
+ : 'function' == typeof define && define.amd
+ ? define('yoi18n', ['{}'], n)
+ : 'object' == typeof exports
+ ? (exports.yoi18n = n(require('{}')))
+ : (e.yoi18n = n(e['{}']))
+})(self, (e) =>
+ (() => {
+ 'use strict'
+ var n = {
+ 324: (n) => {
+ n.exports = e
+ },
+ },
+ t = {}
+ function o(e) {
+ var r = t[e]
+ if (void 0 !== r) return r.exports
+ var i = (t[e] = { exports: {} })
+ return n[e](i, i.exports, o), i.exports
+ }
+ ;(o.n = (e) => {
+ var n = e && e.__esModule ? () => e.default : () => e
+ return o.d(n, { a: n }), n
+ }),
+ (o.d = (e, n) => {
+ for (var t in n)
+ o.o(n, t) && !o.o(e, t) && Object.defineProperty(e, t, { enumerable: !0, get: n[t] })
+ }),
+ (o.o = (e, n) => Object.prototype.hasOwnProperty.call(e, n)),
+ (o.r = (e) => {
+ 'undefined' != typeof Symbol &&
+ Symbol.toStringTag &&
+ Object.defineProperty(e, Symbol.toStringTag, { value: 'Module' }),
+ Object.defineProperty(e, '__esModule', { value: !0 })
+ })
+ var r = {}
+ o.r(r), o.d(r, { default: () => c })
+ var i = o(324)
+ function a(e) {
+ const n = (function (e) {
+ const n = {}
+ return e
+ ? (e.split(';').forEach((e) => {
+ const [t, ...o] = e.split('=')
+ t && (n[t.trim()] = decodeURIComponent(o.join('=')))
+ }),
+ n)
+ : n
+ })(e)
+ return n.lang || null
+ }
+ function u(e) {
+ const n = (function (e) {
+ const n = {}
+ return e
+ ? (e
+ .replace(/^\?/, '')
+ .split('&')
+ .forEach((e) => {
+ const [t, o] = e.split('=')
+ t && o && (n[t] = decodeURIComponent(o))
+ }),
+ n)
+ : n
+ })(e)
+ return n.lang || null
+ }
+ const c = {
+ init: function (e) {
+ const n = {}
+ for (const o in e.namespace) {
+ const r = e.namespace[o]
+ if (!r) throw new Error('Invalid namespace configuration')
+ n[o] =
+ ((t = r.load),
+ JSON.parse(
+ (function (e) {
+ return (0, i.readFileSync)(e, 'utf-8')
+ })(t)
+ ))
+ }
+ var t
+ const o = (function (e) {
+ const { order: n, defaultLang: t } = e
+ return (e) => {
+ for (const t of n) {
+ let n = null
+ if (
+ ('cookie' === t
+ ? (n = a(e.headers.cookie))
+ : 'path' === t
+ ? (n = e.url.split('/').find((e) => /^[a-z]{2}$/.test(e)) || null)
+ : 'query' === t && (n = u(e.url)),
+ n)
+ )
+ return n
+ }
+ return t
+ }
+ })(e.detection)
+ function r(t, r) {
+ var i, a
+ const [u, c] = t.split('.'),
+ l =
+ r && Object.keys(r).length
+ ? o(r)
+ : (u &&
+ (null ===
+ (a =
+ null === (i = null == e ? void 0 : e.namespace) || void 0 === i
+ ? void 0
+ : i[u]) || void 0 === a
+ ? void 0
+ : a.defaultLang)) ||
+ e.detection.defaultLang
+ return u && c && u in n && l in n[u] ? n[u][l][c] || t : n.default[l][t] || t
+ }
+ return (
+ (r.switch = (n, t) => {
+ var o
+ if (!e) throw new Error('Config is undefined')
+ if (((e.detection.defaultLang = n), t)) {
+ const r = null === (o = e.namespace) || void 0 === o ? void 0 : o[t]
+ if (!r) throw new Error(`Namespace ${t} not found`)
+ r.defaultLang = n
+ }
+ }),
+ r
+ )
+ },
+ }
+ return r
+ })()
+)
+//# sourceMappingURL=yoi18n-browser.min.js.map
diff --git a/browser/fasti18n-browser.min.js.map b/browser/fasti18n-browser.min.js.map
index 6d209ca..617be02 100644
--- a/browser/fasti18n-browser.min.js.map
+++ b/browser/fasti18n-browser.min.js.map
@@ -1 +1,117 @@
-{"version":3,"file":"fasti18n-browser.min.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,EAAQG,QAAQ,OACR,mBAAXC,QAAyBA,OAAOC,IAC9CD,OAAO,WAAY,CAAC,MAAOJ,GACD,iBAAZC,QACdA,QAAkB,SAAID,EAAQG,QAAQ,OAEtCJ,EAAe,SAAIC,EAAQD,EAAK,MACjC,CATD,CASGO,MAAOC,G,kCCTVL,EAAOD,QAAUM,C,GCCbC,EAA2B,CAAC,EAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAaV,QAGrB,IAAIC,EAASM,EAAyBE,GAAY,CAGjDT,QAAS,CAAC,GAOX,OAHAY,EAAoBH,GAAUR,EAAQA,EAAOD,QAASQ,GAG/CP,EAAOD,OACf,CCrBAQ,EAAoBK,EAAKZ,IACxB,IAAIa,EAASb,GAAUA,EAAOc,WAC7B,IAAOd,EAAiB,QACxB,IAAM,EAEP,OADAO,EAAoBQ,EAAEF,EAAQ,CAAEG,EAAGH,IAC5BA,CAAM,ECLdN,EAAoBQ,EAAI,CAAChB,EAASkB,KACjC,IAAI,IAAIC,KAAOD,EACXV,EAAoBY,EAAEF,EAAYC,KAASX,EAAoBY,EAAEpB,EAASmB,IAC5EE,OAAOC,eAAetB,EAASmB,EAAK,CAAEI,YAAY,EAAMC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BC,GACtB,MAAM,MAAEC,EAAK,YAAEC,GAAgBF,EAE/B,OAAQG,IACN,IAAK,MAAMC,KAAUH,EAAO,CAC1B,IAAII,EAAsB,KAQ1B,GAPe,WAAXD,EACFC,EAAOvC,EAAWqC,EAAIG,QAAQlC,QACV,SAAXgC,EACTC,EAAgBF,EAAII,IAnBArC,MAAM,KACTsC,MAAMC,GAAS,aAAaC,KAAKD,MACzC,KAkBW,UAAXL,IACTC,EAAO1B,EAAUwB,EAAII,MAEnBF,EACF,OAAOA,CAEX,CACA,OAAOH,CAAW,CAEtB,CAoBqBS,CAAexB,EAAOyB,WAEzC,SAASC,EAAE9D,EAAaoD,G,QACtB,MAAOd,EAAIyB,GAAW/D,EAAImB,MAAM,KAC1BmC,EACJF,GAAOlD,OAAO8D,KAAKZ,GAAKa,OACpBjB,EAAWI,GACXd,IACyB,QAAvB,EAAiB,QAAjB,EAAAF,aAAM,EAANA,EAAQG,iBAAS,eAAGD,UAAG,eAAEa,cACzBf,EAAOyB,UAAUV,YAEzB,OAAIb,GAAMyB,GAAWzB,KAAMD,GAAaiB,KAAQjB,EAAUC,GACjDD,EAAUC,GAAIgB,GAAMS,IAAY/D,EAGlCqC,EAAmB,QAAEiB,GAAMtD,IAAQA,CAC5C,CAoBA,OAlBA8D,EAAEI,OAAS,CAACC,EAAiB7B,K,MAC3B,IAAKF,EACH,MAAM,IAAIK,MAAM,uBAKlB,GAFAL,EAAOyB,UAAUV,YAAcgB,EAE3B7B,EAAI,CACN,MAAMC,EAA4B,QAAhB,EAAAH,EAAOG,iBAAS,eAAGD,GAErC,IAAIC,EAGF,MAAM,IAAIE,MAAM,aAAaH,eAF7BC,EAAUY,YAAcgB,CAI5B,GAGKL,CACT,G","sources":["webpack://fasti18n/webpack/universalModuleDefinition","webpack://fasti18n/external umd \"{}\"","webpack://fasti18n/webpack/bootstrap","webpack://fasti18n/webpack/runtime/compat get default export","webpack://fasti18n/webpack/runtime/define property getters","webpack://fasti18n/webpack/runtime/hasOwnProperty shorthand","webpack://fasti18n/webpack/runtime/make namespace object","webpack://fasti18n/./src/index.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"{}\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"fasti18n\", [\"{}\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"fasti18n\"] = factory(require(\"{}\"));\n\telse\n\t\troot[\"fasti18n\"] = factory(root[\"{}\"]);\n})(self, (__WEBPACK_EXTERNAL_MODULE__324__) => {\nreturn ","module.exports = __WEBPACK_EXTERNAL_MODULE__324__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { readFileSync } from 'node:fs'\n\n// Helper function to read files\nfunction readFile(filePath: string): string {\n return readFileSync(filePath, 'utf-8')\n}\n\nfunction parseCookies(cookieHeader: string | undefined): Record {\n const cookies: Record = {}\n if (!cookieHeader) {\n return cookies\n }\n\n cookieHeader.split(';').forEach((cookie) => {\n const [name, ...rest] = cookie.split('=')\n if (name) {\n cookies[name.trim()] = decodeURIComponent(rest.join('='))\n }\n })\n\n return cookies\n}\n\nfunction parseQueryString(queryString: string): Record {\n const query: Record = {}\n if (!queryString) {\n return query\n }\n\n queryString\n .replace(/^\\?/, '')\n .split('&')\n .forEach((param) => {\n const [key, value] = param.split('=')\n if (key && value) {\n query[key] = decodeURIComponent(value)\n }\n })\n\n return query\n}\n\nfunction loadJSON(filePath: string): Promise> {\n return JSON.parse(readFile(filePath))\n}\n\ninterface I18nConfig {\n namespace: Record<\n string,\n {\n load: string\n type?: string\n storage?: string\n defaultLang: string\n }\n >\n detection: {\n order: string[]\n defaultLang: string\n }\n}\n\nfunction fromCookie(cookies: string | undefined): string | null {\n const parsedCookies = parseCookies(cookies)\n return parsedCookies['lang'] || null\n}\n\nfunction fromPath(reqPath: string): string | null {\n const pathParts = reqPath.split('/')\n const lang = pathParts.find((part) => /^[a-z]{2}$/.test(part))\n return lang || null\n}\n\nfunction fromQuery(queryString: string): string | null {\n const parsedQuery = parseQueryString(queryString)\n return parsedQuery['lang'] || null\n}\n\nfunction detectLanguage(detectionConfig: I18nConfig['detection']) {\n const { order, defaultLang } = detectionConfig\n\n return (req: { headers: { cookie?: string }; url: string }) => {\n for (const method of order) {\n let lang: string | null = null\n if (method === 'cookie') {\n lang = fromCookie(req.headers.cookie)\n } else if (method === 'path') {\n lang = fromPath(req.url)\n } else if (method === 'query') {\n lang = fromQuery(req.url)\n }\n if (lang) {\n return lang\n }\n }\n return defaultLang\n }\n}\n\ninterface TranslateFunction {\n (key: string, req?: { headers: { cookie?: string }; url: string }): string\n switch: (newLang: string, ns: string) => void\n}\n\nfunction i18nInit(config: I18nConfig): TranslateFunction {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const languages: Record = {}\n for (const ns in config.namespace) {\n const namespaceConfig = config.namespace[ns]\n\n if (namespaceConfig) {\n languages[ns] = loadJSON(namespaceConfig.load)\n } else {\n throw new Error('Invalid namespace configuration')\n }\n }\n\n const detectLang = detectLanguage(config.detection)\n\n function t(key: string, req?: { headers: { cookie?: string }; url: string }): string {\n const [ns, langKey] = key.split('.')\n const lang =\n req && Object.keys(req).length\n ? detectLang(req)\n : ns\n ? config?.namespace?.[ns]?.defaultLang || config.detection.defaultLang\n : config.detection.defaultLang\n\n if (ns && langKey && ns in languages && lang in languages[ns]) {\n return languages[ns][lang][langKey] || key\n }\n\n return languages['default'][lang][key] || key\n }\n\n t.switch = (newLang: string, ns: string) => {\n if (!config) {\n throw new Error('Config is undefined')\n }\n\n config.detection.defaultLang = newLang\n\n if (ns) {\n const namespace = config.namespace?.[ns]\n\n if (namespace) {\n namespace.defaultLang = newLang\n } else {\n throw new Error(`Namespace ${ns} not found`)\n }\n }\n }\n\n return t\n}\n\nexport default {\n init: i18nInit,\n}\n"],"names":["root","factory","exports","module","require","define","amd","self","__WEBPACK_EXTERNAL_MODULE__324__","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","n","getter","__esModule","d","a","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","r","Symbol","toStringTag","value","fromCookie","cookies","parsedCookies","cookieHeader","split","forEach","cookie","name","rest","trim","decodeURIComponent","join","parseCookies","fromQuery","queryString","parsedQuery","query","replace","param","parseQueryString","init","config","languages","ns","namespace","namespaceConfig","Error","filePath","load","JSON","parse","readFileSync","readFile","detectLang","detectionConfig","order","defaultLang","req","method","lang","headers","url","find","part","test","detectLanguage","detection","t","langKey","keys","length","switch","newLang"],"sourceRoot":""}
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EnBF,EACF,OAAOA,CAEX,CACA,OAAOH,CAAW,CAEtB,CAoBqBS,CAAexB,EAAOyB,WAEzC,SAASC,EAAE9D,EAAaoD,G,QACtB,MAAOd,EAAIyB,GAAW/D,EAAImB,MAAM,KAC1BmC,EACJF,GAAOlD,OAAO8D,KAAKZ,GAAKa,OACpBjB,EAAWI,GACXd,IACyB,QAAvB,EAAiB,QAAjB,EAAAF,aAAM,EAANA,EAAQG,iBAAS,eAAGD,UAAG,eAAEa,cACzBf,EAAOyB,UAAUV,YAEzB,OAAIb,GAAMyB,GAAWzB,KAAMD,GAAaiB,KAAQjB,EAAUC,GACjDD,EAAUC,GAAIgB,GAAMS,IAAY/D,EAGlCqC,EAAmB,QAAEiB,GAAMtD,IAAQA,CAC5C,CAoBA,OAlBA8D,EAAEI,OAAS,CAACC,EAAiB7B,K,MAC3B,IAAKF,EACH,MAAM,IAAIK,MAAM,uBAKlB,GAFAL,EAAOyB,UAAUV,YAAcgB,EAE3B7B,EAAI,CACN,MAAMC,EAA4B,QAAhB,EAAAH,EAAOG,iBAAS,eAAGD,GAErC,IAAIC,EAGF,MAAM,IAAIE,MAAM,aAAaH,eAF7BC,EAAUY,YAAcgB,CAI5B,GAGKL,CACT,G",
+ "sources": [
+ "webpack://yoi18n/webpack/universalModuleDefinition",
+ "webpack://yoi18n/external umd \"{}\"",
+ "webpack://yoi18n/webpack/bootstrap",
+ "webpack://yoi18n/webpack/runtime/compat get default export",
+ "webpack://yoi18n/webpack/runtime/define property getters",
+ "webpack://yoi18n/webpack/runtime/hasOwnProperty shorthand",
+ "webpack://yoi18n/webpack/runtime/make namespace object",
+ "webpack://yoi18n/./src/index.ts"
+ ],
+ "sourcesContent": [
+ "(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"{}\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"yoi18n\", [\"{}\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"yoi18n\"] = factory(require(\"{}\"));\n\telse\n\t\troot[\"yoi18n\"] = factory(root[\"{}\"]);\n})(self, (__WEBPACK_EXTERNAL_MODULE__324__) => {\nreturn ",
+ "module.exports = __WEBPACK_EXTERNAL_MODULE__324__;",
+ "// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n",
+ "// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};",
+ "// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};",
+ "__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))",
+ "// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};",
+ "import { readFileSync } from 'node:fs'\n\n// Helper function to read files\nfunction readFile(filePath: string): string {\n return readFileSync(filePath, 'utf-8')\n}\n\nfunction parseCookies(cookieHeader: string | undefined): Record {\n const cookies: Record = {}\n if (!cookieHeader) {\n return cookies\n }\n\n cookieHeader.split(';').forEach((cookie) => {\n const [name, ...rest] = cookie.split('=')\n if (name) {\n cookies[name.trim()] = decodeURIComponent(rest.join('='))\n }\n })\n\n return cookies\n}\n\nfunction parseQueryString(queryString: string): Record {\n const query: Record = {}\n if (!queryString) {\n return query\n }\n\n queryString\n .replace(/^\\?/, '')\n .split('&')\n .forEach((param) => {\n const [key, value] = param.split('=')\n if (key && value) {\n query[key] = decodeURIComponent(value)\n }\n })\n\n return query\n}\n\nfunction loadJSON(filePath: string): Promise> {\n return JSON.parse(readFile(filePath))\n}\n\ninterface I18nConfig {\n namespace: Record<\n string,\n {\n load: string\n type?: string\n storage?: string\n defaultLang: string\n }\n >\n detection: {\n order: string[]\n defaultLang: string\n }\n}\n\nfunction fromCookie(cookies: string | undefined): string | null {\n const parsedCookies = parseCookies(cookies)\n return parsedCookies['lang'] || null\n}\n\nfunction fromPath(reqPath: string): string | null {\n const pathParts = reqPath.split('/')\n const lang = pathParts.find((part) => /^[a-z]{2}$/.test(part))\n return lang || null\n}\n\nfunction fromQuery(queryString: string): string | null {\n const parsedQuery = parseQueryString(queryString)\n return parsedQuery['lang'] || null\n}\n\nfunction detectLanguage(detectionConfig: I18nConfig['detection']) {\n const { order, defaultLang } = detectionConfig\n\n return (req: { headers: { cookie?: string }; url: string }) => {\n for (const method of order) {\n let lang: string | null = null\n if (method === 'cookie') {\n lang = fromCookie(req.headers.cookie)\n } else if (method === 'path') {\n lang = fromPath(req.url)\n } else if (method === 'query') {\n lang = fromQuery(req.url)\n }\n if (lang) {\n return lang\n }\n }\n return defaultLang\n }\n}\n\ninterface TranslateFunction {\n (key: string, req?: { headers: { cookie?: string }; url: string }): string\n switch: (newLang: string, ns: string) => void\n}\n\nfunction i18nInit(config: I18nConfig): TranslateFunction {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const languages: Record = {}\n for (const ns in config.namespace) {\n const namespaceConfig = config.namespace[ns]\n\n if (namespaceConfig) {\n languages[ns] = loadJSON(namespaceConfig.load)\n } else {\n throw new Error('Invalid namespace configuration')\n }\n }\n\n const detectLang = detectLanguage(config.detection)\n\n function t(key: string, req?: { headers: { cookie?: string }; url: string }): string {\n const [ns, langKey] = key.split('.')\n const lang =\n req && Object.keys(req).length\n ? detectLang(req)\n : ns\n ? config?.namespace?.[ns]?.defaultLang || config.detection.defaultLang\n : config.detection.defaultLang\n\n if (ns && langKey && ns in languages && lang in languages[ns]) {\n return languages[ns][lang][langKey] || key\n }\n\n return languages['default'][lang][key] || key\n }\n\n t.switch = (newLang: string, ns: string) => {\n if (!config) {\n throw new Error('Config is undefined')\n }\n\n config.detection.defaultLang = newLang\n\n if (ns) {\n const namespace = config.namespace?.[ns]\n\n if (namespace) {\n namespace.defaultLang = newLang\n } else {\n throw new Error(`Namespace ${ns} not found`)\n }\n }\n }\n\n return t\n}\n\nexport default {\n init: i18nInit,\n}\n"
+ ],
+ "names": [
+ "root",
+ "factory",
+ "exports",
+ "module",
+ "require",
+ "define",
+ "amd",
+ "self",
+ "__WEBPACK_EXTERNAL_MODULE__324__",
+ "__webpack_module_cache__",
+ "__webpack_require__",
+ "moduleId",
+ "cachedModule",
+ "undefined",
+ "__webpack_modules__",
+ "n",
+ "getter",
+ "__esModule",
+ "d",
+ "a",
+ "definition",
+ "key",
+ "o",
+ "Object",
+ "defineProperty",
+ "enumerable",
+ "get",
+ "obj",
+ "prop",
+ "prototype",
+ "hasOwnProperty",
+ "call",
+ "r",
+ "Symbol",
+ "toStringTag",
+ "value",
+ "fromCookie",
+ "cookies",
+ "parsedCookies",
+ "cookieHeader",
+ "split",
+ "forEach",
+ "cookie",
+ "name",
+ "rest",
+ "trim",
+ "decodeURIComponent",
+ "join",
+ "parseCookies",
+ "fromQuery",
+ "queryString",
+ "parsedQuery",
+ "query",
+ "replace",
+ "param",
+ "parseQueryString",
+ "init",
+ "config",
+ "languages",
+ "ns",
+ "namespace",
+ "namespaceConfig",
+ "Error",
+ "filePath",
+ "load",
+ "JSON",
+ "parse",
+ "readFileSync",
+ "readFile",
+ "detectLang",
+ "detectionConfig",
+ "order",
+ "defaultLang",
+ "req",
+ "method",
+ "lang",
+ "headers",
+ "url",
+ "find",
+ "part",
+ "test",
+ "detectLanguage",
+ "detection",
+ "t",
+ "langKey",
+ "keys",
+ "length",
+ "switch",
+ "newLang"
+ ],
+ "sourceRoot": ""
+}
diff --git a/browser/reacti18n-browser.min.js b/browser/reacti18n-browser.min.js
index 9d0c4b6..ffb122c 100644
--- a/browser/reacti18n-browser.min.js
+++ b/browser/reacti18n-browser.min.js
@@ -2,10 +2,10 @@
'object' == typeof exports && 'object' == typeof module
? (module.exports = t(require('{}')))
: 'function' == typeof define && define.amd
- ? define('fasti18n', ['{}'], t)
+ ? define('yoi18n', ['{}'], t)
: 'object' == typeof exports
- ? (exports.fasti18n = t(require('{}')))
- : (e.fasti18n = t(e['{}']))
+ ? (exports.yoi18n = t(require('{}')))
+ : (e.yoi18n = t(e['{}']))
})(self, (e) =>
(() => {
'use strict'
@@ -132,4 +132,4 @@
return r
})()
)
-//# sourceMappingURL=fasti18n-browser.min.js.map
+//# sourceMappingURL=yoi18n-browser.min.js.map
diff --git a/browser/reacti18n-browser.min.js.map b/browser/reacti18n-browser.min.js.map
index 99c5d13..ceb0eff 100644
--- a/browser/reacti18n-browser.min.js.map
+++ b/browser/reacti18n-browser.min.js.map
@@ -1,19 +1,19 @@
{
"version": 3,
- "file": "fasti18n-browser.min.js",
+ "file": "yoi18n-browser.min.js",
"mappings": "CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,EAAQG,QAAQ,OACR,mBAAXC,QAAyBA,OAAOC,IAC9CD,OAAO,YAAa,CAAC,MAAOJ,GACF,iBAAZC,QACdA,QAAmB,UAAID,EAAQG,QAAQ,OAEvCJ,EAAgB,UAAIC,EAAQD,EAAK,MAClC,CATD,CASGO,MAAOC,G,kCCTVL,EAAOD,QAAUM,C,GCCbC,EAA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AAMD,GAAaiB,KAAQjB,EAAUC,GACjDD,EAAUC,GAAIgB,GAAMS,IAAY/D,EAGlCqC,EAAmB,QAAEiB,GAAMtD,IAAQA,CAC5C,CAcA,OAZA8D,EAAEI,OAAS,CAACC,EAAiB7B,KAG3B,GAFAF,EAAOyB,UAAUV,YAAcgB,EAE3B7B,EAAI,CACN,IAAIF,EAAOG,UAAUD,GAGnB,MAAM,IAAIG,MAAM,aAAaH,eAF7BF,EAAOG,UAAUD,GAAIa,YAAcgB,CAIvC,GAGKL,CACT,G",
"sources": [
- "webpack://fasti18n/webpack/universalModuleDefinition",
- "webpack://fasti18n/external umd \"{}\"",
- "webpack://fasti18n/webpack/bootstrap",
- "webpack://fasti18n/webpack/runtime/compat get default export",
- "webpack://fasti18n/webpack/runtime/define property getters",
- "webpack://fasti18n/webpack/runtime/hasOwnProperty shorthand",
- "webpack://fasti18n/webpack/runtime/make namespace object",
- "webpack://fasti18n/./src/index.ts"
+ "webpack://yoi18n/webpack/universalModuleDefinition",
+ "webpack://yoi18n/external umd \"{}\"",
+ "webpack://yoi18n/webpack/bootstrap",
+ "webpack://yoi18n/webpack/runtime/compat get default export",
+ "webpack://yoi18n/webpack/runtime/define property getters",
+ "webpack://yoi18n/webpack/runtime/hasOwnProperty shorthand",
+ "webpack://yoi18n/webpack/runtime/make namespace object",
+ "webpack://yoi18n/./src/index.ts"
],
"sourcesContent": [
- "(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"{}\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"fasti18n\", [\"{}\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"fasti18n\"] = factory(require(\"{}\"));\n\telse\n\t\troot[\"fasti18n\"] = factory(root[\"{}\"]);\n})(self, (__WEBPACK_EXTERNAL_MODULE__324__) => {\nreturn ",
+ "(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"{}\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"yoi18n\", [\"{}\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"yoi18n\"] = factory(require(\"{}\"));\n\telse\n\t\troot[\"yoi18n\"] = factory(root[\"{}\"]);\n})(self, (__WEBPACK_EXTERNAL_MODULE__324__) => {\nreturn ",
"module.exports = __WEBPACK_EXTERNAL_MODULE__324__;",
"// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n",
"// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};",
diff --git a/browser/yoi18n-browser.min.js b/browser/yoi18n-browser.min.js
new file mode 100644
index 0000000..847a104
--- /dev/null
+++ b/browser/yoi18n-browser.min.js
@@ -0,0 +1,2 @@
+!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n(require("{}")):"function"==typeof define&&define.amd?define("yoi18n",["{}"],n):"object"==typeof exports?exports.yoi18n=n(require("{}")):e.yoi18n=n(e["{}"])}(self,(e=>(()=>{"use strict";var n={324:n=>{n.exports=e}},t={};function o(e){var r=t[e];if(void 0!==r)return r.exports;var i=t[e]={exports:{}};return n[e](i,i.exports,o),i.exports}o.n=e=>{var n=e&&e.__esModule?()=>e.default:()=>e;return o.d(n,{a:n}),n},o.d=(e,n)=>{for(var t in n)o.o(n,t)&&!o.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:n[t]})},o.o=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};o.r(r),o.d(r,{default:()=>c});var i=o(324);function u(e){const n=function(e){const n={};return e?(e.split(";").forEach((e=>{const[t,...o]=e.split("=");t&&(n[t.trim()]=decodeURIComponent(o.join("=")))})),n):n}(e);return n.lang||null}function a(e){const n=function(e){const n={};return e?(e.replace(/^\?/,"").split("&").forEach((e=>{const[t,o]=e.split("=");t&&o&&(n[t]=decodeURIComponent(o))})),n):n}(e);return n.lang||null}const c={init:function(e){const n={};for(const o in e.namespace){const r=e.namespace[o];if(!r)throw new Error("Invalid namespace configuration");n[o]=(t=r.load,JSON.parse(function(e){return(0,i.readFileSync)(e,"utf-8")}(t)))}var t;const o=function(e){const{order:n,defaultLang:t}=e;return e=>{for(const t of n){let n=null;if("cookie"===t?n=u(e.headers.cookie):"path"===t?n=e.url.split("/").find((e=>/^[a-z]{2}$/.test(e)))||null:"query"===t&&(n=a(e.url)),n)return n}return t}}(e.detection);function r(t,r){var i,u;const[a,c]=t.split("."),l=r&&Object.keys(r).length?o(r):a&&(null===(u=null===(i=null==e?void 0:e.namespace)||void 0===i?void 0:i[a])||void 0===u?void 0:u.defaultLang)||e.detection.defaultLang;return a&&c&&a in n&&l in n[a]?n[a][l][c]||t:n.default[l][t]||t}return r.switch=(n,t)=>{var o;if(!e)throw new Error("Config is undefined");if(e.detection.defaultLang=n,t){const r=null===(o=e.namespace)||void 0===o?void 0:o[t];if(!r)throw new Error(`Namespace ${t} not found`);r.defaultLang=n}},r}};return r})()));
+//# sourceMappingURL=yoi18n-browser.min.js.map
\ No newline at end of file
diff --git a/browser/yoi18n-browser.min.js.map b/browser/yoi18n-browser.min.js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AAKD,MACzC,KAkBW,UAAXL,IACTC,EAAO1B,EAAUwB,EAAII,MAEnBF,EACF,OAAOA,CAEX,CACA,OAAOH,CAAW,CAEtB,CAoBqBS,CAAexB,EAAOyB,WAEzC,SAASC,EAAE9D,EAAaoD,G,QACtB,MAAOd,EAAIyB,GAAW/D,EAAImB,MAAM,KAC1BmC,EACJF,GAAOlD,OAAO8D,KAAKZ,GAAKa,OACpBjB,EAAWI,GACXd,IACyB,QAAvB,EAAiB,QAAjB,EAAAF,aAAM,EAANA,EAAQG,iBAAS,eAAGD,UAAG,eAAEa,cACzBf,EAAOyB,UAAUV,YAEzB,OAAIb,GAAMyB,GAAWzB,KAAMD,GAAaiB,KAAQjB,EAAUC,GACjDD,EAAUC,GAAIgB,GAAMS,IAAY/D,EAGlCqC,EAAmB,QAAEiB,GAAMtD,IAAQA,CAC5C,CAoBA,OAlBA8D,EAAEI,OAAS,CAACC,EAAiB7B,K,MAC3B,IAAKF,EACH,MAAM,IAAIK,MAAM,uBAKlB,GAFAL,EAAOyB,UAAUV,YAAcgB,EAE3B7B,EAAI,CACN,MAAMC,EAA4B,QAAhB,EAAAH,EAAOG,iBAAS,eAAGD,GAErC,IAAIC,EAGF,MAAM,IAAIE,MAAM,aAAaH,eAF7BC,EAAUY,YAAcgB,CAI5B,GAGKL,CACT,G","sources":["webpack://yoi18n/webpack/universalModuleDefinition","webpack://yoi18n/external umd \"{}\"","webpack://yoi18n/webpack/bootstrap","webpack://yoi18n/webpack/runtime/compat get default export","webpack://yoi18n/webpack/runtime/define property getters","webpack://yoi18n/webpack/runtime/hasOwnProperty shorthand","webpack://yoi18n/webpack/runtime/make namespace object","webpack://yoi18n/./src/index.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"{}\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"yoi18n\", [\"{}\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"yoi18n\"] = factory(require(\"{}\"));\n\telse\n\t\troot[\"yoi18n\"] = factory(root[\"{}\"]);\n})(self, (__WEBPACK_EXTERNAL_MODULE__324__) => {\nreturn ","module.exports = __WEBPACK_EXTERNAL_MODULE__324__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { readFileSync } from 'node:fs'\n\n// Helper function to read files\nfunction readFile(filePath: string): string {\n return readFileSync(filePath, 'utf-8')\n}\n\nfunction parseCookies(cookieHeader: string | undefined): Record {\n const cookies: Record = {}\n if (!cookieHeader) {\n return cookies\n }\n\n cookieHeader.split(';').forEach((cookie) => {\n const [name, ...rest] = cookie.split('=')\n if (name) {\n cookies[name.trim()] = decodeURIComponent(rest.join('='))\n }\n })\n\n return cookies\n}\n\nfunction parseQueryString(queryString: string): Record {\n const query: Record = {}\n if (!queryString) {\n return query\n }\n\n queryString\n .replace(/^\\?/, '')\n .split('&')\n .forEach((param) => {\n const [key, value] = param.split('=')\n if (key && value) {\n query[key] = decodeURIComponent(value)\n }\n })\n\n return query\n}\n\nfunction loadJSON(filePath: string): Promise> {\n return JSON.parse(readFile(filePath))\n}\n\ninterface I18nConfig {\n namespace: Record<\n string,\n {\n load: string\n type?: string\n storage?: string\n defaultLang: string\n }\n >\n detection: {\n order: string[]\n defaultLang: string\n }\n}\n\nfunction fromCookie(cookies: string | undefined): string | null {\n const parsedCookies = parseCookies(cookies)\n return parsedCookies['lang'] || null\n}\n\nfunction fromPath(reqPath: string): string | null {\n const pathParts = reqPath.split('/')\n const lang = pathParts.find((part) => /^[a-z]{2}$/.test(part))\n return lang || null\n}\n\nfunction fromQuery(queryString: string): string | null {\n const parsedQuery = parseQueryString(queryString)\n return parsedQuery['lang'] || null\n}\n\nfunction detectLanguage(detectionConfig: I18nConfig['detection']) {\n const { order, defaultLang } = detectionConfig\n\n return (req: { headers: { cookie?: string }; url: string }) => {\n for (const method of order) {\n let lang: string | null = null\n if (method === 'cookie') {\n lang = fromCookie(req.headers.cookie)\n } else if (method === 'path') {\n lang = fromPath(req.url)\n } else if (method === 'query') {\n lang = fromQuery(req.url)\n }\n if (lang) {\n return lang\n }\n }\n return defaultLang\n }\n}\n\ninterface TranslateFunction {\n (key: string, req?: { headers: { cookie?: string }; url: string }): string\n switch: (newLang: string, ns: string) => void\n}\n\nfunction i18nInit(config: I18nConfig): TranslateFunction {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const languages: Record = {}\n for (const ns in config.namespace) {\n const namespaceConfig = config.namespace[ns]\n\n if (namespaceConfig) {\n languages[ns] = loadJSON(namespaceConfig.load)\n } else {\n throw new Error('Invalid namespace configuration')\n }\n }\n\n const detectLang = detectLanguage(config.detection)\n\n function t(key: string, req?: { headers: { cookie?: string }; url: string }): string {\n const [ns, langKey] = key.split('.')\n const lang =\n req && Object.keys(req).length\n ? detectLang(req)\n : ns\n ? config?.namespace?.[ns]?.defaultLang || config.detection.defaultLang\n : config.detection.defaultLang\n\n if (ns && langKey && ns in languages && lang in languages[ns]) {\n return languages[ns][lang][langKey] || key\n }\n\n return languages['default'][lang][key] || key\n }\n\n t.switch = (newLang: string, ns: string) => {\n if (!config) {\n throw new Error('Config is undefined')\n }\n\n config.detection.defaultLang = newLang\n\n if (ns) {\n const namespace = config.namespace?.[ns]\n\n if (namespace) {\n namespace.defaultLang = newLang\n } else {\n throw new Error(`Namespace ${ns} not found`)\n }\n }\n }\n\n return t\n}\n\nexport default {\n init: i18nInit,\n}\n"],"names":["root","factory","exports","module","require","define","amd","self","__WEBPACK_EXTERNAL_MODULE__324__","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","n","getter","__esModule","d","a","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","r","Symbol","toStringTag","value","fromCookie","cookies","parsedCookies","cookieHeader","split","forEach","cookie","name","rest","trim","decodeURIComponent","join","parseCookies","fromQuery","queryString","parsedQuery","query","replace","param","parseQueryString","init","config","languages","ns","namespace","namespaceConfig","Error","filePath","load","JSON","parse","readFileSync","readFile","detectLang","detectionConfig","order","defaultLang","req","method","lang","headers","url","find","part","test","detectLanguage","detection","t","langKey","keys","length","switch","newLang"],"sourceRoot":""}
\ No newline at end of file
diff --git a/jsr.json b/jsr.json
index f2a6ce1..5fd95d5 100644
--- a/jsr.json
+++ b/jsr.json
@@ -1,5 +1,5 @@
{
- "name": "@fzn0x/fasti18n",
+ "name": "@fzn0x/yoi18n",
"version": "0.0.0",
"compilerOptions": {
"lib": ["dom", "dom.iterable", "deno.ns"]
diff --git a/package.json b/package.json
index 5817ded..6907562 100644
--- a/package.json
+++ b/package.json
@@ -1,11 +1,11 @@
{
- "name": "fasti18n",
+ "name": "yoi18n",
"version": "0.0.0",
"description": "Straightforward & less effort React i18n library.",
"main": "./dist/index.js",
"repository": {
"type": "git",
- "url": "https://github.com/fzn0x/fasti18n.git"
+ "url": "https://github.com/fzn0x/yoi18n.git"
},
"type": "module",
"sideEffects": false,
diff --git a/src/index.test.ts b/src/index.test.ts
index a7bd6d4..eec12d3 100644
--- a/src/index.test.ts
+++ b/src/index.test.ts
@@ -1,7 +1,7 @@
-import fasti18n from '../dist'
+import yoi18n from '../dist'
describe('init', () => {
- const t = fasti18n.init({
+ const t = yoi18n.init({
namespace: {
default: {
load: './lang.json',
diff --git a/tsconfig.json b/tsconfig.json
index 1aa8432..635bb77 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -32,7 +32,7 @@
"declarationMap": true,
"types": ["vitest/globals"],
"paths": {
- "fasti18n": ["dist"],
+ "yoi18n": ["dist"],
"*": ["*", "utils/*"]
}
},
diff --git a/webpack.config.ts b/webpack.config.ts
index d477f4a..86fc699 100644
--- a/webpack.config.ts
+++ b/webpack.config.ts
@@ -7,12 +7,12 @@ module.exports = /** @type { import('webpack').Configuration } */ {
devtool: 'source-map',
output: {
library: {
- name: 'fasti18n',
+ name: 'yoi18n',
type: 'umd',
umdNamedDefine: true,
},
path: path.resolve(__dirname, 'browser'),
- filename: 'fasti18n-browser.min.js',
+ filename: 'yoi18n-browser.min.js',
},
externals: {
'node:fs': '{}',