svelte-i18n
Advanced tools
Comparing version 3.0.1 to 3.0.2
@@ -0,1 +1,10 @@ | ||
## [3.0.2](https://github.com/kaisermann/svelte-i18n/compare/v3.0.1...v3.0.2) (2020-03-06) | ||
### Bug Fixes | ||
* 🐛 ignore loadingDelay for the initialLocale ([9d82a98](https://github.com/kaisermann/svelte-i18n/commit/9d82a98e8d6ecf25dca12cce88183502e11133fe)), closes [#53](https://github.com/kaisermann/svelte-i18n/issues/53) [#53](https://github.com/kaisermann/svelte-i18n/issues/53) | ||
## [3.0.1](https://github.com/kaisermann/svelte-i18n/compare/v2.3.1...v3.0.1) (2020-02-03) | ||
@@ -2,0 +11,0 @@ |
@@ -1,2 +0,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=t.writable(!1); | ||
"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} | ||
/*! ***************************************************************************** | ||
@@ -15,2 +15,3 @@ Copyright (c) Microsoft Corporation. All rights reserved. | ||
and limitations under the License. | ||
***************************************************************************** */function m(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 f={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 d(){return f}const p={};function g(e){return p[e]}function w(e){return L(e).reverse().some(g)}const b={};function h(e){if(!w(e))return;if(e in b)return b[e];const t=function(e){return L(e).reverse().map(e=>{const t=g(e);return[e,t?[...t]:[]]}).filter(([,e])=>e.length>0)}(e);if(0===t.length)return;const n=setTimeout(()=>u.set(!0),d().loadingDelay);return b[e]=Promise.all(t.map(([e,t])=>Promise.all(t.map(e=>e())).then(t=>{!function(e){delete p[e]}(e),t=t.map(e=>e.default||e),s(e,...t)}))).then(()=>{clearTimeout(n),u.set(!1),delete b[e]}),b[e]}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}=d();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}=d();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=>function e(t){return null==t||a(t)?t:e(j(t))}(e)&&w(e)?h(e).then(()=>k(e)):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=d().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=m(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=m(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=m(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=m(e,["locale"]);return T(Object.assign({locale:t},n))},q=(e={})=>{var{locale:t=F()}=e,n=m(e,["locale"]);return I(Object.assign({locale:t},n))},H=(e={})=>{var{locale:t=F()}=e,n=m(e,["locale"]);return A(Object.assign({locale:t},n))},Z=$((e,t=F())=>new n(e,t,d().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:(d().warnOnMissingMessages&&console.warn(`[svelte-i18n] The message "${e}" was not found in "${L(o).join('", "')}".${w(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=m(e,["formats"]),o=e.initialLocale||e.fallbackLocale;return Object.assign(f,n,{initialLocale:o}),t&&("number"in t&&Object.assign(f.formats.number,t.number),"date"in t&&Object.assign(f.formats.date,t.date),"time"in t&&Object.assign(f.formats.time,t.time)),x.set(o)},exports.isLoading=u,exports.locale=x,exports.locales=c,exports.number=K,exports.register=function(e,t){g(e)||function(e){p[e]=new Set}(e);const n=g(e);g(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 h(e||F()||d().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 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)}; |
@@ -1,2 +0,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=n(!1); | ||
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))} | ||
/*! ***************************************************************************** | ||
@@ -15,2 +15,2 @@ Copyright (c) Microsoft Corporation. All rights reserved. | ||
and limitations under the License. | ||
***************************************************************************** */function m(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 f={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 d(){return f}function w(n){const{formats:e}=n,t=m(n,["formats"]),o=n.initialLocale||n.fallbackLocale;return Object.assign(f,t,{initialLocale:o}),e&&("number"in e&&Object.assign(f.formats.number,e.number),"date"in e&&Object.assign(f.formats.date,e.date),"time"in e&&Object.assign(f.formats.time,e.time)),j.set(o)}const g={};function b(n){return g[n]}function p(n){return E(n).reverse().some(b)}const h={};function y(n){if(!p(n))return;if(n in h)return h[n];const e=function(n){return E(n).reverse().map(n=>{const e=b(n);return[n,e?[...e]:[]]}).filter(([,n])=>n.length>0)}(n);if(0===e.length)return;const t=setTimeout(()=>u.set(!0),d().loadingDelay);return h[n]=Promise.all(e.map(([n,e])=>Promise.all(e.map(n=>n())).then(e=>{!function(n){delete g[n]}(n),e=e.map(n=>n.default||n),s(n,...e)}))).then(()=>{clearTimeout(t),u.set(!1),delete h[n]}),h[n]}function O(n,e){b(n)||function(n){g[n]=new Set}(n);const t=b(n);b(n).has(e)||(a(n)||i.update(e=>(e[n]={},e)),t.add(e))}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}=d();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}=d();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=>function n(e){return null==e||a(e)?e:n(x(e))}(n)&&p(n)?y(n).then(()=>D(n)):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=d().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=m(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=m(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=m(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=m(n,["locale"]);return _(Object.assign({locale:e},t))},G=(n={})=>{var{locale:e=$()}=n,t=m(n,["locale"]);return q(Object.assign({locale:e},t))},H=(n={})=>{var{locale:e=$()}=n,t=m(n,["locale"]);return z(Object.assign({locale:e},t))},K=J((n,e=$())=>new t(n,e,d().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:(d().warnOnMissingMessages&&console.warn(`[svelte-i18n] The message "${n}" was not found in "${E(o).join('", "')}".${p($())?"\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 y(n||$()||d().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,w as init,u as isLoading,j as locale,c as locales,en as number,O as register,X as t,Y as time,on as waitLocale}; | ||
***************************************************************************** */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}; |
{ | ||
"name": "svelte-i18n", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"main": "dist/runtime.cjs.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/runtime.esm.js", |
@@ -48,2 +48,2 @@ [![npm version](https://badge.fury.io/js/svelte-i18n.svg)](https://badge.fury.io/js/svelte-i18n) ![](https://github.com/kaisermann/svelte-i18n/workflows/CI/badge.svg) | ||
### [Go see the documentation](https://github.com/kaisermann/svelte-i18n/blob/master/docs) | ||
### [Go see the documentation](/docs/Getting%20Started.md) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39742
20
218