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.4.1 to 3.5.0-alpha.0

2

dist/runtime.cjs.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("svelte/store"),t=require("deepmerge"),n=require("intl-messageformat");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=o(t),i=o(n);const s={},l=(e,t,n)=>n?(t in s||(s[t]={}),e in s[t]||(s[t][e]=n),n):n,a=(e,t)=>{if(null==t)return;if(t in s&&e in s[t])return s[t][e];const n=$(t);for(let o=0;o<n.length;o++){const r=d(n[o],e);if(r)return l(e,t,r)}};let u;const c=e.writable({});function m(e){return e in u}function d(e,t){if(!m(e))return null;const n=function(e){return u[e]||null}(e);return function(e,t){if(null==t)return;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}(n,t)}function f(e,...t){delete s[e],c.update((n=>(n[e]=r.default.all([n[e]||{},...t]),n)))}const g=e.derived([c],(([e])=>Object.keys(e)));c.subscribe((e=>u=e));const p={};function h(e){return p[e]}function w(e){return null!=e&&$(e).some((e=>{var t;return null===(t=h(e))||void 0===t?void 0:t.size}))}function b(e,t){const n=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))))));return n.then((t=>f(e,...t)))}const v={};function y(e){if(!w(e))return e in v?v[e]:Promise.resolve();const t=function(e){return $(e).map((e=>{const t=h(e);return[e,t?[...t]:[]]})).filter((([,e])=>e.length>0))}(e);return v[e]=Promise.all(t.map((([e,t])=>b(e,t)))).then((()=>{if(w(e))return y(e);delete v[e]})),v[e]}function x({locale:e,id:t}){console.warn(`[svelte-i18n] The message "${t}" was not found in "${$(e).join('", "')}".${w(k())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`)}const M={fallbackLocale: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,handleMissingMessage:void 0,ignoreTag:!0};function j(){return M}const O=e.writable(!1);let L;const F=e.writable(null);function T(e){return e.split("-").map(((e,t,n)=>n.slice(0,t+1).join("-"))).reverse()}function $(e,t=j().fallbackLocale){const n=T(e);return t?[...new Set([...n,...T(t)])]:n}function k(){return null!=L?L:void 0}F.subscribe((e=>{L=null!=e?e:void 0,"undefined"!=typeof window&&null!=e&&document.documentElement.setAttribute("lang",e)}));const D={...F,set:e=>{if(e&&function(e){if(null==e)return;const t=$(e);for(let e=0;e<t.length;e++){const n=t[e];if(m(n))return n}}(e)&&w(e)){const{loadingDelay:t}=j();let n;return"undefined"!=typeof window&&null!=k()&&t?n=window.setTimeout((()=>O.set(!0)),t):O.set(!0),y(e).then((()=>{F.set(e)})).finally((()=>{clearTimeout(n),O.set(!1)}))}return F.set(e)}},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 o=JSON.stringify(n);return o in t?t[o]:t[o]=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((({locale:e,format:t,...n})=>{if(null==e)throw new Error('[svelte-i18n] A "locale" must be set to format numbers');return t&&(n=S("number",t)),new Intl.NumberFormat(e,n)})),q=P((({locale:e,format:t,...n})=>{if(null==e)throw new Error('[svelte-i18n] A "locale" must be set to format dates');return t?n=S("date",t):0===Object.keys(n).length&&(n=S("date","short")),new Intl.DateTimeFormat(e,n)})),I=P((({locale:e,format:t,...n})=>{if(null==e)throw new Error('[svelte-i18n] A "locale" must be set to format time values');return t?n=S("time",t):0===Object.keys(n).length&&(n=S("time","short")),new Intl.DateTimeFormat(e,n)})),_=({locale:e=k(),...t}={})=>A({locale:e,...t}),z=({locale:e=k(),...t}={})=>q({locale:e,...t}),H=({locale:e=k(),...t}={})=>I({locale:e,...t}),Z=P(((e,t=k())=>new i.default(e,t,j().formats,{ignoreTag:j().ignoreTag}))),C=(e,t={})=>{var n,o,r,i;let s=t;"object"==typeof e&&(s=e,e=s.id);const{values:l,locale:u=k(),default:c}=s;if(null==u)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");let m=a(e,u);if(m){if("string"!=typeof m)return console.warn(`[svelte-i18n] Message with id "${e}" must be of type "string", found: "${typeof m}". Gettin its value through the "$format" method is deprecated; use the "json" method instead.`),m}else m=null!==(i=null!==(r=null===(o=(n=j()).handleMissingMessage)||void 0===o?void 0:o.call(n,{locale:u,id:e,defaultValue:c}))&&void 0!==r?r:c)&&void 0!==i?i:e;if(!l)return m;let d=m;try{d=Z(m,u).format(l)}catch(t){t instanceof Error&&console.warn(`[svelte-i18n] Message "${e}" has syntax error:`,t.message)}return d},G=(e,t)=>H(t).format(e),J=(e,t)=>z(t).format(e),Q=(e,t)=>_(t).format(e),U=(e,t=k())=>a(e,t),V=e.derived([D,c],(()=>C)),B=e.derived([D],(()=>G)),K=e.derived([D],(()=>J)),R=e.derived([D],(()=>Q)),W=e.derived([D,c],(()=>U));exports._=V,exports.addMessages=f,exports.date=K,exports.defineMessages=function(e){return e},exports.dictionary=c,exports.format=V,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,...n}=e,o=e.initialLocale||e.fallbackLocale;return n.warnOnMissingMessages&&(delete n.warnOnMissingMessages,null==n.handleMissingMessage?n.handleMissingMessage=x:console.warn('[svelte-i18n] The "warnOnMissingMessages" option is deprecated. Please use the "handleMissingMessage" option instead.')),Object.assign(M,n,{initialLocale:o}),t&&("number"in t&&Object.assign(M.formats.number,t.number),"date"in t&&Object.assign(M.formats.date,t.date),"time"in t&&Object.assign(M.formats.time,t.time)),D.set(o)},exports.isLoading=O,exports.json=W,exports.locale=D,exports.locales=g,exports.number=R,exports.register=function(e,t){h(e)||function(e){p[e]=new Set}(e);const n=h(e);h(e).has(t)||(m(e)||c.update((t=>(t[e]={},t))),n.add(t))},exports.t=V,exports.time=B,exports.waitLocale=function(e){return y(e||k()||j().initialLocale)};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("svelte/store"),t=require("deepmerge"),n=require("intl-messageformat");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=o(t),i=o(n);const s={},a=(e,t,n)=>n?(t in s||(s[t]={}),e in s[t]||(s[t][e]=n),n):n,l=(e,t)=>{if(null==t)return;if(t in s&&e in s[t])return s[t][e];const n=$(t);for(let o=0;o<n.length;o++){const r=d(n[o],e);if(r)return a(e,t,r)}};let u;const c=e.writable({});function m(e){return e in u}function d(e,t){if(!m(e))return null;const n=function(e){return u[e]||null}(e);return function(e,t){if(null==t)return;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}(n,t)}function f(e,...t){delete s[e],c.update((n=>(n[e]=r.default.all([n[e]||{},...t]),n)))}const g=e.derived([c],(([e])=>Object.keys(e)));c.subscribe((e=>u=e));const p={};function h(e){return p[e]}function w(e){return null!=e&&$(e).some((e=>{var t;return null===(t=h(e))||void 0===t?void 0:t.size}))}function b(e,t){const n=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))))));return n.then((t=>f(e,...t)))}const v={};function y(e){if(!w(e))return e in v?v[e]:Promise.resolve();const t=function(e){return $(e).map((e=>{const t=h(e);return[e,t?[...t]:[]]})).filter((([,e])=>e.length>0))}(e);return v[e]=Promise.all(t.map((([e,t])=>b(e,t)))).then((()=>{if(w(e))return y(e);delete v[e]})),v[e]}function x({locale:e,id:t}){console.warn(`[svelte-i18n] The message "${t}" was not found in "${$(e).join('", "')}".${w(k())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`)}const M={fallbackLocale: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,handleMissingMessage:void 0,ignoreTag:!0};function j(){return M}const O=e.writable(!1);let L;const F=e.writable(null);function T(e){return e.split("-").map(((e,t,n)=>n.slice(0,t+1).join("-"))).reverse()}function $(e,t=j().fallbackLocale){const n=Array.isArray(e)?e.flatMap((e=>T(e))):T(e);return t?[...new Set([...n,...T(t)])]:n}function k(){return null!=L?L:void 0}F.subscribe((e=>{L=null!=e?e:void 0,"undefined"!=typeof window&&null!=e&&document.documentElement.setAttribute("lang",e)}));const A=e=>{const t=Array.isArray(e)?function(e){if(null==e)return;const t=$(e);for(let e=0;e<t.length;e++){const n=t[e];if(m(n))return n}}(e):e;if(!w(t))return F.set(t),Promise.resolve();const{loadingDelay:n}=j();let o;return"undefined"!=typeof window&&null!=k()&&n?o=window.setTimeout((()=>{O.set(!0)}),n):O.set(!0),y(e).then((()=>{F.set(t)})).finally((()=>{clearTimeout(o),O.set(!1)}))},D={subscribe:F.subscribe,update:e=>A(e(k())),set:A},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 o=JSON.stringify(n);return o in t?t[o]:t[o]=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.`)},q=P((({locale:e,format:t,...n})=>{if(null==e)throw new Error('[svelte-i18n] A "locale" must be set to format numbers');return t&&(n=S("number",t)),new Intl.NumberFormat(e,n)})),I=P((({locale:e,format:t,...n})=>{if(null==e)throw new Error('[svelte-i18n] A "locale" must be set to format dates');return t?n=S("date",t):0===Object.keys(n).length&&(n=S("date","short")),new Intl.DateTimeFormat(e,n)})),_=P((({locale:e,format:t,...n})=>{if(null==e)throw new Error('[svelte-i18n] A "locale" must be set to format time values');return t?n=S("time",t):0===Object.keys(n).length&&(n=S("time","short")),new Intl.DateTimeFormat(e,n)})),z=({locale:e=k(),...t}={})=>q({locale:e,...t}),H=({locale:e=k(),...t}={})=>I({locale:e,...t}),Z=({locale:e=k(),...t}={})=>_({locale:e,...t}),C=P(((e,t=k())=>new i.default(e,t,j().formats,{ignoreTag:j().ignoreTag}))),G=(e,t={})=>{var n,o,r,i;let s=t;"object"==typeof e&&(s=e,e=s.id);const{values:a,locale:u=k(),default:c}=s;if(null==u)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");let m=l(e,u);if(m){if("string"!=typeof m)return console.warn(`[svelte-i18n] Message with id "${e}" must be of type "string", found: "${typeof m}". Gettin its value through the "$format" method is deprecated; use the "json" method instead.`),m}else m=null!==(i=null!==(r=null===(o=(n=j()).handleMissingMessage)||void 0===o?void 0:o.call(n,{locale:u,id:e,defaultValue:c}))&&void 0!==r?r:c)&&void 0!==i?i:e;if(!a)return m;let d=m;try{d=C(m,u).format(a)}catch(t){t instanceof Error&&console.warn(`[svelte-i18n] Message "${e}" has syntax error:`,t.message)}return d},J=(e,t)=>Z(t).format(e),Q=(e,t)=>H(t).format(e),U=(e,t)=>z(t).format(e),V=(e,t=k())=>l(e,t),B=e.derived([D,c],(()=>G)),K=e.derived([D],(()=>J)),R=e.derived([D],(()=>Q)),W=e.derived([D],(()=>U)),X=e.derived([D,c],(()=>V));exports._=B,exports.addMessages=f,exports.date=R,exports.defineMessages=function(e){return e},exports.dictionary=c,exports.format=B,exports.getDateFormatter=H,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=C,exports.getNumberFormatter=z,exports.getTimeFormatter=Z,exports.init=function(e){const{formats:t,...n}=e,o=e.initialLocale||e.fallbackLocale;return n.warnOnMissingMessages&&(delete n.warnOnMissingMessages,null==n.handleMissingMessage?n.handleMissingMessage=x:console.warn('[svelte-i18n] The "warnOnMissingMessages" option is deprecated. Please use the "handleMissingMessage" option instead.')),Object.assign(M,n,{initialLocale:o}),t&&("number"in t&&Object.assign(M.formats.number,t.number),"date"in t&&Object.assign(M.formats.date,t.date),"time"in t&&Object.assign(M.formats.time,t.time)),D.set(o)},exports.isLoading=O,exports.json=X,exports.locale=D,exports.locales=g,exports.number=W,exports.register=function(e,t){h(e)||function(e){p[e]=new Set}(e);const n=h(e);h(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 y(e||k()||j().initialLocale)};
import * as svelte_store from 'svelte/store';
import IntlMessageFormat, { FormatXMLElementFn, Formats } from 'intl-messageformat';
type LocaleStoreValue = string | null | undefined;
declare const $locale: {
set: (newLocale: string | null | undefined) => void | Promise<void>;
update(this: void, updater: svelte_store.Updater<string | null | undefined>): void;
subscribe(this: void, run: svelte_store.Subscriber<string | null | undefined>, invalidate?: ((value?: string | null | undefined) => void) | undefined): svelte_store.Unsubscriber;
subscribe: (this: void, run: svelte_store.Subscriber<LocaleStoreValue>, invalidate?: ((value?: LocaleStoreValue) => void) | undefined) => svelte_store.Unsubscriber;
update: (fn: (value: LocaleStoreValue) => string | string[] | null | undefined) => Promise<void>;
set: (newLocale: string | string[] | null | undefined) => Promise<void>;
};

@@ -71,3 +72,3 @@

declare function init(opts: ConfigureOptionsInit): void | Promise<void>;
declare function init(opts: ConfigureOptionsInit): Promise<void>;

@@ -74,0 +75,0 @@ declare function registerLocaleLoader(locale: string, loader: MessagesLoader): void;

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

import{writable as e,derived as n}from"svelte/store";import t from"deepmerge";import o from"intl-messageformat";const i={},r=(e,n,t)=>t?(n in i||(i[n]={}),e in i[n]||(i[n][e]=t),t):t,s=(e,n)=>{if(null==n)return;if(n in i&&e in i[n])return i[n][e];const t=E(n);for(let o=0;o<t.length;o++){const i=c(t[o],e);if(i)return r(e,n,i)}};let l;const a=e({});function u(e){return e in l}function c(e,n){if(!u(e))return null;const t=function(e){return l[e]||null}(e);return function(e,n){if(null==n)return;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)}function m(e,...n){delete i[e],a.update((o=>(o[e]=t.all([o[e]||{},...n]),o)))}const f=n([a],(([e])=>Object.keys(e)));a.subscribe((e=>l=e));const d={};function g(e){return d[e]}function h(e){return null!=e&&E(e).some((e=>{var n;return null===(n=g(e))||void 0===n?void 0:n.size}))}function w(e,n){const t=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))))));return t.then((n=>m(e,...n)))}const p={};function b(e){if(!h(e))return e in p?p[e]:Promise.resolve();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])=>w(e,n)))).then((()=>{if(h(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)||a.update((n=>(n[e]={},n))),t.add(n))}function v({locale:e,id:n}){console.warn(`[svelte-i18n] The message "${n}" was not found in "${E(e).join('", "')}".${h(D())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`)}const M={fallbackLocale: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,handleMissingMessage:void 0,ignoreTag:!0};function j(){return M}function O(e){const{formats:n,...t}=e,o=e.initialLocale||e.fallbackLocale;return t.warnOnMissingMessages&&(delete t.warnOnMissingMessages,null==t.handleMissingMessage?t.handleMissingMessage=v:console.warn('[svelte-i18n] The "warnOnMissingMessages" option is deprecated. Please use the "handleMissingMessage" option instead.')),Object.assign(M,t,{initialLocale:o}),n&&("number"in n&&Object.assign(M.formats.number,n.number),"date"in n&&Object.assign(M.formats.date,n.date),"time"in n&&Object.assign(M.formats.time,n.time)),x.set(o)}const $=e(!1);let k;const T=e(null);function L(e){return e.split("-").map(((e,n,t)=>t.slice(0,n+1).join("-"))).reverse()}function E(e,n=j().fallbackLocale){const t=L(e);return n?[...new Set([...t,...L(n)])]:t}function D(){return null!=k?k:void 0}T.subscribe((e=>{k=null!=e?e:void 0,"undefined"!=typeof window&&null!=e&&document.documentElement.setAttribute("lang",e)}));const x={...T,set:e=>{if(e&&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)&&h(e)){const{loadingDelay:n}=j();let t;return"undefined"!=typeof window&&null!=D()&&n?t=window.setTimeout((()=>$.set(!0)),n):$.set(!0),b(e).then((()=>{T.set(e)})).finally((()=>{clearTimeout(t),$.set(!1)}))}return T.set(e)}},N=(e,n)=>{const t=e.split("&").find((e=>0===e.indexOf(`${n}=`)));return t?t.split("=").pop():null},A=(e,n)=>{const t=n.exec(e);return t&&t[1]||null},P=e=>"undefined"==typeof window?null:A(window.location.hostname,e),S=e=>"undefined"==typeof window?null:A(window.location.pathname,e),F=()=>"undefined"==typeof window?null:window.navigator.language||window.navigator.languages[0],I=e=>"undefined"==typeof window?null:N(window.location.search.substr(1),e),z=e=>"undefined"==typeof window?null:N(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((({locale:e,format:n,...t})=>{if(null==e)throw new Error('[svelte-i18n] A "locale" must be set to format numbers');return n&&(t=C("number",n)),new Intl.NumberFormat(e,t)})),J=Z((({locale:e,format:n,...t})=>{if(null==e)throw new Error('[svelte-i18n] A "locale" must be set to format dates');return n?t=C("date",n):0===Object.keys(t).length&&(t=C("date","short")),new Intl.DateTimeFormat(e,t)})),U=Z((({locale:e,format:n,...t})=>{if(null==e)throw new Error('[svelte-i18n] A "locale" must be set to format time values');return n?t=C("time",n):0===Object.keys(t).length&&(t=C("time","short")),new Intl.DateTimeFormat(e,t)})),V=({locale:e=D(),...n}={})=>G({locale:e,...n}),_=({locale:e=D(),...n}={})=>J({locale:e,...n}),q=({locale:e=D(),...n}={})=>U({locale:e,...n}),B=Z(((e,n=D())=>new o(e,n,j().formats,{ignoreTag:j().ignoreTag}))),H=(e,n={})=>{var t,o,i,r;let l=n;"object"==typeof e&&(l=e,e=l.id);const{values:a,locale:u=D(),default:c}=l;if(null==u)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");let m=s(e,u);if(m){if("string"!=typeof m)return console.warn(`[svelte-i18n] Message with id "${e}" must be of type "string", found: "${typeof m}". Gettin its value through the "$format" method is deprecated; use the "json" method instead.`),m}else m=null!==(r=null!==(i=null===(o=(t=j()).handleMissingMessage)||void 0===o?void 0:o.call(t,{locale:u,id:e,defaultValue:c}))&&void 0!==i?i:c)&&void 0!==r?r:e;if(!a)return m;let f=m;try{f=B(m,u).format(a)}catch(n){n instanceof Error&&console.warn(`[svelte-i18n] Message "${e}" has syntax error:`,n.message)}return f},K=(e,n)=>q(n).format(e),Q=(e,n)=>_(n).format(e),R=(e,n)=>V(n).format(e),W=(e,n=D())=>s(e,n),X=n([x,a],(()=>H)),Y=n([x],(()=>K)),ee=n([x],(()=>Q)),ne=n([x],(()=>R)),te=n([x,a],(()=>W));function oe(e){return e}function ie(e){return b(e||D()||j().initialLocale)}export{X as _,m as addMessages,ee as date,oe as defineMessages,a as dictionary,X as format,_ as getDateFormatter,z as getLocaleFromHash,P as getLocaleFromHostname,F as getLocaleFromNavigator,S as getLocaleFromPathname,I as getLocaleFromQueryString,B as getMessageFormatter,V as getNumberFormatter,q as getTimeFormatter,O as init,$ as isLoading,te as json,x as locale,f as locales,ne as number,y as register,X as t,Y as time,ie as waitLocale};
import{writable as e,derived as n}from"svelte/store";import t from"deepmerge";import o from"intl-messageformat";const i={},r=(e,n,t)=>t?(n in i||(i[n]={}),e in i[n]||(i[n][e]=t),t):t,s=(e,n)=>{if(null==n)return;if(n in i&&e in i[n])return i[n][e];const t=L(n);for(let o=0;o<t.length;o++){const i=c(t[o],e);if(i)return r(e,n,i)}};let l;const a=e({});function u(e){return e in l}function c(e,n){if(!u(e))return null;const t=function(e){return l[e]||null}(e);return function(e,n){if(null==n)return;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)}function m(e,...n){delete i[e],a.update((o=>(o[e]=t.all([o[e]||{},...n]),o)))}const f=n([a],(([e])=>Object.keys(e)));a.subscribe((e=>l=e));const d={};function g(e){return d[e]}function h(e){return null!=e&&L(e).some((e=>{var n;return null===(n=g(e))||void 0===n?void 0:n.size}))}function w(e,n){const t=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))))));return t.then((n=>m(e,...n)))}const p={};function b(e){if(!h(e))return e in p?p[e]:Promise.resolve();const n=function(e){return L(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])=>w(e,n)))).then((()=>{if(h(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)||a.update((n=>(n[e]={},n))),t.add(n))}function v({locale:e,id:n}){console.warn(`[svelte-i18n] The message "${n}" was not found in "${L(e).join('", "')}".${h(E())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`)}const M={fallbackLocale: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,handleMissingMessage:void 0,ignoreTag:!0};function j(){return M}function O(e){const{formats:n,...t}=e,o=e.initialLocale||e.fallbackLocale;return t.warnOnMissingMessages&&(delete t.warnOnMissingMessages,null==t.handleMissingMessage?t.handleMissingMessage=v:console.warn('[svelte-i18n] The "warnOnMissingMessages" option is deprecated. Please use the "handleMissingMessage" option instead.')),Object.assign(M,t,{initialLocale:o}),n&&("number"in n&&Object.assign(M.formats.number,n.number),"date"in n&&Object.assign(M.formats.date,n.date),"time"in n&&Object.assign(M.formats.time,n.time)),x.set(o)}const $=e(!1);let k;const T=e(null);function A(e){return e.split("-").map(((e,n,t)=>t.slice(0,n+1).join("-"))).reverse()}function L(e,n=j().fallbackLocale){const t=Array.isArray(e)?e.flatMap((e=>A(e))):A(e);return n?[...new Set([...t,...A(n)])]:t}function E(){return null!=k?k:void 0}T.subscribe((e=>{k=null!=e?e:void 0,"undefined"!=typeof window&&null!=e&&document.documentElement.setAttribute("lang",e)}));const D=e=>{const n=Array.isArray(e)?function(e){if(null==e)return;const n=L(e);for(let e=0;e<n.length;e++){const t=n[e];if(u(t))return t}}(e):e;if(!h(n))return T.set(n),Promise.resolve();const{loadingDelay:t}=j();let o;return"undefined"!=typeof window&&null!=E()&&t?o=window.setTimeout((()=>{$.set(!0)}),t):$.set(!0),b(e).then((()=>{T.set(n)})).finally((()=>{clearTimeout(o),$.set(!1)}))},x={subscribe:T.subscribe,update:e=>D(e(E())),set:D},N=(e,n)=>{const t=e.split("&").find((e=>0===e.indexOf(`${n}=`)));return t?t.split("=").pop():null},P=(e,n)=>{const t=n.exec(e);return t&&t[1]||null},S=e=>"undefined"==typeof window?null:P(window.location.hostname,e),F=e=>"undefined"==typeof window?null:P(window.location.pathname,e),I=()=>"undefined"==typeof window?null:window.navigator.language||window.navigator.languages[0],z=e=>"undefined"==typeof window?null:N(window.location.search.substr(1),e),Z=e=>"undefined"==typeof window?null:N(window.location.hash.substr(1),e),C=e=>{const n=Object.create(null);return t=>{const o=JSON.stringify(t);return o in n?n[o]:n[o]=e(t)}},G=(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.`)},J=C((({locale:e,format:n,...t})=>{if(null==e)throw new Error('[svelte-i18n] A "locale" must be set to format numbers');return n&&(t=G("number",n)),new Intl.NumberFormat(e,t)})),U=C((({locale:e,format:n,...t})=>{if(null==e)throw new Error('[svelte-i18n] A "locale" must be set to format dates');return n?t=G("date",n):0===Object.keys(t).length&&(t=G("date","short")),new Intl.DateTimeFormat(e,t)})),V=C((({locale:e,format:n,...t})=>{if(null==e)throw new Error('[svelte-i18n] A "locale" must be set to format time values');return n?t=G("time",n):0===Object.keys(t).length&&(t=G("time","short")),new Intl.DateTimeFormat(e,t)})),_=({locale:e=E(),...n}={})=>J({locale:e,...n}),q=({locale:e=E(),...n}={})=>U({locale:e,...n}),B=({locale:e=E(),...n}={})=>V({locale:e,...n}),H=C(((e,n=E())=>new o(e,n,j().formats,{ignoreTag:j().ignoreTag}))),K=(e,n={})=>{var t,o,i,r;let l=n;"object"==typeof e&&(l=e,e=l.id);const{values:a,locale:u=E(),default:c}=l;if(null==u)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");let m=s(e,u);if(m){if("string"!=typeof m)return console.warn(`[svelte-i18n] Message with id "${e}" must be of type "string", found: "${typeof m}". Gettin its value through the "$format" method is deprecated; use the "json" method instead.`),m}else m=null!==(r=null!==(i=null===(o=(t=j()).handleMissingMessage)||void 0===o?void 0:o.call(t,{locale:u,id:e,defaultValue:c}))&&void 0!==i?i:c)&&void 0!==r?r:e;if(!a)return m;let f=m;try{f=H(m,u).format(a)}catch(n){n instanceof Error&&console.warn(`[svelte-i18n] Message "${e}" has syntax error:`,n.message)}return f},Q=(e,n)=>B(n).format(e),R=(e,n)=>q(n).format(e),W=(e,n)=>_(n).format(e),X=(e,n=E())=>s(e,n),Y=n([x,a],(()=>K)),ee=n([x],(()=>Q)),ne=n([x],(()=>R)),te=n([x],(()=>W)),oe=n([x,a],(()=>X));function ie(e){return e}function re(e){return b(e||E()||j().initialLocale)}export{Y as _,m as addMessages,ne as date,ie as defineMessages,a as dictionary,Y as format,q as getDateFormatter,Z as getLocaleFromHash,S as getLocaleFromHostname,I as getLocaleFromNavigator,F as getLocaleFromPathname,z as getLocaleFromQueryString,H as getMessageFormatter,_ as getNumberFormatter,B as getTimeFormatter,O as init,$ as isLoading,oe as json,x as locale,f as locales,te as number,y as register,Y as t,ee as time,re as waitLocale};
{
"name": "svelte-i18n",
"version": "3.4.1",
"version": "3.5.0-alpha.0",
"main": "dist/runtime.cjs.js",

@@ -101,9 +101,9 @@ "module": "dist/runtime.esm.js",

"test": "cross-env NODE_ICU_DATA=node_modules/full-icu jest",
"test:ci": "yarn test -- --silent",
"test:ci": "pnpm test -- --silent",
"lint": "eslint \"{src,test}/**/*.ts\"",
"format": "prettier --loglevel silent --write \"{src,test}/**/*.ts\"",
"release": " git add package.json && git commit -m \"chore(release): v$npm_package_version :tada:\"",
"prebuild": "yarn clean",
"prebuild": "pnpm clean",
"version": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1 && git add CHANGELOG.md"
}
}
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