Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svelte-i18n

Package Overview
Dependencies
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-i18n - npm Package Compare versions

Comparing version 3.3.7 to 3.3.8

9

CHANGELOG.md

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

## [3.3.8](https://github.com/kaisermann/svelte-i18n/compare/v3.3.7...v3.3.8) (2021-03-27)
### Bug Fixes
* 🐛 support more specific fallback locale (i.e en-GB vs en) ([5db1dbc](https://github.com/kaisermann/svelte-i18n/commit/5db1dbc3a40f9a19585f63dbacd42846e599d927)), closes [#137](https://github.com/kaisermann/svelte-i18n/issues/137)
## [3.3.7](https://github.com/kaisermann/svelte-i18n/compare/v3.3.6...v3.3.7) (2021-03-17)

@@ -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("intl-messageformat");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=r(t),i=r(n);const a={},l=(e,t)=>{if(null==t)return;const n=function(e,t){if(!m(e))return null;const n=function(e){return u[e]||null}(e);return function(e,t){if(t in e)return e[t];const n=t.split(".");let r=e;for(let e=0;e<n.length;e++)if("object"==typeof r){if(e>0){const t=n.slice(e,n.length).join(".");if(t in r){r=r[t];break}}r=r[n[e]]}else r=void 0;return r}(n,t)}(t,e);return n||l(e,T(t))},s=(e,t)=>{if(t in a&&e in a[t])return a[t][e];const n=l(e,t);return n?((e,t,n)=>n?(t in a||(a[t]={}),e in a[t]||(a[t][e]=n),n):n)(e,t,n):void 0};let u;const c=e.writable({});function m(e){return e in u}function f(e){return null==e||m(e)?e:f(T(e))}function d(e,...t){delete a[e],c.update((n=>(n[e]=o.default.all([n[e]||{},...t]),n)))}const g=e.derived([c],(([e])=>Object.keys(e)));c.subscribe((e=>u=e));const p={};function w(e){return p[e]}function h(e){return D(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){p[e].delete(t),0===p[e].size&&delete p[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 D(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]}
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("svelte/store"),t=require("deepmerge"),n=require("intl-messageformat");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=r(t),i=r(n);const a={},l=(e,t,n)=>n?(t in a||(a[t]={}),e in a[t]||(a[t][e]=n),n):n,s=(e,t)=>{if(null==t)return;if(t in a&&e in a[t])return a[t][e];const n=k(t);for(let r=0;r<n.length;r++){const o=f(n[r],e);if(o)return l(e,t,o)}};let u;const c=e.writable({});function m(e){return e in u}function f(e,t){if(!m(e))return null;return function(e,t){if(t in e)return e[t];const n=t.split(".");let r=e;for(let e=0;e<n.length;e++)if("object"==typeof r){if(e>0){const t=n.slice(e,n.length).join(".");if(t in r){r=r[t];break}}r=r[n[e]]}else r=void 0;return r}(function(e){return u[e]||null}(e),t)}function d(e,...t){delete a[e],c.update((n=>(n[e]=o.default.all([n[e]||{},...t]),n)))}const g=e.derived([c],(([e])=>Object.keys(e)));c.subscribe((e=>u=e));const p={};function w(e){return p[e]}function h(e){return k(e).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){p[e].delete(t),0===p[e].size&&delete p[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 k(e).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,ignoreTag:!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 T(e){const t=e.lastIndexOf("-");if(t>0)return e.slice(0,t);const{fallbackLocale:n}=j();return n&&!$(e,n)?n:null}function D(e){const t=e.split("-").map(((e,t,n)=>n.slice(0,t+1).join("-"))),{fallbackLocale:n}=j();return n&&!$(e,n)?t.concat(D(n)):t}function E(){return F}k.subscribe((e=>{F=e,"undefined"!=typeof window&&document.documentElement.setAttribute("lang",e)}));const N=k.set;k.set=e=>{if(f(e)&&h(e)){const{loadingDelay:t}=j();let n;return"undefined"!=typeof window&&null!=E()&&t?n=window.setTimeout((()=>L.set(!0)),t):L.set(!0),v(e).then((()=>{N(e)})).finally((()=>{clearTimeout(n),L.set(!1)}))}return N(e)},k.update=e=>N(e(F));const P=(e,t)=>{const n=e.split("&").find((e=>0===e.indexOf(`${t}=`)));return n?n.split("=").pop():null},S=(e,t)=>{const n=t.exec(e);return n&&n[1]||null},I=e=>{const t=Object.create(null);return n=>{const r=JSON.stringify(n);return r in t?t[r]:t[r]=e(n)}},A=(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.`)},q=I((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=A("number",n)),new Intl.NumberFormat(t,r)})),_=I((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=A("date",n):0===Object.keys(r).length&&(r=A("date","short")),new Intl.DateTimeFormat(t,r)})),z=I((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=A("time",n):0===Object.keys(r).length&&(r=A("time","short")),new Intl.DateTimeFormat(t,r)})),H=(e={})=>{var{locale:t=E()}=e,n=x(e,["locale"]);return q(Object.assign({locale:t},n))},Z=(e={})=>{var{locale:t=E()}=e,n=x(e,["locale"]);return _(Object.assign({locale:t},n))},C=(e={})=>{var{locale:t=E()}=e,n=x(e,["locale"]);return z(Object.assign({locale:t},n))},G=I(((e,t=E())=>new i.default(e,t,j().formats,{ignoreTag:j().ignoreTag}))),J=(e,t={})=>{"object"==typeof e&&(e=(t=e).id);const{values:n,locale:r=E(),default:o}=t;if(null==r)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");let i=s(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 "${D(r).join('", "')}".${h(E())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`),i=o||e;if(!n)return i;let a=i;try{a=G(i,r).format(n)}catch(t){console.warn(`[svelte-i18n] Message "${e}" has syntax error:`,t.message)}return a},Q=(e,t)=>C(t).format(e),U=(e,t)=>Z(t).format(e),B=(e,t)=>H(t).format(e),K=(e,t=E())=>s(e,t),R=e.derived([k,c],(()=>J)),V=e.derived([k],(()=>Q)),W=e.derived([k],(()=>U)),X=e.derived([k],(()=>B)),Y=e.derived([k,c],(()=>K));exports._=R,exports.addMessages=d,exports.date=W,exports.defineMessages=function(e){return e},exports.dictionary=c,exports.format=R,exports.getDateFormatter=Z,exports.getLocaleFromHash=e=>"undefined"==typeof window?null:P(window.location.hash.substr(1),e),exports.getLocaleFromHostname=e=>"undefined"==typeof window?null:S(window.location.hostname,e),exports.getLocaleFromNavigator=()=>"undefined"==typeof window?null:window.navigator.language||window.navigator.languages[0],exports.getLocaleFromPathname=e=>"undefined"==typeof window?null:S(window.location.pathname,e),exports.getLocaleFromQueryString=e=>"undefined"==typeof window?null:P(window.location.search.substr(1),e),exports.getMessageFormatter=G,exports.getNumberFormatter=H,exports.getTimeFormatter=C,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=Y,exports.locale=k,exports.locales=g,exports.number=X,exports.register=function(e,t){w(e)||function(e){p[e]=new Set}(e);const n=w(e);w(e).has(t)||(m(e)||c.update((t=>(t[e]={},t))),n.add(t))},exports.t=R,exports.time=V,exports.waitLocale=function(e){return v(e||E()||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,ignoreTag:!0};function j(){return O}const L=e.writable(!1);let F;const M=e.writable(null);function $(e){return e.split("-").map(((e,t,n)=>n.slice(0,t+1).join("-"))).reverse()}function k(e,t=j().fallbackLocale){const n=$(e);return t?[...new Set([...n,...$(t)])]:n}function T(){return F}M.subscribe((e=>{F=e,"undefined"!=typeof window&&document.documentElement.setAttribute("lang",e)}));const D=M.set;M.set=e=>{if(function(e){if(null==e)return;const t=k(e);for(let e=0;e<t.length;e++){const n=t[e];if(m(n))return n}}(e)&&h(e)){const{loadingDelay:t}=j();let n;return"undefined"!=typeof window&&null!=T()&&t?n=window.setTimeout((()=>L.set(!0)),t):L.set(!0),v(e).then((()=>{D(e)})).finally((()=>{clearTimeout(n),L.set(!1)}))}return D(e)},M.update=e=>D(e(F));const E=(e,t)=>{const n=e.split("&").find((e=>0===e.indexOf(`${t}=`)));return n?n.split("=").pop():null},N=(e,t)=>{const n=t.exec(e);return n&&n[1]||null},P=e=>{const t=Object.create(null);return n=>{const r=JSON.stringify(n);return r in t?t[r]:t[r]=e(n)}},S=(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.`)},A=P((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=S("number",n)),new Intl.NumberFormat(t,r)})),I=P((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=S("date",n):0===Object.keys(r).length&&(r=S("date","short")),new Intl.DateTimeFormat(t,r)})),q=P((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=S("time",n):0===Object.keys(r).length&&(r=S("time","short")),new Intl.DateTimeFormat(t,r)})),_=(e={})=>{var{locale:t=T()}=e,n=x(e,["locale"]);return A(Object.assign({locale:t},n))},z=(e={})=>{var{locale:t=T()}=e,n=x(e,["locale"]);return I(Object.assign({locale:t},n))},H=(e={})=>{var{locale:t=T()}=e,n=x(e,["locale"]);return q(Object.assign({locale:t},n))},Z=P(((e,t=T())=>new i.default(e,t,j().formats,{ignoreTag:j().ignoreTag}))),C=(e,t={})=>{"object"==typeof e&&(e=(t=e).id);const{values:n,locale:r=T(),default:o}=t;if(null==r)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");let i=s(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 "${k(r).join('", "')}".${h(T())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`),i=o||e;if(!n)return i;let a=i;try{a=Z(i,r).format(n)}catch(t){console.warn(`[svelte-i18n] Message "${e}" has syntax error:`,t.message)}return a},G=(e,t)=>H(t).format(e),J=(e,t)=>z(t).format(e),Q=(e,t)=>_(t).format(e),U=(e,t=T())=>s(e,t),B=e.derived([M,c],(()=>C)),K=e.derived([M],(()=>G)),R=e.derived([M],(()=>J)),V=e.derived([M],(()=>Q)),W=e.derived([M,c],(()=>U));exports._=B,exports.addMessages=d,exports.date=R,exports.defineMessages=function(e){return e},exports.dictionary=c,exports.format=B,exports.getDateFormatter=z,exports.getLocaleFromHash=e=>"undefined"==typeof window?null:E(window.location.hash.substr(1),e),exports.getLocaleFromHostname=e=>"undefined"==typeof window?null:N(window.location.hostname,e),exports.getLocaleFromNavigator=()=>"undefined"==typeof window?null:window.navigator.language||window.navigator.languages[0],exports.getLocaleFromPathname=e=>"undefined"==typeof window?null:N(window.location.pathname,e),exports.getLocaleFromQueryString=e=>"undefined"==typeof window?null:E(window.location.search.substr(1),e),exports.getMessageFormatter=Z,exports.getNumberFormatter=_,exports.getTimeFormatter=H,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)),M.set(r)},exports.isLoading=L,exports.json=W,exports.locale=M,exports.locales=g,exports.number=V,exports.register=function(e,t){w(e)||function(e){p[e]=new Set}(e);const n=w(e);w(e).has(t)||(m(e)||c.update((t=>(t[e]={},t))),n.add(t))},exports.t=B,exports.time=K,exports.waitLocale=function(e){return v(e||T()||j().initialLocale)};

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

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

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

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function v(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 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,ignoreTag:!0};function j(){return O}function k(e){const{formats:n}=e,t=v(e,["formats"]),o=e.initialLocale||e.fallbackLocale;return Object.assign(O,t,{initialLocale:o}),n&&("number"in n&&Object.assign(O.formats.number,n.number),"date"in n&&Object.assign(O.formats.date,n.date),"time"in n&&Object.assign(O.formats.time,n.time)),x.set(o)}const L=e(!1);let $;const x=e(null);function T(e,n){return 0===n.indexOf(e)&&e!==n}function E(e,n){return e===n||T(e,n)||T(n,e)}function D(e){const n=e.lastIndexOf("-");if(n>0)return e.slice(0,n);const{fallbackLocale:t}=j();return t&&!E(e,t)?t:null}function M(e){const n=e.split("-").map(((e,n,t)=>t.slice(0,n+1).join("-"))),{fallbackLocale:t}=j();return t&&!E(e,t)?n.concat(M(t)):n}function I(){return $}x.subscribe((e=>{$=e,"undefined"!=typeof window&&document.documentElement.setAttribute("lang",e)}));const N=x.set;x.set=e=>{if(u(e)&&w(e)){const{loadingDelay:n}=j();let t;return"undefined"!=typeof window&&null!=I()&&n?t=window.setTimeout((()=>L.set(!0)),n):L.set(!0),b(e).then((()=>{N(e)})).finally((()=>{clearTimeout(t),L.set(!1)}))}return N(e)},x.update=e=>N(e($));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},A=e=>"undefined"==typeof window?null:S(window.location.hostname,e),F=e=>"undefined"==typeof window?null:S(window.location.pathname,e),z=()=>"undefined"==typeof window?null:window.navigator.language||window.navigator.languages[0],Z=e=>"undefined"==typeof window?null:P(window.location.search.substr(1),e),C=e=>"undefined"==typeof window?null:P(window.location.hash.substr(1),e),G=e=>{const n=Object.create(null);return t=>{const o=JSON.stringify(t);return o in n?n[o]:n[o]=e(t)}},J=(e,n)=>{const{formats:t}=j();if(e in t&&n in t[e])return t[e][n];throw new Error(`[svelte-i18n] Unknown "${n}" ${e} format.`)},U=G((e=>{var{locale:n,format:t}=e,o=v(e,["locale","format"]);if(null==n)throw new Error('[svelte-i18n] A "locale" must be set to format numbers');return t&&(o=J("number",t)),new Intl.NumberFormat(n,o)})),_=G((e=>{var{locale:n,format:t}=e,o=v(e,["locale","format"]);if(null==n)throw new Error('[svelte-i18n] A "locale" must be set to format dates');return t?o=J("date",t):0===Object.keys(o).length&&(o=J("date","short")),new Intl.DateTimeFormat(n,o)})),q=G((e=>{var{locale:n,format:t}=e,o=v(e,["locale","format"]);if(null==n)throw new Error('[svelte-i18n] A "locale" must be set to format time values');return t?o=J("time",t):0===Object.keys(o).length&&(o=J("time","short")),new Intl.DateTimeFormat(n,o)})),B=(e={})=>{var{locale:n=I()}=e,t=v(e,["locale"]);return U(Object.assign({locale:n},t))},H=(e={})=>{var{locale:n=I()}=e,t=v(e,["locale"]);return _(Object.assign({locale:n},t))},K=(e={})=>{var{locale:n=I()}=e,t=v(e,["locale"]);return q(Object.assign({locale:n},t))},Q=G(((e,n=I())=>new o(e,n,j().formats,{ignoreTag:j().ignoreTag}))),R=(e,n={})=>{"object"==typeof e&&(e=(n=e).id);const{values:t,locale:o=I(),default:r}=n;if(null==o)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");let i=a(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 j().warnOnMissingMessages&&console.warn(`[svelte-i18n] The message "${e}" was not found in "${M(o).join('", "')}".${w(I())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`),i=r||e;if(!t)return i;let l=i;try{l=Q(i,o).format(t)}catch(n){console.warn(`[svelte-i18n] Message "${e}" has syntax error:`,n.message)}return l},V=(e,n)=>K(n).format(e),W=(e,n)=>H(n).format(e),X=(e,n)=>B(n).format(e),Y=(e,n=I())=>a(e,n),ee=n([x,s],(()=>R)),ne=n([x],(()=>V)),te=n([x],(()=>W)),oe=n([x],(()=>X)),re=n([x,s],(()=>Y));function ie(e){return e}function ae(e){return b(e||I()||j().initialLocale)}export{ee as _,m as addMessages,te as date,ie as defineMessages,s as dictionary,ee as format,H as getDateFormatter,C as getLocaleFromHash,A as getLocaleFromHostname,z as getLocaleFromNavigator,F as getLocaleFromPathname,Z as getLocaleFromQueryString,Q as getMessageFormatter,B as getNumberFormatter,K as getTimeFormatter,k as init,L as isLoading,re as json,x as locale,f as locales,oe as number,y as register,ee as t,ne as time,ae as waitLocale};
***************************************************************************** */function v(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}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,ignoreTag:!0};function j(){return O}function $(e){const{formats:t}=e,n=v(e,["formats"]),o=e.initialLocale||e.fallbackLocale;return Object.assign(O,n,{initialLocale:o}),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)),T.set(o)}const k=e(!1);let L;const T=e(null);function x(e){return e.split("-").map(((e,t,n)=>n.slice(0,t+1).join("-"))).reverse()}function E(e,t=j().fallbackLocale){const n=x(e);return t?[...new Set([...n,...x(t)])]:n}function D(){return L}T.subscribe((e=>{L=e,"undefined"!=typeof window&&document.documentElement.setAttribute("lang",e)}));const M=T.set;T.set=e=>{if(function(e){if(null==e)return;const t=E(e);for(let e=0;e<t.length;e++){const n=t[e];if(u(n))return n}}(e)&&w(e)){const{loadingDelay:t}=j();let n;return"undefined"!=typeof window&&null!=D()&&t?n=window.setTimeout((()=>k.set(!0)),t):k.set(!0),b(e).then((()=>{M(e)})).finally((()=>{clearTimeout(n),k.set(!1)}))}return M(e)},T.update=e=>M(e(L));const S=(e,t)=>{const n=e.split("&").find((e=>0===e.indexOf(`${t}=`)));return n?n.split("=").pop():null},N=(e,t)=>{const n=t.exec(e);return n&&n[1]||null},P=e=>"undefined"==typeof window?null:N(window.location.hostname,e),A=e=>"undefined"==typeof window?null:N(window.location.pathname,e),I=()=>"undefined"==typeof window?null:window.navigator.language||window.navigator.languages[0],F=e=>"undefined"==typeof window?null:S(window.location.search.substr(1),e),z=e=>"undefined"==typeof window?null:S(window.location.hash.substr(1),e),Z=e=>{const t=Object.create(null);return n=>{const o=JSON.stringify(n);return o in t?t[o]:t[o]=e(n)}},C=(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.`)},G=Z((e=>{var{locale:t,format:n}=e,o=v(e,["locale","format"]);if(null==t)throw new Error('[svelte-i18n] A "locale" must be set to format numbers');return n&&(o=C("number",n)),new Intl.NumberFormat(t,o)})),J=Z((e=>{var{locale:t,format:n}=e,o=v(e,["locale","format"]);if(null==t)throw new Error('[svelte-i18n] A "locale" must be set to format dates');return n?o=C("date",n):0===Object.keys(o).length&&(o=C("date","short")),new Intl.DateTimeFormat(t,o)})),U=Z((e=>{var{locale:t,format:n}=e,o=v(e,["locale","format"]);if(null==t)throw new Error('[svelte-i18n] A "locale" must be set to format time values');return n?o=C("time",n):0===Object.keys(o).length&&(o=C("time","short")),new Intl.DateTimeFormat(t,o)})),_=(e={})=>{var{locale:t=D()}=e,n=v(e,["locale"]);return G(Object.assign({locale:t},n))},q=(e={})=>{var{locale:t=D()}=e,n=v(e,["locale"]);return J(Object.assign({locale:t},n))},B=(e={})=>{var{locale:t=D()}=e,n=v(e,["locale"]);return U(Object.assign({locale:t},n))},H=Z(((e,t=D())=>new o(e,t,j().formats,{ignoreTag:j().ignoreTag}))),K=(e,t={})=>{"object"==typeof e&&(e=(t=e).id);const{values:n,locale:o=D(),default:r}=t;if(null==o)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");let i=a(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 j().warnOnMissingMessages&&console.warn(`[svelte-i18n] The message "${e}" was not found in "${E(o).join('", "')}".${w(D())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`),i=r||e;if(!n)return i;let l=i;try{l=H(i,o).format(n)}catch(t){console.warn(`[svelte-i18n] Message "${e}" has syntax error:`,t.message)}return l},Q=(e,t)=>B(t).format(e),R=(e,t)=>q(t).format(e),V=(e,t)=>_(t).format(e),W=(e,t=D())=>a(e,t),X=t([T,s],(()=>K)),Y=t([T],(()=>Q)),ee=t([T],(()=>R)),te=t([T],(()=>V)),ne=t([T,s],(()=>W));function oe(e){return e}function re(e){return b(e||D()||j().initialLocale)}export{X as _,m as addMessages,ee as date,oe as defineMessages,s as dictionary,X as format,q as getDateFormatter,z as getLocaleFromHash,P as getLocaleFromHostname,I as getLocaleFromNavigator,A as getLocaleFromPathname,F as getLocaleFromQueryString,H as getMessageFormatter,_ as getNumberFormatter,B as getTimeFormatter,$ as init,k as isLoading,ne as json,T as locale,f as locales,te as number,y as register,X as t,Y as time,re as waitLocale};
{
"name": "svelte-i18n",
"version": "3.3.7",
"version": "3.3.8",
"main": "dist/runtime.cjs.js",

@@ -81,2 +81,3 @@ "module": "dist/runtime.esm.js",

"@types/jest": "^26.0.14",
"@types/node": "^14.14.35",
"@types/sade": "^1.7.2",

@@ -83,0 +84,0 @@ "babel-core": "^7.0.0-bridge.0",

@@ -6,2 +6,2 @@ export declare const lookupCache: {

};
export declare const lookup: (path: string, locale: string) => any;
export declare const lookup: (path: string, refLocale: string) => any;

@@ -7,5 +7,5 @@ import type { LocaleDictionary, LocalesDictionary } from '../types/index';

export declare function getMessageFromDictionary(locale: string, id: string): any;
export declare function getClosestAvailableLocale(locale: string): string | null;
export declare function getClosestAvailableLocale(refLocale: string): string | null;
export declare function addMessages(locale: string, ...partials: LocaleDictionary[]): void;
declare const $locales: import("svelte/store").Readable<string[]>;
export { $dictionary, $locales };
declare const $locale: import("svelte/store").Writable<any>;
export declare function isFallbackLocaleOf(localeA: string, localeB: string): boolean;
export declare function isRelatedLocale(localeA: string, localeB: string): boolean;
export declare function getFallbackOf(locale: string): string;
export declare function getRelatedLocalesOf(locale: string): string[];
export declare function getPossibleLocales(refLocale: string, fallbackLocale?: string): string[];
export declare function getCurrentLocale(): string;
export { $locale };
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc