@verbadev/js 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +7 -3
package/dist/index.d.mts
CHANGED
|
@@ -8,6 +8,12 @@ interface VerbaConfig {
|
|
|
8
8
|
*/
|
|
9
9
|
locale?: string | 'auto';
|
|
10
10
|
baseUrl?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Custom locale detector function.
|
|
13
|
+
* Called instead of the default browser-based detection (navigator.language).
|
|
14
|
+
* Return a locale string (e.g., 'en-US') or null to fall back to 'en'.
|
|
15
|
+
*/
|
|
16
|
+
localeDetector?: () => string | null;
|
|
11
17
|
}
|
|
12
18
|
interface TranslationsResponse {
|
|
13
19
|
version: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,12 @@ interface VerbaConfig {
|
|
|
8
8
|
*/
|
|
9
9
|
locale?: string | 'auto';
|
|
10
10
|
baseUrl?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Custom locale detector function.
|
|
13
|
+
* Called instead of the default browser-based detection (navigator.language).
|
|
14
|
+
* Return a locale string (e.g., 'en-US') or null to fall back to 'en'.
|
|
15
|
+
*/
|
|
16
|
+
localeDetector?: () => string | null;
|
|
11
17
|
}
|
|
12
18
|
interface TranslationsResponse {
|
|
13
19
|
version: number;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var l=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var g=(n,e)=>{for(var s in e)l(n,s,{get:e[s],enumerable:!0})},p=(n,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of u(e))!d.call(n,t)&&t!==s&&l(n,t,{get:()=>e[t],enumerable:!(r=h(e,t))||r.enumerable});return n};var f=n=>p(l({},"__esModule",{value:!0}),n);var m={};g(m,{Verba:()=>o});module.exports=f(m);var y="https://verba.dev";function b(){return typeof navigator>"u"?null:(navigator.languages??[navigator.language])[0]??null}function v(n,e){if(e.includes(n))return n;let s=n.split("-")[0];if(e.includes(s))return s;let r=e.find(t=>t.startsWith(s+"-"));return r||null}var o=class{constructor(e){this.cache=null;this.fetchPromise=null;this.pendingKeys=new Set;this.projectId=e.projectId,this.publicKey=e.publicKey,this.baseUrl=e.baseUrl??y,this.autoDetect=e.locale===void 0||e.locale==="auto",this.autoDetect
|
|
1
|
+
"use strict";var l=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var g=(n,e)=>{for(var s in e)l(n,s,{get:e[s],enumerable:!0})},p=(n,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of u(e))!d.call(n,t)&&t!==s&&l(n,t,{get:()=>e[t],enumerable:!(r=h(e,t))||r.enumerable});return n};var f=n=>p(l({},"__esModule",{value:!0}),n);var m={};g(m,{Verba:()=>o});module.exports=f(m);var y="https://verba.dev";function b(){return typeof navigator>"u"?null:(navigator.languages??[navigator.language])[0]??null}function v(n,e){if(e.includes(n))return n;let s=n.split("-")[0];if(e.includes(s))return s;let r=e.find(t=>t.startsWith(s+"-"));return r||null}var o=class{constructor(e){this.cache=null;this.fetchPromise=null;this.pendingKeys=new Set;if(this.projectId=e.projectId,this.publicKey=e.publicKey,this.baseUrl=e.baseUrl??y,this.autoDetect=e.locale===void 0||e.locale==="auto",this.autoDetect){let s=e.localeDetector??b;this.locale=s()??"en"}else this.locale=e.locale;this.fetchPromise=this.fetchTranslations()}setLocale(e){this.locale=e}getLocale(){return this.locale}getLocales(){return this.cache?.locales??[]}getDefaultLocale(){return this.cache?.defaultLocale??null}t(e,s,r){let t,i;typeof s=="string"?(t=s,i=r):typeof s=="object"&&(i=s);let a;if(!this.cache)t!==void 0&&this.createKeyInBackground(e,t),a=t??e;else{let c=this.cache.data[e];c?a=c[this.locale]??c[this.cache.defaultLocale]??t??e:(t!==void 0&&this.createKeyInBackground(e,t),a=t??e)}return i&&(a=this.interpolate(a,i)),a}interpolate(e,s){return e.replace(/\{(\w+)\}/g,(r,t)=>s[t]!==void 0?String(s[t]):r)}async ready(){this.fetchPromise&&await this.fetchPromise}async fetchTranslations(){let e=`${this.baseUrl}/api/sdk/${this.projectId}/translations`,s={"X-Public-Key":this.publicKey};this.cache&&(s["If-None-Match"]=String(this.cache.version));try{let r=await fetch(e,{headers:s});if(r.status===304&&this.cache)return this.cache;if(!r.ok)throw new Error(`Failed to fetch translations: ${r.status}`);let t=await r.json();if(this.cache={version:t.version,defaultLocale:t.defaultLocale,locales:t.locales,data:t.translations},this.autoDetect){let i=v(this.locale,t.locales);this.locale=i??t.defaultLocale}return this.cache}catch(r){throw console.error("[Verba] Failed to fetch translations:",r),r}}async createKeyInBackground(e,s){if(!this.pendingKeys.has(e)){this.pendingKeys.add(e);try{let r=`${this.baseUrl}/api/sdk/${this.projectId}/keys`,t=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json","X-Public-Key":this.publicKey},body:JSON.stringify({key:e,defaultValue:s})});if(!t.ok){let a=await t.json().catch(()=>({}));console.error("[Verba] Failed to create key:",a.error??t.status);return}let i=await t.json();this.cache&&i.translations&&(this.cache.data[e]=i.translations)}catch(r){console.error("[Verba] Failed to create key:",r)}finally{this.pendingKeys.delete(e)}}}};0&&(module.exports={Verba});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var l="https://verba.dev";function h(){return typeof navigator>"u"?null:(navigator.languages??[navigator.language])[0]??null}function u(a,e){if(e.includes(a))return a;let
|
|
1
|
+
var l="https://verba.dev";function h(){return typeof navigator>"u"?null:(navigator.languages??[navigator.language])[0]??null}function u(a,e){if(e.includes(a))return a;let s=a.split("-")[0];if(e.includes(s))return s;let r=e.find(t=>t.startsWith(s+"-"));return r||null}var c=class{constructor(e){this.cache=null;this.fetchPromise=null;this.pendingKeys=new Set;if(this.projectId=e.projectId,this.publicKey=e.publicKey,this.baseUrl=e.baseUrl??l,this.autoDetect=e.locale===void 0||e.locale==="auto",this.autoDetect){let s=e.localeDetector??h;this.locale=s()??"en"}else this.locale=e.locale;this.fetchPromise=this.fetchTranslations()}setLocale(e){this.locale=e}getLocale(){return this.locale}getLocales(){return this.cache?.locales??[]}getDefaultLocale(){return this.cache?.defaultLocale??null}t(e,s,r){let t,n;typeof s=="string"?(t=s,n=r):typeof s=="object"&&(n=s);let i;if(!this.cache)t!==void 0&&this.createKeyInBackground(e,t),i=t??e;else{let o=this.cache.data[e];o?i=o[this.locale]??o[this.cache.defaultLocale]??t??e:(t!==void 0&&this.createKeyInBackground(e,t),i=t??e)}return n&&(i=this.interpolate(i,n)),i}interpolate(e,s){return e.replace(/\{(\w+)\}/g,(r,t)=>s[t]!==void 0?String(s[t]):r)}async ready(){this.fetchPromise&&await this.fetchPromise}async fetchTranslations(){let e=`${this.baseUrl}/api/sdk/${this.projectId}/translations`,s={"X-Public-Key":this.publicKey};this.cache&&(s["If-None-Match"]=String(this.cache.version));try{let r=await fetch(e,{headers:s});if(r.status===304&&this.cache)return this.cache;if(!r.ok)throw new Error(`Failed to fetch translations: ${r.status}`);let t=await r.json();if(this.cache={version:t.version,defaultLocale:t.defaultLocale,locales:t.locales,data:t.translations},this.autoDetect){let n=u(this.locale,t.locales);this.locale=n??t.defaultLocale}return this.cache}catch(r){throw console.error("[Verba] Failed to fetch translations:",r),r}}async createKeyInBackground(e,s){if(!this.pendingKeys.has(e)){this.pendingKeys.add(e);try{let r=`${this.baseUrl}/api/sdk/${this.projectId}/keys`,t=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json","X-Public-Key":this.publicKey},body:JSON.stringify({key:e,defaultValue:s})});if(!t.ok){let i=await t.json().catch(()=>({}));console.error("[Verba] Failed to create key:",i.error??t.status);return}let n=await t.json();this.cache&&n.translations&&(this.cache.data[e]=n.translations)}catch(r){console.error("[Verba] Failed to create key:",r)}finally{this.pendingKeys.delete(e)}}}};export{c as Verba};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verbadev/js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "JavaScript SDK for Verba Translation Management System",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -37,6 +37,10 @@
|
|
|
37
37
|
},
|
|
38
38
|
"repository": {
|
|
39
39
|
"type": "git",
|
|
40
|
-
"url": ""
|
|
41
|
-
}
|
|
40
|
+
"url": "git+https://github.com/verbadev/js-sdk.git"
|
|
41
|
+
},
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/verbadev/js-sdk/issues"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://github.com/verbadev/js-sdk#readme"
|
|
42
46
|
}
|