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

83

dist/cli.js

@@ -6,2 +6,3 @@ #!/usr/bin/env node

var path = require('path');
var color = require('cli-color');
var sade = require('sade');

@@ -12,26 +13,2 @@ var glob = require('tiny-glob');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return Object.freeze(n);
}
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
var sade__default = /*#__PURE__*/_interopDefaultLegacy(sade);
var glob__default = /*#__PURE__*/_interopDefaultLegacy(glob);
/* eslint-disable no-multi-assign */

@@ -239,7 +216,15 @@ /* eslint-disable no-return-assign */

const { readFile, writeFile, mkdir, access } = fs__default["default"].promises;
const { readFile, writeFile, mkdir, access, stat } = fs.promises;
const fileExists = (path) => access(path)
.then(() => true)
.catch(() => false);
const program = sade__default["default"]('svelte-i18n');
const isDirectory = (path) => stat(path).then((stats) => stats.isDirectory());
function isSvelteError(error, code) {
return (typeof error === 'object' &&
error != null &&
'message' in error &&
'code' in error &&
(code == null || error.code === code));
}
const program = sade('svelte-i18n');
program

@@ -250,6 +235,11 @@ .command('extract <glob> [output]')

.option('--overwrite', 'overwrite the content of the output file instead of just appending new properties', false)
.option('-c, --config <dir>', 'path to the "svelte.config.js" file', process.cwd())
.option('-c, --config <dir>', 'path to the "svelte.config.js" file', `${process.cwd()}/svelte.config.js`)
.action(async (globStr, output, { shallow, overwrite, config }) => {
const filesToExtract = (await glob__default["default"](globStr)).filter((file) => file.match(/\.html|svelte$/i));
const svelteConfig = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(path.resolve(config, 'svelte.config.js')).catch(() => null);
const filesToExtract = (await glob(globStr)).filter((file) => file.match(/\.html|svelte$/i));
const isConfigDir = await isDirectory(config);
const resolvedConfigPath = path.resolve(config, isConfigDir ? 'svelte.config.js' : '');
if (isConfigDir) {
console.warn(color.yellow(`Warning: -c/--config should point to the svelte.config file, not to a directory.\nUsing "${resolvedConfigPath}".`));
}
const svelteConfig = await import(resolvedConfigPath).catch(() => null);
let accumulator = {};

@@ -265,11 +255,30 @@ if (output != null && overwrite === false && (await fileExists(output))) {

for await (const filePath of filesToExtract) {
const buffer = await readFile(filePath);
let content = buffer.toString();
if (svelteConfig === null || svelteConfig === void 0 ? void 0 : svelteConfig.preprocess) {
const processed = await compiler.preprocess(content, svelteConfig.preprocess, {
filename: filePath,
});
content = processed.code;
try {
const buffer = await readFile(filePath);
let content = buffer.toString();
if (svelteConfig === null || svelteConfig === void 0 ? void 0 : svelteConfig.preprocess) {
const processed = await compiler.preprocess(content, svelteConfig.preprocess, {
filename: filePath,
});
content = processed.code;
}
extractMessages(content, { accumulator, shallow });
}
extractMessages(content, { accumulator, shallow });
catch (e) {
if (isSvelteError(e, 'parse-error') &&
e.message.includes('Unexpected token')) {
const msg = [
`Error: unexpected token detected in "${filePath}"`,
svelteConfig == null &&
`A svelte config is needed if the Svelte files use preprocessors. Tried to load "${resolvedConfigPath}".`,
svelteConfig != null &&
`A svelte config was detected at "${resolvedConfigPath}". Make sure the preprocess step is correctly configured."`,
]
.filter(Boolean)
.join('\n');
console.error(color.red(msg));
process.exit(1);
}
throw e;
}
}

@@ -276,0 +285,0 @@ const jsonDictionary = JSON.stringify(accumulator, null, ' ');

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

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

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

@@ -75,0 +74,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=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};
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};
{
"name": "svelte-i18n",
"version": "3.5.0-alpha.0",
"version": "3.5.0",
"main": "dist/runtime.cjs.js",

@@ -22,4 +22,17 @@ "module": "dist/runtime.esm.js",

"engines": {
"node": ">= 11.15.0"
"node": ">= 17.5.0"
},
"scripts": {
"clean": "rm -rf dist/",
"build": "rollup -c",
"dev": "rollup -c -w",
"test": "cross-env NODE_ICU_DATA=node_modules/full-icu jest",
"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": "pnpm clean",
"version": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1 && git add CHANGELOG.md",
"prepublishOnly": "pnpm test && pnpm build"
},
"files": [

@@ -42,14 +55,2 @@ "dist/"

},
"jest": {
"collectCoverage": true,
"testMatch": [
"<rootDir>/test/**/*.test.ts"
],
"collectCoverageFrom": [
"<rootDir>/src/**/*.ts"
],
"transform": {
"^.+\\.tsx?$": "ts-jest"
}
},
"peerDependencies": {

@@ -63,12 +64,14 @@ "svelte": "^3.25.1"

"@kiwi/prettier-config": "^1.19.5",
"@rollup/plugin-commonjs": "^20.0.0",
"@rollup/plugin-commonjs": "^23.0.2",
"@rollup/plugin-terser": "^0.1.0",
"@rollup/plugin-typescript": "^9.0.2",
"@types/cli-color": "^2.0.2",
"@types/dlv": "^1.1.2",
"@types/estree": "1.0.0",
"@types/intl": "^1.2.0",
"@types/jest": "^26.0.24",
"@types/node": "^14.18.33",
"@types/jest": "^29.2.3",
"@types/node": "^18.11.9",
"@types/sade": "^1.7.4",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^26.6.3",
"babel-jest": "^29.3.1",
"conventional-changelog-cli": "^2.2.2",

@@ -79,16 +82,17 @@ "cross-env": "^7.0.3",

"husky": "^4.3.8",
"jest": "^26.6.3",
"lint-staged": "^10.5.4",
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"rollup": "^2.79.1",
"rollup": "^3.3.0",
"rollup-plugin-auto-external": "^2.0.0",
"rollup-plugin-dts": "^4.2.3",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-dts": "^5.0.0",
"sass": "^1.56.1",
"svelte": "^3.53.1",
"svelte-preprocess": "^4.10.7",
"ts-jest": "^26.5.6",
"ts-jest": "^29.0.3",
"typescript": "^4.9.3"
},
"dependencies": {
"cli-color": "^2.0.3",
"deepmerge": "^4.2.2",

@@ -100,14 +104,5 @@ "estree-walker": "^2",

},
"scripts": {
"clean": "rm -rf dist/",
"build": "rollup -c",
"dev": "rollup -c -w",
"test": "cross-env NODE_ICU_DATA=node_modules/full-icu jest",
"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": "pnpm clean",
"version": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1 && git add CHANGELOG.md"
"volta": {
"node": "17.5.0"
}
}
}

@@ -51,3 +51,3 @@ > :information_source: `svelte-i18n` is due to some reworking, like moving from a singleton to instances. This will be worked on when I find the time and priority :pray:

- [Documentation / Getting Started](/docs/Getting%20Started.md)
- [Usage with Svelte Kit](/docs/SvelteKit.md)
- [Usage with Svelte Kit](/docs/Svelte-Kit.md)
- [i18n VSCode extension (3rd party)](https://github.com/antfu/i18n-ally)
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