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.0.2 to 3.0.3

9

CHANGELOG.md

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

## [3.0.3](https://github.com/kaisermann/svelte-i18n/compare/v3.0.2...v3.0.3) (2020-03-29)
### Bug Fixes
* 🐛 prevent server from breaking on locale.set ([07ef1da](https://github.com/kaisermann/svelte-i18n/commit/07ef1da6d5177854b4707d5f038f5a14562e6bf5)), closes [#55](https://github.com/kaisermann/svelte-i18n/issues/55)
## [3.0.2](https://github.com/kaisermann/svelte-i18n/compare/v3.0.1...v3.0.2) (2020-03-06)

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

2

dist/runtime.cjs.js

@@ -16,2 +16,2 @@ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("svelte/store"),n=(e=require("intl-messageformat"))&&"object"==typeof e&&"default"in e?e.default:e;const o=(e,t="")=>{const n={};for(const r in e){const i=t+r;"object"==typeof e[r]?Object.assign(n,o(e[r],`${i}.`)):n[i]=e[r]}return n};let r;const i=t.writable({});function a(e){return e in r}function l(e,t){if(a(e)){const n=function(e){return r[e]||null}(e);if(t in n)return n[t]}return null}function s(e,...t){const n=t.map(e=>o(e));i.update(t=>(t[e]=Object.assign(t[e]||{},...n),t))}const c=t.derived([i],([e])=>Object.keys(e));i.subscribe(e=>r=e);const u={};function m(e){return u[e]}function f(e){return L(e).reverse().some(m)}const d={};function p(e){if(!f(e))return;if(e in d)return d[e];const t=function(e){return L(e).reverse().map(e=>{const t=m(e);return[e,t?[...t]:[]]}).filter(([,e])=>e.length>0)}(e);return 0!==t.length?(d[e]=Promise.all(t.map(([e,t])=>Promise.all(t.map(e=>e())).then(t=>{!function(e){delete u[e]}(e),t=t.map(e=>e.default||e),s(e,...t)}))).then(()=>{delete d[e]}),d[e]):void 0}

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

@@ -15,2 +15,2 @@ import{writable as n,derived as e}from"svelte/store";import t from"intl-messageformat";const o=(n,e="")=>{const t={};for(const r in n){const i=e+r;"object"==typeof n[r]?Object.assign(t,o(n[r],`${i}.`)):t[i]=n[r]}return t};let r;const i=n({});function a(n){return n in r}function l(n,e){if(a(n)){const t=function(n){return r[n]||null}(n);if(e in t)return t[e]}return null}function s(n,...e){const t=e.map(n=>o(n));i.update(e=>(e[n]=Object.assign(e[n]||{},...t),e))}const c=e([i],([n])=>Object.keys(n));i.subscribe(n=>r=n);const u={};function m(n){return u[n]}function f(n){return E(n).reverse().some(m)}const d={};function w(n){if(!f(n))return;if(n in d)return d[n];const e=function(n){return E(n).reverse().map(n=>{const e=m(n);return[n,e?[...e]:[]]}).filter(([,n])=>n.length>0)}(n);return 0!==e.length?(d[n]=Promise.all(e.map(([n,e])=>Promise.all(e.map(n=>n())).then(e=>{!function(n){delete u[n]}(n),e=e.map(n=>n.default||n),s(n,...e)}))).then(()=>{delete d[n]}),d[n]):void 0}function g(n,e){m(n)||function(n){u[n]=new Set}(n);const t=m(n);m(n).has(e)||(a(n)||i.update(e=>(e[n]={},e)),t.add(e))}

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