Socket
Socket
Sign inDemoInstall

svelte-i18n

Package Overview
Dependencies
6
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.2.7 to 3.3.0

9

CHANGELOG.md

@@ -0,1 +1,10 @@

# [3.3.0](https://github.com/kaisermann/svelte-i18n/compare/v3.2.7...v3.3.0) (2020-11-24)
### Features
* 🎸 add $json method to get raw dictionary values ([52400b5](https://github.com/kaisermann/svelte-i18n/commit/52400b5c51213b45270da101aab6e8ae2bda024c)), closes [#109](https://github.com/kaisermann/svelte-i18n/issues/109) [#83](https://github.com/kaisermann/svelte-i18n/issues/83)
## [3.2.7](https://github.com/kaisermann/svelte-i18n/compare/v3.2.6...v3.2.7) (2020-11-23)

@@ -2,0 +11,0 @@

4

dist/runtime.cjs.js

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("svelte/store"),t=require("deepmerge"),n=require("dlv"),r=require("intl-messageformat");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=o(t),a=o(n),l=o(r);let s;const u=e.writable({});function c(e){return e in s}function m(e,t){if(!c(e))return null;const n=function(e){return s[e]||null}(e);if(t in n)return n[t];return a.default(n,t)}function f(e){return null==e||c(e)?e:f(E(e))}function d(e,...t){u.update((n=>(n[e]=i.default.all([n[e]||{},...t]),n)))}const p=e.derived([u],(([e])=>Object.keys(e)));u.subscribe((e=>s=e));const g={};function w(e){return g[e]}function b(e){return N(e).reverse().some((e=>{var t;return null===(t=w(e))||void 0===t?void 0:t.size}))}function h(e,t){return Promise.all(t.map((t=>(function(e,t){g[e].delete(t),0===g[e].size&&delete g[e]}(e,t),t().then((e=>e.default||e)))))).then((t=>d(e,...t)))}const y={};function v(e){if(!b(e))return e in y?y[e]:void 0;const t=function(e){return N(e).reverse().map((e=>{const t=w(e);return[e,t?[...t]:[]]})).filter((([,e])=>e.length>0))}(e);return y[e]=Promise.all(t.map((([e,t])=>h(e,t)))).then((()=>{if(b(e))return v(e);delete y[e]})),y[e]}
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("svelte/store"),t=require("deepmerge"),n=require("dlv"),r=require("intl-messageformat");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=o(t),a=o(n),l=o(r);let s;const u=e.writable({});function c(e){return e in s}function m(e,t){if(!c(e))return null;const n=function(e){return s[e]||null}(e);if(t in n)return n[t];return a.default(n,t)}function f(e){return null==e||c(e)?e:f(D(e))}function d(e,...t){u.update((n=>(n[e]=i.default.all([n[e]||{},...t]),n)))}const p=e.derived([u],(([e])=>Object.keys(e)));u.subscribe((e=>s=e));const g={};function w(e){return g[e]}function h(e){return E(e).reverse().some((e=>{var t;return null===(t=w(e))||void 0===t?void 0:t.size}))}function b(e,t){return Promise.all(t.map((t=>(function(e,t){g[e].delete(t),0===g[e].size&&delete g[e]}(e,t),t().then((e=>e.default||e)))))).then((t=>d(e,...t)))}const y={};function v(e){if(!h(e))return e in y?y[e]:void 0;const t=function(e){return E(e).reverse().map((e=>{const t=w(e);return[e,t?[...t]:[]]})).filter((([,e])=>e.length>0))}(e);return y[e]=Promise.all(t.map((([e,t])=>b(e,t)))).then((()=>{if(h(e))return v(e);delete y[e]})),y[e]}
/*! *****************************************************************************

@@ -16,2 +16,2 @@ Copyright (c) Microsoft Corporation.

***************************************************************************** */
function x(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}const O={fallbackLocale:null,initialLocale:null,loadingDelay:200,formats:{number:{scientific:{notation:"scientific"},engineering:{notation:"engineering"},compactLong:{notation:"compact",compactDisplay:"long"},compactShort:{notation:"compact",compactDisplay:"short"}},date:{short:{month:"numeric",day:"numeric",year:"2-digit"},medium:{month:"short",day:"numeric",year:"numeric"},long:{month:"long",day:"numeric",year:"numeric"},full:{weekday:"long",month:"long",day:"numeric",year:"numeric"}},time:{short:{hour:"numeric",minute:"numeric"},medium:{hour:"numeric",minute:"numeric",second:"numeric"},long:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"},full:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"}}},warnOnMissingMessages:!0};function j(){return O}const L=e.writable(!1);let F;const k=e.writable(null);function M(e,t){return 0===t.indexOf(e)&&e!==t}function D(e,t){return e===t||M(e,t)||M(t,e)}function E(e){const t=e.lastIndexOf("-");if(t>0)return e.slice(0,t);const{fallbackLocale:n}=j();return n&&!D(e,n)?n:null}function N(e){const t=e.split("-").map(((e,t,n)=>n.slice(0,t+1).join("-"))),{fallbackLocale:n}=j();return n&&!D(e,n)?t.concat(N(n)):t}function P(){return F}k.subscribe((e=>{F=e,"undefined"!=typeof window&&document.documentElement.setAttribute("lang",e)}));const S=k.set;k.set=e=>{if(f(e)&&b(e)){const{loadingDelay:t}=j();let n;return"undefined"!=typeof window&&null!=P()&&t?n=window.setTimeout((()=>L.set(!0)),t):L.set(!0),v(e).then((()=>{S(e)})).finally((()=>{clearTimeout(n),L.set(!1)}))}return S(e)},k.update=e=>S(e(F));const T=(e,t)=>{const n=e.split("&").find((e=>0===e.indexOf(t+"=")));return n?n.split("=").pop():null},I=(e,t)=>{const n=t.exec(e);return n&&n[1]||null},$={},q=(e,t)=>{if(null==t)return null;const n=m(t,e);return n||q(e,E(t))},A=(e,t)=>{if(t in $&&e in $[t])return $[t][e];const n=q(e,t);return n?((e,t,n)=>n?(t in $||($[t]={}),e in $[t]||($[t][e]=n),n):n)(e,t,n):null},_=e=>{const t=Object.create(null);return n=>{const r=JSON.stringify(n);return r in t?t[r]:t[r]=e(n)}},z=(e,t)=>{const{formats:n}=j();if(e in n&&t in n[e])return n[e][t];throw new Error(`[svelte-i18n] Unknown "${t}" ${e} format.`)},H=_((e=>{var{locale:t,format:n}=e,r=x(e,["locale","format"]);if(null==t)throw new Error('[svelte-i18n] A "locale" must be set to format numbers');return n&&(r=z("number",n)),new Intl.NumberFormat(t,r)})),Z=_((e=>{var{locale:t,format:n}=e,r=x(e,["locale","format"]);if(null==t)throw new Error('[svelte-i18n] A "locale" must be set to format dates');return n?r=z("date",n):0===Object.keys(r).length&&(r=z("date","short")),new Intl.DateTimeFormat(t,r)})),C=_((e=>{var{locale:t,format:n}=e,r=x(e,["locale","format"]);if(null==t)throw new Error('[svelte-i18n] A "locale" must be set to format time values');return n?r=z("time",n):0===Object.keys(r).length&&(r=z("time","short")),new Intl.DateTimeFormat(t,r)})),J=(e={})=>{var{locale:t=P()}=e,n=x(e,["locale"]);return H(Object.assign({locale:t},n))},Q=(e={})=>{var{locale:t=P()}=e,n=x(e,["locale"]);return Z(Object.assign({locale:t},n))},U=(e={})=>{var{locale:t=P()}=e,n=x(e,["locale"]);return C(Object.assign({locale:t},n))},B=_(((e,t=P())=>new l.default(e,t,j().formats))),G=(e,t={})=>{"object"==typeof e&&(e=(t=e).id);const{values:n,locale:r=P(),default:o}=t;if(null==r)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");let i=A(e,r);return i||(j().warnOnMissingMessages&&console.warn(`[svelte-i18n] The message "${e}" was not found in "${N(r).join('", "')}".${b(P())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`),i=o||e),n?B(i,r).format(n):i},K=(e,t)=>U(t).format(e),R=(e,t)=>Q(t).format(e),V=(e,t)=>J(t).format(e),W=e.derived([k,u],(()=>G)),X=e.derived([k],(()=>K)),Y=e.derived([k],(()=>R)),ee=e.derived([k],(()=>V));exports._=W,exports.addMessages=d,exports.date=Y,exports.defineMessages=function(e){return e},exports.dictionary=u,exports.format=W,exports.getDateFormatter=Q,exports.getLocaleFromHash=e=>"undefined"==typeof window?null:T(window.location.hash.substr(1),e),exports.getLocaleFromHostname=e=>"undefined"==typeof window?null:I(window.location.hostname,e),exports.getLocaleFromNavigator=()=>"undefined"==typeof window?null:window.navigator.language||window.navigator.languages[0],exports.getLocaleFromPathname=e=>"undefined"==typeof window?null:I(window.location.pathname,e),exports.getLocaleFromQueryString=e=>"undefined"==typeof window?null:T(window.location.search.substr(1),e),exports.getMessageFormatter=B,exports.getNumberFormatter=J,exports.getTimeFormatter=U,exports.init=function(e){const{formats:t}=e,n=x(e,["formats"]),r=e.initialLocale||e.fallbackLocale;return Object.assign(O,n,{initialLocale:r}),t&&("number"in t&&Object.assign(O.formats.number,t.number),"date"in t&&Object.assign(O.formats.date,t.date),"time"in t&&Object.assign(O.formats.time,t.time)),k.set(r)},exports.isLoading=L,exports.locale=k,exports.locales=p,exports.number=ee,exports.register=function(e,t){w(e)||function(e){g[e]=new Set}(e);const n=w(e);w(e).has(t)||(c(e)||u.update((t=>(t[e]={},t))),n.add(t))},exports.t=W,exports.time=X,exports.waitLocale=function(e){return v(e||P()||j().initialLocale)};
function x(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}const O={fallbackLocale:null,initialLocale:null,loadingDelay:200,formats:{number:{scientific:{notation:"scientific"},engineering:{notation:"engineering"},compactLong:{notation:"compact",compactDisplay:"long"},compactShort:{notation:"compact",compactDisplay:"short"}},date:{short:{month:"numeric",day:"numeric",year:"2-digit"},medium:{month:"short",day:"numeric",year:"numeric"},long:{month:"long",day:"numeric",year:"numeric"},full:{weekday:"long",month:"long",day:"numeric",year:"numeric"}},time:{short:{hour:"numeric",minute:"numeric"},medium:{hour:"numeric",minute:"numeric",second:"numeric"},long:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"},full:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"}}},warnOnMissingMessages:!0};function j(){return O}const L=e.writable(!1);let F;const k=e.writable(null);function M(e,t){return 0===t.indexOf(e)&&e!==t}function $(e,t){return e===t||M(e,t)||M(t,e)}function D(e){const t=e.lastIndexOf("-");if(t>0)return e.slice(0,t);const{fallbackLocale:n}=j();return n&&!$(e,n)?n:null}function E(e){const t=e.split("-").map(((e,t,n)=>n.slice(0,t+1).join("-"))),{fallbackLocale:n}=j();return n&&!$(e,n)?t.concat(E(n)):t}function N(){return F}k.subscribe((e=>{F=e,"undefined"!=typeof window&&document.documentElement.setAttribute("lang",e)}));const P=k.set;k.set=e=>{if(f(e)&&h(e)){const{loadingDelay:t}=j();let n;return"undefined"!=typeof window&&null!=N()&&t?n=window.setTimeout((()=>L.set(!0)),t):L.set(!0),v(e).then((()=>{P(e)})).finally((()=>{clearTimeout(n),L.set(!1)}))}return P(e)},k.update=e=>P(e(F));const S=(e,t)=>{const n=e.split("&").find((e=>0===e.indexOf(t+"=")));return n?n.split("=").pop():null},T=(e,t)=>{const n=t.exec(e);return n&&n[1]||null},I={},q=(e,t)=>{if(null==t)return;const n=m(t,e);return n||q(e,D(t))},A=(e,t)=>{if(t in I&&e in I[t])return I[t][e];const n=q(e,t);return n?((e,t,n)=>n?(t in I||(I[t]={}),e in I[t]||(I[t][e]=n),n):n)(e,t,n):void 0},_=e=>{const t=Object.create(null);return n=>{const r=JSON.stringify(n);return r in t?t[r]:t[r]=e(n)}},z=(e,t)=>{const{formats:n}=j();if(e in n&&t in n[e])return n[e][t];throw new Error(`[svelte-i18n] Unknown "${t}" ${e} format.`)},H=_((e=>{var{locale:t,format:n}=e,r=x(e,["locale","format"]);if(null==t)throw new Error('[svelte-i18n] A "locale" must be set to format numbers');return n&&(r=z("number",n)),new Intl.NumberFormat(t,r)})),Z=_((e=>{var{locale:t,format:n}=e,r=x(e,["locale","format"]);if(null==t)throw new Error('[svelte-i18n] A "locale" must be set to format dates');return n?r=z("date",n):0===Object.keys(r).length&&(r=z("date","short")),new Intl.DateTimeFormat(t,r)})),C=_((e=>{var{locale:t,format:n}=e,r=x(e,["locale","format"]);if(null==t)throw new Error('[svelte-i18n] A "locale" must be set to format time values');return n?r=z("time",n):0===Object.keys(r).length&&(r=z("time","short")),new Intl.DateTimeFormat(t,r)})),G=(e={})=>{var{locale:t=N()}=e,n=x(e,["locale"]);return H(Object.assign({locale:t},n))},J=(e={})=>{var{locale:t=N()}=e,n=x(e,["locale"]);return Z(Object.assign({locale:t},n))},Q=(e={})=>{var{locale:t=N()}=e,n=x(e,["locale"]);return C(Object.assign({locale:t},n))},U=_(((e,t=N())=>new l.default(e,t,j().formats))),B=(e,t={})=>{"object"==typeof e&&(e=(t=e).id);const{values:n,locale:r=N(),default:o}=t;if(null==r)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");let i=A(e,r);if(i){if("string"!=typeof i)return console.warn(`[svelte-i18n] Message with id "${e}" must be of type "string", found: "${typeof i}". Gettin its value through the "$format" method is deprecated; use the "json" method instead.`),i}else j().warnOnMissingMessages&&console.warn(`[svelte-i18n] The message "${e}" was not found in "${E(r).join('", "')}".${h(N())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`),i=o||e;return n?U(i,r).format(n):i},K=(e,t)=>Q(t).format(e),R=(e,t)=>J(t).format(e),V=(e,t)=>G(t).format(e),W=(e,t=N())=>A(e,t),X=e.derived([k,u],(()=>B)),Y=e.derived([k],(()=>K)),ee=e.derived([k],(()=>R)),te=e.derived([k],(()=>V)),ne=e.derived([k,u],(()=>W));exports._=X,exports.addMessages=d,exports.date=ee,exports.defineMessages=function(e){return e},exports.dictionary=u,exports.format=X,exports.getDateFormatter=J,exports.getLocaleFromHash=e=>"undefined"==typeof window?null:S(window.location.hash.substr(1),e),exports.getLocaleFromHostname=e=>"undefined"==typeof window?null:T(window.location.hostname,e),exports.getLocaleFromNavigator=()=>"undefined"==typeof window?null:window.navigator.language||window.navigator.languages[0],exports.getLocaleFromPathname=e=>"undefined"==typeof window?null:T(window.location.pathname,e),exports.getLocaleFromQueryString=e=>"undefined"==typeof window?null:S(window.location.search.substr(1),e),exports.getMessageFormatter=U,exports.getNumberFormatter=G,exports.getTimeFormatter=Q,exports.init=function(e){const{formats:t}=e,n=x(e,["formats"]),r=e.initialLocale||e.fallbackLocale;return Object.assign(O,n,{initialLocale:r}),t&&("number"in t&&Object.assign(O.formats.number,t.number),"date"in t&&Object.assign(O.formats.date,t.date),"time"in t&&Object.assign(O.formats.time,t.time)),k.set(r)},exports.isLoading=L,exports.json=ne,exports.locale=k,exports.locales=p,exports.number=te,exports.register=function(e,t){w(e)||function(e){g[e]=new Set}(e);const n=w(e);w(e).has(t)||(c(e)||u.update((t=>(t[e]={},t))),n.add(t))},exports.t=X,exports.time=Y,exports.waitLocale=function(e){return v(e||N()||j().initialLocale)};

@@ -1,2 +0,2 @@

import{writable as e,derived as n}from"svelte/store";import t from"deepmerge";import o from"dlv";import r from"intl-messageformat";let i;const a=e({});function l(e){return e in i}function u(e,n){if(!l(e))return null;const t=function(e){return i[e]||null}(e);if(n in t)return t[n];return o(t,n)}function s(e){return null==e||l(e)?e:s(I(e))}function c(e,...n){a.update((o=>(o[e]=t.all([o[e]||{},...n]),o)))}const m=n([a],(([e])=>Object.keys(e)));a.subscribe((e=>i=e));const f={};function d(e){return f[e]}function w(e){return N(e).reverse().some((e=>{var n;return null===(n=d(e))||void 0===n?void 0:n.size}))}function g(e,n){return Promise.all(n.map((n=>(function(e,n){f[e].delete(n),0===f[e].size&&delete f[e]}(e,n),n().then((e=>e.default||e)))))).then((n=>c(e,...n)))}const p={};function h(e){if(!w(e))return e in p?p[e]:void 0;const n=function(e){return N(e).reverse().map((e=>{const n=d(e);return[e,n?[...n]:[]]})).filter((([,e])=>e.length>0))}(e);return p[e]=Promise.all(n.map((([e,n])=>g(e,n)))).then((()=>{if(w(e))return h(e);delete p[e]})),p[e]}function b(e,n){d(e)||function(e){f[e]=new Set}(e);const t=d(e);d(e).has(n)||(l(e)||a.update((n=>(n[e]={},n))),t.add(n))}
import{writable as e,derived as n}from"svelte/store";import t from"deepmerge";import o from"dlv";import r from"intl-messageformat";let i;const a=e({});function l(e){return e in i}function s(e,n){if(!l(e))return null;const t=function(e){return i[e]||null}(e);if(n in t)return t[n];return o(t,n)}function u(e){return null==e||l(e)?e:u(D(e))}function c(e,...n){a.update((o=>(o[e]=t.all([o[e]||{},...n]),o)))}const m=n([a],(([e])=>Object.keys(e)));a.subscribe((e=>i=e));const f={};function d(e){return f[e]}function w(e){return I(e).reverse().some((e=>{var n;return null===(n=d(e))||void 0===n?void 0:n.size}))}function g(e,n){return Promise.all(n.map((n=>(function(e,n){f[e].delete(n),0===f[e].size&&delete f[e]}(e,n),n().then((e=>e.default||e)))))).then((n=>c(e,...n)))}const h={};function p(e){if(!w(e))return e in h?h[e]:void 0;const n=function(e){return I(e).reverse().map((e=>{const n=d(e);return[e,n?[...n]:[]]})).filter((([,e])=>e.length>0))}(e);return h[e]=Promise.all(n.map((([e,n])=>g(e,n)))).then((()=>{if(w(e))return p(e);delete h[e]})),h[e]}function b(e,n){d(e)||function(e){f[e]=new Set}(e);const t=d(e);d(e).has(n)||(l(e)||a.update((n=>(n[e]={},n))),t.add(n))}
/*! *****************************************************************************

@@ -15,2 +15,2 @@ Copyright (c) Microsoft Corporation.

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function y(e,n){var t={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&n.indexOf(o)<0&&(t[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)n.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(t[o[r]]=e[o[r]])}return t}const v={fallbackLocale:null,initialLocale:null,loadingDelay:200,formats:{number:{scientific:{notation:"scientific"},engineering:{notation:"engineering"},compactLong:{notation:"compact",compactDisplay:"long"},compactShort:{notation:"compact",compactDisplay:"short"}},date:{short:{month:"numeric",day:"numeric",year:"2-digit"},medium:{month:"short",day:"numeric",year:"numeric"},long:{month:"long",day:"numeric",year:"numeric"},full:{weekday:"long",month:"long",day:"numeric",year:"numeric"}},time:{short:{hour:"numeric",minute:"numeric"},medium:{hour:"numeric",minute:"numeric",second:"numeric"},long:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"},full:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"}}},warnOnMissingMessages:!0};function O(){return v}function j(e){const{formats:n}=e,t=y(e,["formats"]),o=e.initialLocale||e.fallbackLocale;return Object.assign(v,t,{initialLocale:o}),n&&("number"in n&&Object.assign(v.formats.number,n.number),"date"in n&&Object.assign(v.formats.date,n.date),"time"in n&&Object.assign(v.formats.time,n.time)),x.set(o)}const L=e(!1);let k;const x=e(null);function E(e,n){return 0===n.indexOf(e)&&e!==n}function D(e,n){return e===n||E(e,n)||E(n,e)}function I(e){const n=e.lastIndexOf("-");if(n>0)return e.slice(0,n);const{fallbackLocale:t}=O();return t&&!D(e,t)?t:null}function N(e){const n=e.split("-").map(((e,n,t)=>t.slice(0,n+1).join("-"))),{fallbackLocale:t}=O();return t&&!D(e,t)?n.concat(N(t)):n}function P(){return k}x.subscribe((e=>{k=e,"undefined"!=typeof window&&document.documentElement.setAttribute("lang",e)}));const S=x.set;x.set=e=>{if(s(e)&&w(e)){const{loadingDelay:n}=O();let t;return"undefined"!=typeof window&&null!=P()&&n?t=window.setTimeout((()=>L.set(!0)),n):L.set(!0),h(e).then((()=>{S(e)})).finally((()=>{clearTimeout(t),L.set(!1)}))}return S(e)},x.update=e=>S(e(k));const T=(e,n)=>{const t=e.split("&").find((e=>0===e.indexOf(n+"=")));return t?t.split("=").pop():null},$=(e,n)=>{const t=n.exec(e);return t&&t[1]||null},A=e=>"undefined"==typeof window?null:$(window.location.hostname,e),M=e=>"undefined"==typeof window?null:$(window.location.pathname,e),F=()=>"undefined"==typeof window?null:window.navigator.language||window.navigator.languages[0],z=e=>"undefined"==typeof window?null:T(window.location.search.substr(1),e),Z=e=>"undefined"==typeof window?null:T(window.location.hash.substr(1),e),C={},J=(e,n)=>{if(null==n)return null;const t=u(n,e);return t||J(e,I(n))},U=(e,n)=>{if(n in C&&e in C[n])return C[n][e];const t=J(e,n);return t?((e,n,t)=>t?(n in C||(C[n]={}),e in C[n]||(C[n][e]=t),t):t)(e,n,t):null},_=e=>{const n=Object.create(null);return t=>{const o=JSON.stringify(t);return o in n?n[o]:n[o]=e(t)}},q=(e,n)=>{const{formats:t}=O();if(e in t&&n in t[e])return t[e][n];throw new Error(`[svelte-i18n] Unknown "${n}" ${e} format.`)},B=_((e=>{var{locale:n,format:t}=e,o=y(e,["locale","format"]);if(null==n)throw new Error('[svelte-i18n] A "locale" must be set to format numbers');return t&&(o=q("number",t)),new Intl.NumberFormat(n,o)})),G=_((e=>{var{locale:n,format:t}=e,o=y(e,["locale","format"]);if(null==n)throw new Error('[svelte-i18n] A "locale" must be set to format dates');return t?o=q("date",t):0===Object.keys(o).length&&(o=q("date","short")),new Intl.DateTimeFormat(n,o)})),H=_((e=>{var{locale:n,format:t}=e,o=y(e,["locale","format"]);if(null==n)throw new Error('[svelte-i18n] A "locale" must be set to format time values');return t?o=q("time",t):0===Object.keys(o).length&&(o=q("time","short")),new Intl.DateTimeFormat(n,o)})),K=(e={})=>{var{locale:n=P()}=e,t=y(e,["locale"]);return B(Object.assign({locale:n},t))},Q=(e={})=>{var{locale:n=P()}=e,t=y(e,["locale"]);return G(Object.assign({locale:n},t))},R=(e={})=>{var{locale:n=P()}=e,t=y(e,["locale"]);return H(Object.assign({locale:n},t))},V=_(((e,n=P())=>new r(e,n,O().formats))),W=(e,n={})=>{"object"==typeof e&&(e=(n=e).id);const{values:t,locale:o=P(),default:r}=n;if(null==o)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");let i=U(e,o);return i||(O().warnOnMissingMessages&&console.warn(`[svelte-i18n] The message "${e}" was not found in "${N(o).join('", "')}".${w(P())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`),i=r||e),t?V(i,o).format(t):i},X=(e,n)=>R(n).format(e),Y=(e,n)=>Q(n).format(e),ee=(e,n)=>K(n).format(e),ne=n([x,a],(()=>W)),te=n([x],(()=>X)),oe=n([x],(()=>Y)),re=n([x],(()=>ee));function ie(e){return e}function ae(e){return h(e||P()||O().initialLocale)}export{ne as _,c as addMessages,oe as date,ie as defineMessages,a as dictionary,ne as format,Q as getDateFormatter,Z as getLocaleFromHash,A as getLocaleFromHostname,F as getLocaleFromNavigator,M as getLocaleFromPathname,z as getLocaleFromQueryString,V as getMessageFormatter,K as getNumberFormatter,R as getTimeFormatter,j as init,L as isLoading,x as locale,m as locales,re as number,b as register,ne as t,te as time,ae as waitLocale};
***************************************************************************** */function y(e,n){var t={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&n.indexOf(o)<0&&(t[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)n.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(t[o[r]]=e[o[r]])}return t}const v={fallbackLocale:null,initialLocale:null,loadingDelay:200,formats:{number:{scientific:{notation:"scientific"},engineering:{notation:"engineering"},compactLong:{notation:"compact",compactDisplay:"long"},compactShort:{notation:"compact",compactDisplay:"short"}},date:{short:{month:"numeric",day:"numeric",year:"2-digit"},medium:{month:"short",day:"numeric",year:"numeric"},long:{month:"long",day:"numeric",year:"numeric"},full:{weekday:"long",month:"long",day:"numeric",year:"numeric"}},time:{short:{hour:"numeric",minute:"numeric"},medium:{hour:"numeric",minute:"numeric",second:"numeric"},long:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"},full:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"}}},warnOnMissingMessages:!0};function O(){return v}function j(e){const{formats:n}=e,t=y(e,["formats"]),o=e.initialLocale||e.fallbackLocale;return Object.assign(v,t,{initialLocale:o}),n&&("number"in n&&Object.assign(v.formats.number,n.number),"date"in n&&Object.assign(v.formats.date,n.date),"time"in n&&Object.assign(v.formats.time,n.time)),x.set(o)}const L=e(!1);let k;const x=e(null);function $(e,n){return 0===n.indexOf(e)&&e!==n}function E(e,n){return e===n||$(e,n)||$(n,e)}function D(e){const n=e.lastIndexOf("-");if(n>0)return e.slice(0,n);const{fallbackLocale:t}=O();return t&&!E(e,t)?t:null}function I(e){const n=e.split("-").map(((e,n,t)=>t.slice(0,n+1).join("-"))),{fallbackLocale:t}=O();return t&&!E(e,t)?n.concat(I(t)):n}function M(){return k}x.subscribe((e=>{k=e,"undefined"!=typeof window&&document.documentElement.setAttribute("lang",e)}));const N=x.set;x.set=e=>{if(u(e)&&w(e)){const{loadingDelay:n}=O();let t;return"undefined"!=typeof window&&null!=M()&&n?t=window.setTimeout((()=>L.set(!0)),n):L.set(!0),p(e).then((()=>{N(e)})).finally((()=>{clearTimeout(t),L.set(!1)}))}return N(e)},x.update=e=>N(e(k));const P=(e,n)=>{const t=e.split("&").find((e=>0===e.indexOf(n+"=")));return t?t.split("=").pop():null},S=(e,n)=>{const t=n.exec(e);return t&&t[1]||null},T=e=>"undefined"==typeof window?null:S(window.location.hostname,e),A=e=>"undefined"==typeof window?null:S(window.location.pathname,e),F=()=>"undefined"==typeof window?null:window.navigator.language||window.navigator.languages[0],z=e=>"undefined"==typeof window?null:P(window.location.search.substr(1),e),Z=e=>"undefined"==typeof window?null:P(window.location.hash.substr(1),e),C={},G=(e,n)=>{if(null==n)return;const t=s(n,e);return t||G(e,D(n))},J=(e,n)=>{if(n in C&&e in C[n])return C[n][e];const t=G(e,n);return t?((e,n,t)=>t?(n in C||(C[n]={}),e in C[n]||(C[n][e]=t),t):t)(e,n,t):void 0},U=e=>{const n=Object.create(null);return t=>{const o=JSON.stringify(t);return o in n?n[o]:n[o]=e(t)}},_=(e,n)=>{const{formats:t}=O();if(e in t&&n in t[e])return t[e][n];throw new Error(`[svelte-i18n] Unknown "${n}" ${e} format.`)},q=U((e=>{var{locale:n,format:t}=e,o=y(e,["locale","format"]);if(null==n)throw new Error('[svelte-i18n] A "locale" must be set to format numbers');return t&&(o=_("number",t)),new Intl.NumberFormat(n,o)})),B=U((e=>{var{locale:n,format:t}=e,o=y(e,["locale","format"]);if(null==n)throw new Error('[svelte-i18n] A "locale" must be set to format dates');return t?o=_("date",t):0===Object.keys(o).length&&(o=_("date","short")),new Intl.DateTimeFormat(n,o)})),H=U((e=>{var{locale:n,format:t}=e,o=y(e,["locale","format"]);if(null==n)throw new Error('[svelte-i18n] A "locale" must be set to format time values');return t?o=_("time",t):0===Object.keys(o).length&&(o=_("time","short")),new Intl.DateTimeFormat(n,o)})),K=(e={})=>{var{locale:n=M()}=e,t=y(e,["locale"]);return q(Object.assign({locale:n},t))},Q=(e={})=>{var{locale:n=M()}=e,t=y(e,["locale"]);return B(Object.assign({locale:n},t))},R=(e={})=>{var{locale:n=M()}=e,t=y(e,["locale"]);return H(Object.assign({locale:n},t))},V=U(((e,n=M())=>new r(e,n,O().formats))),W=(e,n={})=>{"object"==typeof e&&(e=(n=e).id);const{values:t,locale:o=M(),default:r}=n;if(null==o)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");let i=J(e,o);if(i){if("string"!=typeof i)return console.warn(`[svelte-i18n] Message with id "${e}" must be of type "string", found: "${typeof i}". Gettin its value through the "$format" method is deprecated; use the "json" method instead.`),i}else O().warnOnMissingMessages&&console.warn(`[svelte-i18n] The message "${e}" was not found in "${I(o).join('", "')}".${w(M())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`),i=r||e;return t?V(i,o).format(t):i},X=(e,n)=>R(n).format(e),Y=(e,n)=>Q(n).format(e),ee=(e,n)=>K(n).format(e),ne=(e,n=M())=>J(e,n),te=n([x,a],(()=>W)),oe=n([x],(()=>X)),re=n([x],(()=>Y)),ie=n([x],(()=>ee)),ae=n([x,a],(()=>ne));function le(e){return e}function se(e){return p(e||M()||O().initialLocale)}export{te as _,c as addMessages,re as date,le as defineMessages,a as dictionary,te as format,Q as getDateFormatter,Z as getLocaleFromHash,T as getLocaleFromHostname,F as getLocaleFromNavigator,A as getLocaleFromPathname,z as getLocaleFromQueryString,V as getMessageFormatter,K as getNumberFormatter,R as getTimeFormatter,j as init,L as isLoading,ae as json,x as locale,m as locales,ie as number,b as register,te as t,oe as time,se as waitLocale};
{
"name": "svelte-i18n",
"version": "3.2.7",
"version": "3.3.0",
"main": "dist/runtime.cjs.js",

@@ -5,0 +5,0 @@ "module": "dist/runtime.esm.js",

@@ -1,2 +0,6 @@

export declare const lookupCache: Record<string, Record<string, string>>;
export declare const lookup: (path: string, locale: string) => string;
export declare const lookupCache: {
[locale: string]: {
[messageId: string]: any;
};
};
export declare const lookup: (path: string, locale: string) => any;
import { MessageObject } from './types';
import { $locale } from './stores/locale';
import { init } from './configs';
import { registerLocaleLoader } from './includes/loaderQueue';
import { getLocaleFromHostname, getLocaleFromPathname, getLocaleFromNavigator, getLocaleFromQueryString, getLocaleFromHash } from './includes/localeGetters';
import { $dictionary, $locales, addMessages } from './stores/dictionary';
import { $isLoading } from './stores/loading';
import { $format, $formatDate, $formatNumber, $formatTime, $getJSON } from './stores/formatters';
import { getDateFormatter, getNumberFormatter, getTimeFormatter, getMessageFormatter } from './includes/formatters';
export declare function defineMessages(i: Record<string, MessageObject>): Record<string, MessageObject>;
export declare function waitLocale(locale?: string): Promise<void>;
export { init } from './configs';
export { getLocaleFromHostname, getLocaleFromPathname, getLocaleFromNavigator, getLocaleFromQueryString, getLocaleFromHash, } from './includes/localeGetters';
export { $locale as locale } from './stores/locale';
export { $dictionary as dictionary, $locales as locales, addMessages, } from './stores/dictionary';
export { registerLocaleLoader as register } from './includes/loaderQueue';
export { $isLoading as isLoading } from './stores/loading';
export { $format as format, $format as _, $format as t, $formatDate as date, $formatNumber as number, $formatTime as time, } from './stores/formatters';
export { getDateFormatter, getNumberFormatter, getTimeFormatter, getMessageFormatter, } from './includes/formatters';
export { init, addMessages, registerLocaleLoader as register, $locale as locale, $dictionary as dictionary, $locales as locales, $isLoading as isLoading, $format as format, $format as _, $format as t, $formatDate as date, $formatNumber as number, $formatTime as time, $getJSON as json, getDateFormatter, getNumberFormatter, getTimeFormatter, getMessageFormatter, getLocaleFromHostname, getLocaleFromPathname, getLocaleFromNavigator, getLocaleFromQueryString, getLocaleFromHash, };

@@ -1,2 +0,2 @@

import { MessageFormatter, TimeFormatter, DateFormatter, NumberFormatter } from '../types';
import { MessageFormatter, TimeFormatter, DateFormatter, NumberFormatter, JSONGetter } from '../types';
export declare const $format: import("svelte/store").Readable<MessageFormatter>;

@@ -6,1 +6,2 @@ export declare const $formatTime: import("svelte/store").Readable<TimeFormatter>;

export declare const $formatNumber: import("svelte/store").Readable<NumberFormatter>;
export declare const $getJSON: import("svelte/store").Readable<JSONGetter>;

@@ -20,2 +20,3 @@ import type { FormatXMLElementFn, Formats } from 'intl-messageformat';

export declare type NumberFormatter = (d: number, options?: IntlFormatterOptions<Intl.NumberFormatOptions>) => string;
export declare type JSONGetter = <T extends any>(id: string, locale?: string) => T;
declare type IntlFormatterOptions<T> = T & {

@@ -22,0 +23,0 @@ format?: string;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc