Socket
Socket
Sign inDemoInstall

svelte-i18n

Package Overview
Dependencies
Maintainers
1
Versions
79
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.8 to 3.3.9

9

CHANGELOG.md

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

## [3.3.9](https://github.com/kaisermann/svelte-i18n/compare/v3.3.8...v3.3.9) (2021-03-27)
### Bug Fixes
* 🐛 only set lang attr if lang is not nullish ([1c516c9](https://github.com/kaisermann/svelte-i18n/commit/1c516c9cda45e5a25dd466947804a5cc94734d22)), closes [#133](https://github.com/kaisermann/svelte-i18n/issues/133)
## [3.3.8](https://github.com/kaisermann/svelte-i18n/compare/v3.3.7...v3.3.8) (2021-03-27)

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

2

dist/runtime.cjs.js

@@ -16,2 +16,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,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]}

***************************************************************************** */
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)};
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&&null!==e&&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 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))}
import{writable as e,derived as n}from"svelte/store";import t from"deepmerge";import o from"intl-messageformat";const r={},i=(e,n,t)=>t?(n in r||(r[n]={}),e in r[n]||(r[n][e]=t),t):t,a=(e,n)=>{if(null==n)return;if(n in r&&e in r[n])return r[n][e];const t=E(n);for(let o=0;o<t.length;o++){const r=c(t[o],e);if(r)return i(e,n,r)}};let l;const s=e({});function u(e){return e in l}function c(e,n){if(!u(e))return null;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}(function(e){return l[e]||null}(e),n)}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 E(e).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 E(e).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)||(u(e)||s.update((n=>(n[e]={},n))),t.add(n))}
/*! *****************************************************************************

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

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */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};
***************************************************************************** */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 $(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)),T.set(o)}const k=e(!1);let L;const T=e(null);function x(e){return e.split("-").map(((e,n,t)=>t.slice(0,n+1).join("-"))).reverse()}function E(e,n=j().fallbackLocale){const t=x(e);return n?[...new Set([...t,...x(n)])]:t}function D(){return L}T.subscribe((e=>{L=e,"undefined"!=typeof window&&null!==e&&document.documentElement.setAttribute("lang",e)}));const M=T.set;T.set=e=>{if(function(e){if(null==e)return;const n=E(e);for(let e=0;e<n.length;e++){const t=n[e];if(u(t))return t}}(e)&&w(e)){const{loadingDelay:n}=j();let t;return"undefined"!=typeof window&&null!=D()&&n?t=window.setTimeout((()=>k.set(!0)),n):k.set(!0),b(e).then((()=>{M(e)})).finally((()=>{clearTimeout(t),k.set(!1)}))}return M(e)},T.update=e=>M(e(L));const S=(e,n)=>{const t=e.split("&").find((e=>0===e.indexOf(`${n}=`)));return t?t.split("=").pop():null},N=(e,n)=>{const t=n.exec(e);return t&&t[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 n=Object.create(null);return t=>{const o=JSON.stringify(t);return o in n?n[o]:n[o]=e(t)}},C=(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.`)},G=Z((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=C("number",t)),new Intl.NumberFormat(n,o)})),J=Z((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=C("date",t):0===Object.keys(o).length&&(o=C("date","short")),new Intl.DateTimeFormat(n,o)})),U=Z((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=C("time",t):0===Object.keys(o).length&&(o=C("time","short")),new Intl.DateTimeFormat(n,o)})),_=(e={})=>{var{locale:n=D()}=e,t=v(e,["locale"]);return G(Object.assign({locale:n},t))},q=(e={})=>{var{locale:n=D()}=e,t=v(e,["locale"]);return J(Object.assign({locale:n},t))},B=(e={})=>{var{locale:n=D()}=e,t=v(e,["locale"]);return U(Object.assign({locale:n},t))},H=Z(((e,n=D())=>new o(e,n,j().formats,{ignoreTag:j().ignoreTag}))),K=(e,n={})=>{"object"==typeof e&&(e=(n=e).id);const{values:t,locale:o=D(),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 "${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(!t)return i;let l=i;try{l=H(i,o).format(t)}catch(n){console.warn(`[svelte-i18n] Message "${e}" has syntax error:`,n.message)}return l},Q=(e,n)=>B(n).format(e),R=(e,n)=>q(n).format(e),V=(e,n)=>_(n).format(e),W=(e,n=D())=>a(e,n),X=n([T,s],(()=>K)),Y=n([T],(()=>Q)),ee=n([T],(()=>R)),ne=n([T],(()=>V)),te=n([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,te as json,T as locale,f as locales,ne as number,y as register,X as t,Y as time,re as waitLocale};
{
"name": "svelte-i18n",
"version": "3.3.8",
"version": "3.3.9",
"main": "dist/runtime.cjs.js",

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

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