generaltranslation 7.0.0-alpha.19 → 7.0.0-alpha.2

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.
@@ -1,2 +1,2 @@
1
- "use strict";var e=["singular","plural","dual","zero","one","two","few","many","other"];var r=new(function(){function e(){this.cache=new Map}return e.prototype._generateKey=function(e,r,t){void 0===t&&(t={});var n=Array.isArray(r)?r.join(","):r,u=t?JSON.stringify(t,Object.keys(t).sort()):"{}";return"".concat(e,":").concat(n,":").concat(u)},e.prototype.get=function(e,r,t){void 0===t&&(t={});var n=this._generateKey(e,r,t);if(!this.cache.has(n)){var u=new Intl[e](r,t);this.cache.set(n,u)}return this.cache.get(n)},e}());var t={variable:"v",number:"n",datetime:"d",currency:"c"};exports.defaultBaseUrl="https://api.gtx.dev",exports.defaultCacheUrl="https://cdn.gtx.dev",exports.defaultRuntimeApiUrl="https://runtime.gtx.dev",exports.getPluralForm=function(t,n,u){void 0===n&&(n=e),void 0===u&&(u=["en"]);var i=r.get("PluralRules",u).select(t),l=Math.abs(t);if(0===l&&n.includes("zero"))return"zero";if(1===l){if(n.includes("singular"))return"singular";if(n.includes("one"))return"one"}if("one"===i&&n.includes("singular"))return"singular";if(2===l){if(n.includes("dual"))return"dual";if(n.includes("two"))return"two"}return"two"===i&&n.includes("dual")?"dual":n.includes(i)?i:"two"===i&&n.includes("dual")?"dual":"two"===i&&n.includes("plural")?"plural":"two"===i&&n.includes("other")?"other":"few"===i&&n.includes("plural")?"plural":"few"===i&&n.includes("other")?"other":"many"===i&&n.includes("plural")?"plural":"many"===i&&n.includes("other")?"other":"other"===i&&n.includes("plural")?"plural":""},exports.isAcceptedPluralForm=function(r){return e.includes(r)},exports.isVariable=function(e){var r=e;if(r&&"object"==typeof r&&"string"==typeof r.k){var t=Object.keys(r);if(1===t.length)return!0;if(2===t.length){if("number"==typeof r.i)return!0;if("string"==typeof r.v)return!0}if(3===t.length&&"string"==typeof r.v&&"number"==typeof r.i)return!0}return!1},exports.libraryDefaultLocale="en",exports.minifyVariableType=function(e){return t[e]},exports.pluralForms=e;
1
+ "use strict";var e=["singular","plural","dual","zero","one","two","few","many","other"];var r=new(function(){function e(){this.cache=new Map}return e.prototype._generateKey=function(e,r,t){void 0===t&&(t={});var n=Array.isArray(r)?r.join(","):r,l=t?JSON.stringify(t,Object.keys(t).sort()):"{}";return"".concat(e,":").concat(n,":").concat(l)},e.prototype.get=function(e,r,t){void 0===t&&(t={});var n=this._generateKey(e,r,t);if(!this.cache.has(n)){var l=new Intl[e](r,t);this.cache.set(n,l)}return this.cache.get(n)},e}());exports.defaultBaseUrl="https://api.gtx.dev",exports.defaultCacheUrl="https://cdn.gtx.dev",exports.defaultRuntimeApiUrl="https://runtime.gtx.dev",exports.getPluralForm=function(t,n,l){void 0===n&&(n=e),void 0===l&&(l=["en"]);var u=r.get("PluralRules",l).select(t),a=Math.abs(t);if(0===a&&n.includes("zero"))return"zero";if(1===a){if(n.includes("singular"))return"singular";if(n.includes("one"))return"one"}if("one"===u&&n.includes("singular"))return"singular";if(2===a){if(n.includes("dual"))return"dual";if(n.includes("two"))return"two"}return"two"===u&&n.includes("dual")?"dual":n.includes(u)?u:"two"===u&&n.includes("dual")?"dual":"two"===u&&n.includes("plural")?"plural":"two"===u&&n.includes("other")?"other":"few"===u&&n.includes("plural")?"plural":"few"===u&&n.includes("other")?"other":"many"===u&&n.includes("plural")?"plural":"many"===u&&n.includes("other")?"other":"other"===u&&n.includes("plural")?"plural":""},exports.isAcceptedPluralForm=function(r){return e.includes(r)},exports.libraryDefaultLocale="en",exports.pluralForms=e;
2
2
  //# sourceMappingURL=internal.cjs.min.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"internal.cjs.min.cjs","sources":["../src/settings/settingsUrls.ts","../src/settings/plurals.ts","../src/cache/IntlCache.ts","../src/utils/minify.ts","../src/locales/getPluralForm.ts","../src/settings/settings.ts","../src/utils/isVariable.ts"],"sourcesContent":["export const defaultCacheUrl = 'https://cdn.gtx.dev' as const;\nexport const defaultBaseUrl = 'https://api.gtx.dev' as const;\nexport const defaultRuntimeApiUrl = 'https://runtime.gtx.dev' as const;\nexport const translateBatchUrl = '/v1/translate/batch' as const;\nexport const translateJsxUrl = '/v1/translate/react' as const;\nexport const translateContentUrl = '/v1/translate/content' as const;\nexport const translateIcuUrl = '/v1/translate/icu' as const;\nexport const updateProjectTranslationsUrl =\n '/v1/project/translations/update' as const;\nexport const getProjectLocalesUrl = '/v1/project/locales' as const;\n","export const pluralForms = [\n 'singular',\n 'plural',\n 'dual',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n 'other',\n] as const;\nexport type PluralType = (typeof pluralForms)[number];\nexport function isAcceptedPluralForm(form: string): form is PluralType {\n return pluralForms.includes(form as (typeof pluralForms)[number]);\n}\n","class IntlCache {\n private cache: Map<string, any>;\n\n constructor() {\n // Create separate caches for each Intl constructor\n this.cache = new Map();\n }\n\n private _generateKey(\n constructor: string,\n locales: string | string[],\n options = {}\n ) {\n // Handle both string and array locales\n const localeKey = Array.isArray(locales) ? locales.join(',') : locales;\n // Sort option keys to ensure consistent key generation\n const sortedOptions = options\n ? JSON.stringify(options, Object.keys(options).sort())\n : '{}';\n return `${constructor}:${localeKey}:${sortedOptions}`;\n }\n\n get<K extends keyof typeof Intl>(\n constructor: K,\n locales: string | string[],\n options = {}\n ): /* @ts-expect-error constructors must be valid */\n InstanceType<(typeof Intl)[K]> {\n const key = this._generateKey(constructor, locales, options);\n if (!this.cache.has(key)) {\n // Create a new Intl object if not in cache\n const intlObject = new (Intl[constructor] as any)(locales, options);\n this.cache.set(key, intlObject);\n }\n return this.cache.get(key);\n }\n}\n\nexport const intlCache = new IntlCache();\n","import { VariableTransformationSuffix, VariableType } from '../types';\n\nconst VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES = {\n variable: 'v',\n number: 'n',\n datetime: 'd',\n currency: 'c',\n} as const;\n\nexport function minifyVariableType(\n variableType: VariableTransformationSuffix\n): VariableType {\n return VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES[variableType];\n}\n","import { intlCache } from 'src/cache/IntlCache';\nimport { pluralForms, PluralType } from '../settings/plurals';\nimport { libraryDefaultLocale } from '../settings/settings';\n\n/**\n * Given a number and a list of allowed plural forms, return the plural form that best fits the number.\n *\n * @param {number} n - The number to determine the plural form for.\n * @param {locales[]} forms - The allowed plural forms.\n * @returns {PluralType} The determined plural form, or an empty string if none fit.\n */\nexport default function _getPluralForm(\n n: number,\n forms: PluralType[] = pluralForms as any,\n locales: string[] = [libraryDefaultLocale]\n): PluralType | '' {\n const pluralRules = intlCache.get('PluralRules', locales);\n const provisionalBranchName = pluralRules.select(n);\n // aliases\n const absN = Math.abs(n);\n // 0\n if (absN === 0 && forms.includes('zero')) return 'zero'; // override\n // 1\n if (absN === 1) {\n if (forms.includes('singular')) return 'singular'; // override\n if (forms.includes('one')) return 'one'; // override\n }\n if (provisionalBranchName === 'one' && forms.includes('singular'))\n return 'singular';\n // 2\n if (absN === 2) {\n if (forms.includes('dual')) return 'dual'; // override\n if (forms.includes('two')) return 'two'; // override\n }\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n // fallbacks\n if (forms.includes(provisionalBranchName)) return provisionalBranchName;\n // two\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n if (provisionalBranchName === 'two' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'two' && forms.includes('other'))\n return 'other';\n // few\n if (provisionalBranchName === 'few' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'few' && forms.includes('other'))\n return 'other';\n // many\n if (provisionalBranchName === 'many' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'many' && forms.includes('other'))\n return 'other';\n // other\n if (provisionalBranchName === 'other' && forms.includes('plural'))\n return 'plural';\n return '';\n}\n","export const libraryDefaultLocale = 'en' as const;\nexport const maxTimeout = 60000;\n","import { Variable } from '../types';\n\nexport default function isVariable(obj: unknown): obj is Variable {\n const variableObj = obj as Variable;\n if (\n variableObj &&\n typeof variableObj === 'object' &&\n typeof (variableObj as Variable).k === 'string'\n ) {\n const k = Object.keys(variableObj);\n if (k.length === 1) return true;\n if (k.length === 2) {\n if (typeof variableObj.i === 'number') return true;\n if (typeof variableObj.v === 'string') return true;\n }\n if (k.length === 3) {\n if (\n typeof variableObj.v === 'string' &&\n typeof variableObj.i === 'number'\n )\n return true;\n }\n }\n return false;\n}\n"],"names":["pluralForms","intlCache","IntlCache","this","cache","Map","prototype","_generateKey","constructor","locales","options","localeKey","Array","isArray","join","sortedOptions","JSON","stringify","Object","keys","sort","concat","get","key","has","intlObject","Intl","set","VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES","variable","number","datetime","currency","n","forms","provisionalBranchName","select","absN","Math","abs","includes","form","obj","variableObj","k","length","i","v","variableType"],"mappings":"aAAO,ICAMA,EAAc,CACzB,WACA,SACA,OACA,OACA,MACA,MACA,MACA,OACA,SCTF,IAsCaC,EAAY,IAtCzB,WAGE,SAAAC,IAEEC,KAAKC,MAAQ,IAAIC,IA+BrB,OA5BUH,EAAAI,UAAAC,aAAR,SACEC,EACAC,EACAC,QAAA,IAAAA,IAAAA,EAAY,CAAA,GAGZ,IAAMC,EAAYC,MAAMC,QAAQJ,GAAWA,EAAQK,KAAK,KAAOL,EAEzDM,EAAgBL,EAClBM,KAAKC,UAAUP,EAASQ,OAAOC,KAAKT,GAASU,QAC7C,KACJ,MAAO,UAAGZ,EAAW,KAAAa,OAAIV,EAAa,KAAAU,OAAAN,EACvC,EAEDb,EAAAI,UAAAgB,IAAA,SACEd,EACAC,EACAC,QAAA,IAAAA,IAAAA,EAAY,CAAA,GAGZ,IAAMa,EAAMpB,KAAKI,aAAaC,EAAaC,EAASC,GACpD,IAAKP,KAAKC,MAAMoB,IAAID,GAAM,CAExB,IAAME,EAAa,IAAKC,KAAKlB,GAAqBC,EAASC,GAC3DP,KAAKC,MAA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A,EAAyBC,EACjC,CACA,IAAMA,EAAI1B,OAAOC,KAAKwB,GACtB,GAAiB,IAAbC,EAAEC,OAAc,OAAO,EAC3B,GAAiB,IAAbD,EAAEC,OAAc,CAClB,GAA6B,iBAAlBF,EAAYG,EAAgB,OAAO,EAC9C,GAA6B,iBAAlBH,EAAYI,EAAgB,OAAO,EAEhD,GAAiB,IAAbH,EAAEC,QAEuB,iBAAlBF,EAAYI,GACM,iBAAlBJ,EAAYG,EAEnB,OAAO,EAGb,OAAO,CACT,+BDxBoC,gCFS9B,SACJE,GAEA,OAAOpB,EAAmDoB,EAC5D"}
1
+ {"version":3,"file":"internal.cjs.min.cjs","sources":["../src/settings/settingsUrls.ts","../src/settings/plurals.ts","../src/cache/IntlCache.ts","../src/locales/getPluralForm.ts","../src/settings/settings.ts"],"sourcesContent":["export const defaultCacheUrl = 'https://cdn.gtx.dev' as const;\nexport const defaultBaseUrl = 'https://api.gtx.dev' as const;\nexport const defaultRuntimeApiUrl = 'https://runtime.gtx.dev' as const;\nexport const translateBatchUrl = '/v1/translate/batch' as const;\nexport const translateJsxUrl = '/v1/translate/react' as const;\nexport const translateContentUrl = '/v1/translate/content' as const;\nexport const translateIcuUrl = '/v1/translate/icu' as const;\nexport const updateProjectTranslationsUrl =\n '/v1/project/translations/update' as const;\nexport const getProjectLocalesUrl = '/v1/project/locales' as const;\n","export const pluralForms = [\n 'singular',\n 'plural',\n 'dual',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n 'other',\n] as const;\nexport type PluralType = (typeof pluralForms)[number];\nexport function isAcceptedPluralForm(form: string): form is PluralType {\n return pluralForms.includes(form as (typeof pluralForms)[number]);\n}\n","class IntlCache {\n private cache: Map<string, any>;\n\n constructor() {\n // Create separate caches for each Intl constructor\n this.cache = new Map();\n }\n\n private _generateKey(\n constructor: string,\n locales: string | string[],\n options = {}\n ) {\n // Handle both string and array locales\n const localeKey = Array.isArray(locales) ? locales.join(',') : locales;\n // Sort option keys to ensure consistent key generation\n const sortedOptions = options\n ? JSON.stringify(options, Object.keys(options).sort())\n : '{}';\n return `${constructor}:${localeKey}:${sortedOptions}`;\n }\n\n get<K extends keyof typeof Intl>(\n constructor: K,\n locales: string | string[],\n options = {}\n ): /* @ts-expect-error constructors must be valid */\n InstanceType<(typeof Intl)[K]> {\n const key = this._generateKey(constructor, locales, options);\n if (!this.cache.has(key)) {\n // Create a new Intl object if not in cache\n const intlObject = new (Intl[constructor] as any)(locales, options);\n this.cache.set(key, intlObject);\n }\n return this.cache.get(key);\n }\n}\n\nexport const intlCache = new IntlCache();\n","import { intlCache } from 'src/cache/IntlCache';\nimport { pluralForms, PluralType } from '../settings/plurals';\nimport { libraryDefaultLocale } from '../settings/settings';\n\n/**\n * Given a number and a list of allowed plural forms, return the plural form that best fits the number.\n *\n * @param {number} n - The number to determine the plural form for.\n * @param {locales[]} forms - The allowed plural forms.\n * @returns {PluralType} The determined plural form, or an empty string if none fit.\n */\nexport default function _getPluralForm(\n n: number,\n forms: PluralType[] = pluralForms as any,\n locales: string[] = [libraryDefaultLocale]\n): PluralType | '' {\n const pluralRules = intlCache.get('PluralRules', locales);\n const provisionalBranchName = pluralRules.select(n);\n // aliases\n const absN = Math.abs(n);\n // 0\n if (absN === 0 && forms.includes('zero')) return 'zero'; // override\n // 1\n if (absN === 1) {\n if (forms.includes('singular')) return 'singular'; // override\n if (forms.includes('one')) return 'one'; // override\n }\n if (provisionalBranchName === 'one' && forms.includes('singular'))\n return 'singular';\n // 2\n if (absN === 2) {\n if (forms.includes('dual')) return 'dual'; // override\n if (forms.includes('two')) return 'two'; // override\n }\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n // fallbacks\n if (forms.includes(provisionalBranchName)) return provisionalBranchName;\n // two\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n if (provisionalBranchName === 'two' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'two' && forms.includes('other'))\n return 'other';\n // few\n if (provisionalBranchName === 'few' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'few' && forms.includes('other'))\n return 'other';\n // many\n if (provisionalBranchName === 'many' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'many' && forms.includes('other'))\n return 'other';\n // other\n if (provisionalBranchName === 'other' && forms.includes('plural'))\n return 'plural';\n return '';\n}\n","export const libraryDefaultLocale = 'en' as const;\nexport const maxTimeout = 60000;\n"],"names":["pluralForms","intlCache","IntlCache","this","cache","Map","prototype","_generateKey","constructor","locales","options","localeKey","Array","isArray","join","sortedOptions","JSON","stringify","Object","keys","sort","concat","get","key","has","intlObject","Intl","set","n","forms","provisionalBranchName","select","absN","Math","abs","includes","form"],"mappings":"aAAO,ICAMA,EAAc,CACzB,WACA,SACA,OACA,OACA,MACA,MACA,MACA,OACA,SCTF,IAsCaC,EAAY,IAtCzB,WAGE,SAAAC,IAEEC,KAAKC,MAAQ,IAAIC,IA+BrB,OA5BUH,EAAAI,UAAAC,aAAR,SACEC,EACAC,EACAC,QAAA,IAAAA,IAAAA,EAAY,CAAA,GAGZ,IAAMC,EAAYC,MAAMC,QAAQJ,GAAWA,EAAQK,KAAK,KAAOL,EAEzDM,EAAgBL,EAClBM,KAAKC,UAAUP,EAASQ,OAAOC,KAAKT,GAASU,QAC7C,KACJ,MAAO,UAAGZ,EAAW,KAAAa,OAAIV,EAAa,KAAAU,OAAAN,EACvC,EAEDb,EAAAI,UAAAgB,IAAA,SACEd,EACAC,EACAC,QAAA,IAAAA,IAAAA,EAAY,CAAA,GAGZ,IAAMa,EAAMpB,KAAKI,aAAaC,EAAaC,EAASC,GACpD,IAAKP,KAAKC,MAAMoB,IAAID,GAAM,CAExB,IAAME,EAAa,IAAKC,KAAKlB,GAAqBC,EAASC,GAC3DP,KAAKC,MAAMuB,IAAIJ,EAAKE,GAEtB,OAAOtB,KAAKC,MAAMkB,IAAIC,EACvB,EACFrB,CAAD,4BFnC8B,8CADC,mDAEK,gDGSZ,SACtB0B,EACAC,EACApB,QADA,IAAAoB,IAAAA,EAAsB7B,QACtB,IAAAS,IAAAA,EAAqB,CCda,ODgBlC,IACMqB,EADc7B,EAAUqB,IAAI,cAAeb,GACPsB,OAAOH,GAE3CI,EAAOC,KAAKC,IAAIN,GAEtB,GAAa,IAATI,GAAcH,EAAMM,SAAS,QAAS,MAAO,OAEjD,GAAa,IAATH,EAAY,CACd,GAAIH,EAAMM,SAAS,YAAa,MAAO,WACvC,GAAIN,EAAMM,SAAS,OAAQ,MAAO,MAEpC,GAA8B,QAA1BL,GAAmCD,EAAMM,SAAS,YACpD,MAAO,WAET,GAAa,IAATH,EAAY,CACd,GAAIH,EAAMM,SAAS,QAAS,MAAO,OACnC,GAAIN,EAAMM,SAAS,OAAQ,MAAO,MAEpC,MAA8B,QAA1BL,GAAmCD,EAAMM,SAAS,QAAgB,OAElEN,EAAMM,SAASL,GAA+BA,EAEpB,QAA1BA,GAAmCD,EAAMM,SAAS,QAAgB,OACxC,QAA1BL,GAAmCD,EAAMM,SAAS,UAC7C,SACqB,QAA1BL,GAAmCD,EAAMM,SAAS,SAC7C,QAEqB,QAA1BL,GAAmCD,EAAMM,SAAS,UAC7C,SACqB,QAA1BL,GAAmCD,EAAMM,SAAS,SAC7C,QAEqB,SAA1BL,GAAoCD,EAAMM,SAAS,UAC9C,SACqB,SAA1BL,GAAoCD,EAAMM,SAAS,SAC9C,QAEqB,UAA1BL,GAAqCD,EAAMM,SAAS,UAC/C,SACF,EACT,+BF7CM,SAA+BC,GACnC,OAAOpC,EAAYmC,SAASC,EAC9B,+BGdoC"}
@@ -1,9 +1,65 @@
1
- export { defaultBaseUrl, defaultCacheUrl, defaultRuntimeApiUrl, } from './settings/settingsUrls';
2
- export { libraryDefaultLocale } from './settings/settings';
3
- export { pluralForms, isAcceptedPluralForm } from './settings/plurals';
4
- import _getPluralForm from './locales/getPluralForm';
5
- import { Content, JsxChild, JsxChildren, JsxElement } from './types';
6
- import { LocaleProperties } from './types';
7
- import isVariable from './utils/isVariable';
8
- import { minifyVariableType } from './utils/minify';
9
- export { _getPluralForm as getPluralForm, JsxChildren, Content, JsxChild, JsxElement, LocaleProperties, isVariable, minifyVariableType, };
1
+ declare const defaultCacheUrl: "https://cdn.gtx.dev";
2
+ declare const defaultBaseUrl: "https://api.gtx.dev";
3
+ declare const defaultRuntimeApiUrl: "https://runtime.gtx.dev";
4
+
5
+ declare const libraryDefaultLocale: "en";
6
+
7
+ declare const pluralForms: readonly ["singular", "plural", "dual", "zero", "one", "two", "few", "many", "other"];
8
+ type PluralType = (typeof pluralForms)[number];
9
+ declare function isAcceptedPluralForm(form: string): form is PluralType;
10
+
11
+ /**
12
+ * Given a number and a list of allowed plural forms, return the plural form that best fits the number.
13
+ *
14
+ * @param {number} n - The number to determine the plural form for.
15
+ * @param {locales[]} forms - The allowed plural forms.
16
+ * @returns {PluralType} The determined plural form, or an empty string if none fit.
17
+ */
18
+ declare function _getPluralForm(n: number, forms?: PluralType[], locales?: string[]): PluralType | '';
19
+
20
+ type LocaleProperties = {
21
+ code: string;
22
+ name: string;
23
+ nativeName: string;
24
+ languageCode: string;
25
+ languageName: string;
26
+ nativeLanguageName: string;
27
+ nameWithRegionCode: string;
28
+ nativeNameWithRegionCode: string;
29
+ regionCode: string;
30
+ regionName: string;
31
+ nativeRegionName: string;
32
+ scriptCode: string;
33
+ scriptName: string;
34
+ nativeScriptName: string;
35
+ maximizedCode: string;
36
+ maximizedName: string;
37
+ nativeMaximizedName: string;
38
+ minimizedCode: string;
39
+ minimizedName: string;
40
+ nativeMinimizedName: string;
41
+ emoji: string;
42
+ };
43
+
44
+ type Variable = {
45
+ variable?: string;
46
+ id?: string | number;
47
+ key: string;
48
+ };
49
+ type Content = string | Array<string | Variable>;
50
+ type JsxElement = {
51
+ type: string;
52
+ props: {
53
+ 'data-_gt'?: {
54
+ id: number;
55
+ transformation?: string;
56
+ branches?: Record<string, JsxChildren>;
57
+ };
58
+ children?: JsxChildren;
59
+ };
60
+ };
61
+ type JsxChild = string | JsxElement | Variable;
62
+ type JsxChildren = JsxChild | JsxChild[];
63
+
64
+ export { defaultBaseUrl, defaultCacheUrl, defaultRuntimeApiUrl, _getPluralForm as getPluralForm, isAcceptedPluralForm, libraryDefaultLocale, pluralForms };
65
+ export type { Content, JsxChild, JsxChildren, JsxElement, LocaleProperties };
@@ -1,2 +1,2 @@
1
- var e="https://cdn.gtx.dev",r="https://api.gtx.dev",t="https://runtime.gtx.dev",n="en",u=["singular","plural","dual","zero","one","two","few","many","other"];function i(e){return u.includes(e)}var l=new(function(){function e(){this.cache=new Map}return e.prototype._generateKey=function(e,r,t){void 0===t&&(t={});var n=Array.isArray(r)?r.join(","):r,u=t?JSON.stringify(t,Object.keys(t).sort()):"{}";return"".concat(e,":").concat(n,":").concat(u)},e.prototype.get=function(e,r,t){void 0===t&&(t={});var n=this._generateKey(e,r,t);if(!this.cache.has(n)){var u=new Intl[e](r,t);this.cache.set(n,u)}return this.cache.get(n)},e}());function a(e,r,t){void 0===r&&(r=u),void 0===t&&(t=["en"]);var n=l.get("PluralRules",t).select(e),i=Math.abs(e);if(0===i&&r.includes("zero"))return"zero";if(1===i){if(r.includes("singular"))return"singular";if(r.includes("one"))return"one"}if("one"===n&&r.includes("singular"))return"singular";if(2===i){if(r.includes("dual"))return"dual";if(r.includes("two"))return"two"}return"two"===n&&r.includes("dual")?"dual":r.includes(n)?n:"two"===n&&r.includes("dual")?"dual":"two"===n&&r.includes("plural")?"plural":"two"===n&&r.includes("other")?"other":"few"===n&&r.includes("plural")?"plural":"few"===n&&r.includes("other")?"other":"many"===n&&r.includes("plural")?"plural":"many"===n&&r.includes("other")?"other":"other"===n&&r.includes("plural")?"plural":""}function o(e){var r=e;if(r&&"object"==typeof r&&"string"==typeof r.k){var t=Object.keys(r);if(1===t.length)return!0;if(2===t.length){if("number"==typeof r.i)return!0;if("string"==typeof r.v)return!0}if(3===t.length&&"string"==typeof r.v&&"number"==typeof r.i)return!0}return!1}var c={variable:"v",number:"n",datetime:"d",currency:"c"};function s(e){return c[e]}export{r as defaultBaseUrl,e as defaultCacheUrl,t as defaultRuntimeApiUrl,a as getPluralForm,i as isAcceptedPluralForm,o as isVariable,n as libraryDefaultLocale,s as minifyVariableType,u as pluralForms};
1
+ var e="https://cdn.gtx.dev",r="https://api.gtx.dev",t="https://runtime.gtx.dev",n="en",u=["singular","plural","dual","zero","one","two","few","many","other"];function l(e){return u.includes(e)}var i=new(function(){function e(){this.cache=new Map}return e.prototype._generateKey=function(e,r,t){void 0===t&&(t={});var n=Array.isArray(r)?r.join(","):r,u=t?JSON.stringify(t,Object.keys(t).sort()):"{}";return"".concat(e,":").concat(n,":").concat(u)},e.prototype.get=function(e,r,t){void 0===t&&(t={});var n=this._generateKey(e,r,t);if(!this.cache.has(n)){var u=new Intl[e](r,t);this.cache.set(n,u)}return this.cache.get(n)},e}());function a(e,r,t){void 0===r&&(r=u),void 0===t&&(t=["en"]);var n=i.get("PluralRules",t).select(e),l=Math.abs(e);if(0===l&&r.includes("zero"))return"zero";if(1===l){if(r.includes("singular"))return"singular";if(r.includes("one"))return"one"}if("one"===n&&r.includes("singular"))return"singular";if(2===l){if(r.includes("dual"))return"dual";if(r.includes("two"))return"two"}return"two"===n&&r.includes("dual")?"dual":r.includes(n)?n:"two"===n&&r.includes("dual")?"dual":"two"===n&&r.includes("plural")?"plural":"two"===n&&r.includes("other")?"other":"few"===n&&r.includes("plural")?"plural":"few"===n&&r.includes("other")?"other":"many"===n&&r.includes("plural")?"plural":"many"===n&&r.includes("other")?"other":"other"===n&&r.includes("plural")?"plural":""}export{r as defaultBaseUrl,e as defaultCacheUrl,t as defaultRuntimeApiUrl,a as getPluralForm,l as isAcceptedPluralForm,n as libraryDefaultLocale,u as pluralForms};
2
2
  //# sourceMappingURL=internal.esm.min.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"internal.esm.min.mjs","sources":["../src/settings/settingsUrls.ts","../src/settings/settings.ts","../src/settings/plurals.ts","../src/cache/IntlCache.ts","../src/locales/getPluralForm.ts","../src/utils/isVariable.ts","../src/utils/minify.ts"],"sourcesContent":["export const defaultCacheUrl = 'https://cdn.gtx.dev' as const;\nexport const defaultBaseUrl = 'https://api.gtx.dev' as const;\nexport const defaultRuntimeApiUrl = 'https://runtime.gtx.dev' as const;\nexport const translateBatchUrl = '/v1/translate/batch' as const;\nexport const translateJsxUrl = '/v1/translate/react' as const;\nexport const translateContentUrl = '/v1/translate/content' as const;\nexport const translateIcuUrl = '/v1/translate/icu' as const;\nexport const updateProjectTranslationsUrl =\n '/v1/project/translations/update' as const;\nexport const getProjectLocalesUrl = '/v1/project/locales' as const;\n","export const libraryDefaultLocale = 'en' as const;\nexport const maxTimeout = 60000;\n","export const pluralForms = [\n 'singular',\n 'plural',\n 'dual',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n 'other',\n] as const;\nexport type PluralType = (typeof pluralForms)[number];\nexport function isAcceptedPluralForm(form: string): form is PluralType {\n return pluralForms.includes(form as (typeof pluralForms)[number]);\n}\n","class IntlCache {\n private cache: Map<string, any>;\n\n constructor() {\n // Create separate caches for each Intl constructor\n this.cache = new Map();\n }\n\n private _generateKey(\n constructor: string,\n locales: string | string[],\n options = {}\n ) {\n // Handle both string and array locales\n const localeKey = Array.isArray(locales) ? locales.join(',') : locales;\n // Sort option keys to ensure consistent key generation\n const sortedOptions = options\n ? JSON.stringify(options, Object.keys(options).sort())\n : '{}';\n return `${constructor}:${localeKey}:${sortedOptions}`;\n }\n\n get<K extends keyof typeof Intl>(\n constructor: K,\n locales: string | string[],\n options = {}\n ): /* @ts-expect-error constructors must be valid */\n InstanceType<(typeof Intl)[K]> {\n const key = this._generateKey(constructor, locales, options);\n if (!this.cache.has(key)) {\n // Create a new Intl object if not in cache\n const intlObject = new (Intl[constructor] as any)(locales, options);\n this.cache.set(key, intlObject);\n }\n return this.cache.get(key);\n }\n}\n\nexport const intlCache = new IntlCache();\n","import { intlCache } from 'src/cache/IntlCache';\nimport { pluralForms, PluralType } from '../settings/plurals';\nimport { libraryDefaultLocale } from '../settings/settings';\n\n/**\n * Given a number and a list of allowed plural forms, return the plural form that best fits the number.\n *\n * @param {number} n - The number to determine the plural form for.\n * @param {locales[]} forms - The allowed plural forms.\n * @returns {PluralType} The determined plural form, or an empty string if none fit.\n */\nexport default function _getPluralForm(\n n: number,\n forms: PluralType[] = pluralForms as any,\n locales: string[] = [libraryDefaultLocale]\n): PluralType | '' {\n const pluralRules = intlCache.get('PluralRules', locales);\n const provisionalBranchName = pluralRules.select(n);\n // aliases\n const absN = Math.abs(n);\n // 0\n if (absN === 0 && forms.includes('zero')) return 'zero'; // override\n // 1\n if (absN === 1) {\n if (forms.includes('singular')) return 'singular'; // override\n if (forms.includes('one')) return 'one'; // override\n }\n if (provisionalBranchName === 'one' && forms.includes('singular'))\n return 'singular';\n // 2\n if (absN === 2) {\n if (forms.includes('dual')) return 'dual'; // override\n if (forms.includes('two')) return 'two'; // override\n }\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n // fallbacks\n if (forms.includes(provisionalBranchName)) return provisionalBranchName;\n // two\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n if (provisionalBranchName === 'two' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'two' && forms.includes('other'))\n return 'other';\n // few\n if (provisionalBranchName === 'few' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'few' && forms.includes('other'))\n return 'other';\n // many\n if (provisionalBranchName === 'many' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'many' && forms.includes('other'))\n return 'other';\n // other\n if (provisionalBranchName === 'other' && forms.includes('plural'))\n return 'plural';\n return '';\n}\n","import { Variable } from '../types';\n\nexport default function isVariable(obj: unknown): obj is Variable {\n const variableObj = obj as Variable;\n if (\n variableObj &&\n typeof variableObj === 'object' &&\n typeof (variableObj as Variable).k === 'string'\n ) {\n const k = Object.keys(variableObj);\n if (k.length === 1) return true;\n if (k.length === 2) {\n if (typeof variableObj.i === 'number') return true;\n if (typeof variableObj.v === 'string') return true;\n }\n if (k.length === 3) {\n if (\n typeof variableObj.v === 'string' &&\n typeof variableObj.i === 'number'\n )\n return true;\n }\n }\n return false;\n}\n","import { VariableTransformationSuffix, VariableType } from '../types';\n\nconst VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES = {\n variable: 'v',\n number: 'n',\n datetime: 'd',\n currency: 'c',\n} as const;\n\nexport function minifyVariableType(\n variableType: VariableTransformationSuffix\n): VariableType {\n return VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES[variableType];\n}\n"],"names":["defaultCacheUrl","defaultBaseUrl","defaultRuntimeApiUrl","libraryDefaultLocale","pluralForms","isAcceptedPluralForm","form","includes","intlCache","IntlCache","this","cache","Map","prototype","_generateKey","constructor","locales","options","localeKey","Array","isArray","join","sortedOptions","JSON","stringify","Object","keys","sort","concat","get","key","has","intlObject","Intl","set","_getPluralForm","n","forms","provisionalBranchName","select","absN","Math","abs","isVariable","obj","variableObj","k","length","i","v","VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES","variable","number","datetime","currency","minifyVariableType","variableType"],"mappings":"AAAO,IAAMA,EAAkB,sBAClBC,EAAiB,sBACjBC,EAAuB,0BCFvBC,EAAuB,KCAvBC,EAAc,CACzB,WACA,SACA,OACA,OACA,MACA,MACA,MACA,OACA,SAGI,SAAUC,EAAqBC,GACnC,OAAOF,EAAYG,SAASD,EAC9B,CCdA,IAsCaE,EAAY,IAtCzB,WAGE,SAAAC,IAEEC,KAAKC,MAAQ,IAAIC,IA+BrB,OA5BUH,EAAAI,UAAAC,aAAR,SACEC,EACAC,EACAC,QAAA,IAAAA,IAAAA,EAAY,CAAA,GAGZ,IAAMC,EAAYC,MAAMC,QAAQJ,GAAWA,EAAQK,KAAK,KAAOL,EAEzDM,EAAgBL,EAClBM,KAAKC,UAAUP,EAASQ,OAAOC,KAAKT,GAASU,QAC7C,KACJ,MAAO,UAAGZ,EAAW,KA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ACqB,SAA1B+B,GAAoCD,EAAM9B,SAAS,SAC9C,QAEqB,UAA1B+B,GAAqCD,EAAM9B,SAAS,UAC/C,SACF,EACT,CCvDwB,SAAAoC,EAAWC,GACjC,IAAMC,EAAcD,EACpB,GACEC,GACuB,iBAAhBA,GACgC,iBAA/BA,EAAyBC,EACjC,CACA,IAAMA,EAAIrB,OAAOC,KAAKmB,GACtB,GAAiB,IAAbC,EAAEC,OAAc,OAAO,EAC3B,GAAiB,IAAbD,EAAEC,OAAc,CAClB,GAA6B,iBAAlBF,EAAYG,EAAgB,OAAO,EAC9C,GAA6B,iBAAlBH,EAAYI,EAAgB,OAAO,EAEhD,GAAiB,IAAbH,EAAEC,QAEuB,iBAAlBF,EAAYI,GACM,iBAAlBJ,EAAYG,EAEnB,OAAO,EAGb,OAAO,CACT,CCtBA,IAAME,EAAqD,CACzDC,SAAU,IACVC,OAAQ,IACRC,SAAU,IACVC,SAAU,KAGN,SAAUC,EACdC,GAEA,OAAON,EAAmDM,EAC5D"}
1
+ {"version":3,"file":"internal.esm.min.mjs","sources":["../src/settings/settingsUrls.ts","../src/settings/settings.ts","../src/settings/plurals.ts","../src/cache/IntlCache.ts","../src/locales/getPluralForm.ts"],"sourcesContent":["export const defaultCacheUrl = 'https://cdn.gtx.dev' as const;\nexport const defaultBaseUrl = 'https://api.gtx.dev' as const;\nexport const defaultRuntimeApiUrl = 'https://runtime.gtx.dev' as const;\nexport const translateBatchUrl = '/v1/translate/batch' as const;\nexport const translateJsxUrl = '/v1/translate/react' as const;\nexport const translateContentUrl = '/v1/translate/content' as const;\nexport const translateIcuUrl = '/v1/translate/icu' as const;\nexport const updateProjectTranslationsUrl =\n '/v1/project/translations/update' as const;\nexport const getProjectLocalesUrl = '/v1/project/locales' as const;\n","export const libraryDefaultLocale = 'en' as const;\nexport const maxTimeout = 60000;\n","export const pluralForms = [\n 'singular',\n 'plural',\n 'dual',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n 'other',\n] as const;\nexport type PluralType = (typeof pluralForms)[number];\nexport function isAcceptedPluralForm(form: string): form is PluralType {\n return pluralForms.includes(form as (typeof pluralForms)[number]);\n}\n","class IntlCache {\n private cache: Map<string, any>;\n\n constructor() {\n // Create separate caches for each Intl constructor\n this.cache = new Map();\n }\n\n private _generateKey(\n constructor: string,\n locales: string | string[],\n options = {}\n ) {\n // Handle both string and array locales\n const localeKey = Array.isArray(locales) ? locales.join(',') : locales;\n // Sort option keys to ensure consistent key generation\n const sortedOptions = options\n ? JSON.stringify(options, Object.keys(options).sort())\n : '{}';\n return `${constructor}:${localeKey}:${sortedOptions}`;\n }\n\n get<K extends keyof typeof Intl>(\n constructor: K,\n locales: string | string[],\n options = {}\n ): /* @ts-expect-error constructors must be valid */\n InstanceType<(typeof Intl)[K]> {\n const key = this._generateKey(constructor, locales, options);\n if (!this.cache.has(key)) {\n // Create a new Intl object if not in cache\n const intlObject = new (Intl[constructor] as any)(locales, options);\n this.cache.set(key, intlObject);\n }\n return this.cache.get(key);\n }\n}\n\nexport const intlCache = new IntlCache();\n","import { intlCache } from 'src/cache/IntlCache';\nimport { pluralForms, PluralType } from '../settings/plurals';\nimport { libraryDefaultLocale } from '../settings/settings';\n\n/**\n * Given a number and a list of allowed plural forms, return the plural form that best fits the number.\n *\n * @param {number} n - The number to determine the plural form for.\n * @param {locales[]} forms - The allowed plural forms.\n * @returns {PluralType} The determined plural form, or an empty string if none fit.\n */\nexport default function _getPluralForm(\n n: number,\n forms: PluralType[] = pluralForms as any,\n locales: string[] = [libraryDefaultLocale]\n): PluralType | '' {\n const pluralRules = intlCache.get('PluralRules', locales);\n const provisionalBranchName = pluralRules.select(n);\n // aliases\n const absN = Math.abs(n);\n // 0\n if (absN === 0 && forms.includes('zero')) return 'zero'; // override\n // 1\n if (absN === 1) {\n if (forms.includes('singular')) return 'singular'; // override\n if (forms.includes('one')) return 'one'; // override\n }\n if (provisionalBranchName === 'one' && forms.includes('singular'))\n return 'singular';\n // 2\n if (absN === 2) {\n if (forms.includes('dual')) return 'dual'; // override\n if (forms.includes('two')) return 'two'; // override\n }\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n // fallbacks\n if (forms.includes(provisionalBranchName)) return provisionalBranchName;\n // two\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n if (provisionalBranchName === 'two' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'two' && forms.includes('other'))\n return 'other';\n // few\n if (provisionalBranchName === 'few' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'few' && forms.includes('other'))\n return 'other';\n // many\n if (provisionalBranchName === 'many' && forms.includes('plural'))\n return 'plural';\n if (provisionalBranchName === 'many' && forms.includes('other'))\n return 'other';\n // other\n if (provisionalBranchName === 'other' && forms.includes('plural'))\n return 'plural';\n return '';\n}\n"],"names":["defaultCacheUrl","defaultBaseUrl","defaultRuntimeApiUrl","libraryDefaultLocale","pluralForms","isAcceptedPluralForm","form","includes","intlCache","IntlCache","this","cache","Map","prototype","_generateKey","constructor","locales","options","localeKey","Array","isArray","join","sortedOptions","JSON","stringify","Object","keys","sort","concat","get","key","has","intlObject","Intl","set","_getPluralForm","n","forms","provisionalBranchName","select","absN","Math","abs"],"mappings":"AAAO,IAAMA,EAAkB,sBAClBC,EAAiB,sBACjBC,EAAuB,0BCFvBC,EAAuB,KCAvBC,EAAc,CACzB,WACA,SACA,OACA,OACA,MACA,MACA,MACA,OACA,SAGI,SAAUC,EAAqBC,GACnC,OAAOF,EAAYG,SAASD,EAC9B,CCdA,IAsCaE,EAAY,IAtCzB,WAGE,SAAAC,IAEEC,KAAKC,MAAQ,IAAIC,IA+BrB,OA5BUH,EAAAI,UAAAC,aAAR,SACEC,EACAC,EACAC,QAAA,IAAAA,IAAAA,EAAY,CAAA,GAGZ,IAAMC,EAAYC,MAAMC,QAAQJ,GAAWA,EAAQK,KAAK,KAAOL,EAEzDM,EAAgBL,EAClBM,KAAKC,UAAUP,EAASQ,OAAOC,KAAKT,GAAS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A1B+B,GAAoCD,EAAM9B,SAAS,UAC9C,SACqB,SAA1B+B,GAAoCD,EAAM9B,SAAS,SAC9C,QAEqB,UAA1B+B,GAAqCD,EAAM9B,SAAS,UAC/C,SACF,EACT"}
package/dist/types.d.ts CHANGED
@@ -1,77 +1,33 @@
1
- type LocaleProperties = {
2
- code: string;
3
- name: string;
4
- nativeName: string;
5
- languageCode: string;
6
- languageName: string;
7
- nativeLanguageName: string;
8
- nameWithRegionCode: string;
9
- nativeNameWithRegionCode: string;
10
- regionCode: string;
11
- regionName: string;
12
- nativeRegionName: string;
13
- scriptCode: string;
14
- scriptName: string;
15
- nativeScriptName: string;
16
- maximizedCode: string;
17
- maximizedName: string;
18
- nativeMaximizedName: string;
19
- minimizedCode: string;
20
- minimizedName: string;
21
- nativeMinimizedName: string;
22
- emoji: string;
1
+ import { LocaleProperties } from './locales/getLocaleProperties';
2
+ export { LocaleProperties };
3
+ export type Variable = {
4
+ variable?: string;
5
+ id?: string | number;
6
+ key: string;
23
7
  };
24
-
25
- type CustomMapping = Record<string, string | Partial<LocaleProperties>>;
26
-
27
- type Content = string | Array<string | Variable>;
28
- /**
29
- * Map of data-_gt properties to their corresponding React props
30
- */
31
- declare const HTML_CONTENT_PROPS: {
32
- readonly pl: "placeholder";
33
- readonly ti: "title";
34
- readonly alt: "alt";
35
- readonly arl: "aria-label";
36
- readonly arb: "aria-labelledby";
37
- readonly ard: "aria-describedby";
38
- };
39
- type HtmlContentPropKeysRecord = Partial<Record<keyof typeof HTML_CONTENT_PROPS, string>>;
40
- type HtmlContentPropValuesRecord = Partial<Record<(typeof HTML_CONTENT_PROPS)[keyof typeof HTML_CONTENT_PROPS], string>>;
41
- /**
42
- * Transformations are made from a prefix and a suffix.
43
- */
44
- type Transformation = 'translate-client' | 'translate-server' | 'variable-variable' | 'variable-currency' | 'variable-datetime' | 'variable-number' | 'plural' | 'branch';
45
- type TransformationPrefix = 'translate' | 'variable' | 'plural' | 'branch' | 'fragment';
46
- type VariableTransformationSuffix = 'variable' | 'number' | 'datetime' | 'currency';
47
- /**
48
- * GTProp is an internal property used to contain data for translating and rendering elements.
49
- * note, transformations are only read on the server side if they are 'plural' or 'branch'
50
- */
51
- type GTProp = {
52
- b?: Record<string, JsxChildren>;
53
- t?: 'p' | 'b';
54
- } & HtmlContentPropKeysRecord;
55
- type JsxElement = {
8
+ export type Content = string | Array<string | Variable>;
9
+ export type JsxElement = {
56
10
  type: string;
57
- i?: number;
58
11
  props: {
59
- d?: GTProp;
12
+ 'data-_gt'?: {
13
+ id: number;
14
+ transformation?: string;
15
+ branches?: Record<string, JsxChildren>;
16
+ };
60
17
  children?: JsxChildren;
61
18
  };
62
19
  };
63
- type JsxChild = string | JsxElement | Variable;
64
- type JsxChildren = JsxChild | JsxChild[];
65
- type Metadata = {
20
+ export type JsxChild = string | JsxElement | Variable;
21
+ export type JsxChildren = JsxChild | JsxChild[];
22
+ export type Metadata = {
66
23
  context?: string;
67
24
  id?: string;
68
25
  sourceLocale?: string;
69
26
  actionType?: 'standard' | 'fast' | string;
70
27
  [key: string]: any;
71
28
  };
72
- type DataFormat = 'JSX' | 'ICU' | 'I18NEXT';
73
- type FormatVariables = Record<string, string | number | boolean | null | undefined | Date>;
74
- type Update = {
29
+ export type FormatVariables = Record<string, string | number | boolean | null | undefined | Date>;
30
+ export type Update = {
75
31
  type: 'content';
76
32
  data: {
77
33
  source: Content;
@@ -84,7 +40,7 @@ type Update = {
84
40
  metadata: Metadata;
85
41
  };
86
42
  };
87
- type Request = {
43
+ export type Request = {
88
44
  type: 'content';
89
45
  data: {
90
46
  source: Content;
@@ -99,7 +55,7 @@ type Request = {
99
55
  metadata: Metadata;
100
56
  };
101
57
  };
102
- type ContentTranslationResult = {
58
+ export type ContentTranslationResult = {
103
59
  translation: Content;
104
60
  locale: string;
105
61
  reference?: {
@@ -107,7 +63,7 @@ type ContentTranslationResult = {
107
63
  key: string;
108
64
  };
109
65
  };
110
- type IcuTranslationResult = {
66
+ export type IcuTranslationResult = {
111
67
  translation: string;
112
68
  locale: string;
113
69
  reference?: {
@@ -115,7 +71,7 @@ type IcuTranslationResult = {
115
71
  key: string;
116
72
  };
117
73
  };
118
- type JsxTranslationResult = {
74
+ export type JsxTranslationResult = {
119
75
  translation: JsxChildren;
120
76
  locale: string;
121
77
  reference?: {
@@ -123,7 +79,7 @@ type JsxTranslationResult = {
123
79
  key: string;
124
80
  };
125
81
  };
126
- type TranslationError = {
82
+ export type TranslationError = {
127
83
  error: string;
128
84
  code: number;
129
85
  reference?: {
@@ -131,16 +87,4 @@ type TranslationError = {
131
87
  key: string;
132
88
  };
133
89
  };
134
-
135
- type VariableType = 'v' | 'n' | 'd' | 'c';
136
- /**
137
- * Variables are used to store the variable name and type.
138
- */
139
- type Variable = {
140
- k: string;
141
- i?: number;
142
- v?: VariableType;
143
- };
144
-
145
- export { HTML_CONTENT_PROPS };
146
- export type { Content, ContentTranslationResult, CustomMapping, DataFormat, FormatVariables, GTProp, HtmlContentPropKeysRecord, HtmlContentPropValuesRecord, IcuTranslationResult, JsxChild, JsxChildren, JsxElement, JsxTranslationResult, LocaleProperties, Metadata, Request, Transformation, TransformationPrefix, TranslationError, Update, Variable, VariableTransformationSuffix, VariableType };
90
+ export type { CustomMapping } from './locales/customLocaleMapping';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generaltranslation",
3
- "version": "7.0.0-alpha.19",
3
+ "version": "7.0.0-alpha.2",
4
4
  "description": "A language toolkit for AI developers",
5
5
  "main": "dist/index.cjs.min.cjs",
6
6
  "module": "dist/index.esm.min.mjs",
@@ -1,2 +0,0 @@
1
- "use strict";exports.HTML_CONTENT_PROPS={pl:"placeholder",ti:"title",alt:"alt",arl:"aria-label",arb:"aria-labelledby",ard:"aria-describedby"};
2
- //# sourceMappingURL=types.cjs.min.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.cjs.min.cjs","sources":["../src/types.ts"],"sourcesContent":["import { LocaleProperties } from './locales/getLocaleProperties';\n\nexport { LocaleProperties };\n\nexport type Content = string | Array<string | Variable>;\n\n/**\n * Map of data-_gt properties to their corresponding React props\n */\nexport const HTML_CONTENT_PROPS = {\n pl: 'placeholder',\n ti: 'title',\n alt: 'alt',\n arl: 'aria-label',\n arb: 'aria-labelledby',\n ard: 'aria-describedby',\n} as const;\n\nexport type HtmlContentPropKeysRecord = Partial<\n Record<keyof typeof HTML_CONTENT_PROPS, string>\n>;\nexport type HtmlContentPropValuesRecord = Partial<\n Record<(typeof HTML_CONTENT_PROPS)[keyof typeof HTML_CONTENT_PROPS], string>\n>;\n\n/**\n * Transformations are made from a prefix and a suffix.\n */\nexport type Transformation =\n | 'translate-client'\n | 'translate-server'\n | 'variable-variable'\n | 'variable-currency'\n | 'variable-datetime'\n | 'variable-number'\n | 'plural'\n | 'branch';\nexport type TransformationPrefix =\n | 'translate'\n | 'variable'\n | 'plural'\n | 'branch'\n | 'fragment';\nexport type VariableTransformationSuffix =\n | 'variable'\n | 'number'\n | 'datetime'\n | 'currency';\n\n/**\n * GTProp is an internal property used to contain data for translating and rendering elements.\n * note, transformations are only read on the server side if they are 'plural' or 'branch'\n */\nexport type GTProp = {\n b?: Record<string, JsxChildren>; // Branches\n t?: 'p' | 'b'; // Branch Transformation\n} & HtmlContentPropKeysRecord;\n\nexport type JsxElement = {\n type: string;\n i?: number; // id\n props: {\n d?: GTProp;\n children?: JsxChildren;\n };\n};\n\nexport type JsxChild = string | JsxElement | Variable;\nexport type JsxChildren = JsxChild | JsxChild[];\n\nexport type Metadata = {\n context?: string;\n id?: string;\n sourceLocale?: string;\n actionType?: 'standard' | 'fast' | string;\n [key: string]: any;\n};\n\nexport type DataFormat = 'JSX' | 'ICU' | 'I18NEXT';\n\nexport type FormatVariables = Record<\n string,\n string | number | boolean | null | undefined | Date\n>;\n\nexport type Update =\n | {\n type: 'content';\n data: {\n source: Content;\n metadata: Metadata;\n };\n }\n | {\n type: 'jsx';\n data: {\n source: JsxChildren;\n metadata: Metadata;\n };\n };\n\nexport type Request =\n | {\n type: 'content';\n data: {\n source: Content;\n targetLocale: string;\n metadata: Metadata;\n };\n }\n | {\n type: 'jsx';\n data: {\n source: JsxChildren;\n targetLocale: string;\n metadata: Metadata;\n };\n };\n\nexport type ContentTranslationResult = {\n translation: Content;\n locale: string;\n reference?: {\n id: string;\n key: string;\n };\n};\n\nexport type IcuTranslationResult = {\n translation: string;\n locale: string;\n reference?: {\n id: string;\n key: string;\n };\n};\n\nexport type JsxTranslationResult = {\n translation: JsxChildren;\n locale: string;\n reference?: {\n id: string;\n key: string;\n };\n};\n\nexport type TranslationError = {\n error: string;\n code: number;\n reference?: {\n id: string;\n key: string;\n };\n};\n\nexport type { CustomMapping } from './locales/customLocaleMapping';\n\n// ----- VARIABLES ----- //\n\nexport type VariableType =\n | 'v' // Variable\n | 'n' // Number\n | 'd' // Date\n | 'c'; // Currency\n\n/**\n * Variables are used to store the variable name and type.\n */\nexport type Variable = {\n k: string;\n i?: number;\n v?: VariableType;\n};\n"],"names":["pl","ti","alt","arl","arb","ard"],"mappings":"wCASkC,CAChCA,GAAI,cACJC,GAAI,QACJC,IAAK,MACLC,IAAK,aACLC,IAAK,kBACLC,IAAK"}
@@ -1,2 +0,0 @@
1
- var a={pl:"placeholder",ti:"title",alt:"alt",arl:"aria-label",arb:"aria-labelledby",ard:"aria-describedby"};export{a as HTML_CONTENT_PROPS};
2
- //# sourceMappingURL=types.esm.min.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.esm.min.mjs","sources":["../src/types.ts"],"sourcesContent":["import { LocaleProperties } from './locales/getLocaleProperties';\n\nexport { LocaleProperties };\n\nexport type Content = string | Array<string | Variable>;\n\n/**\n * Map of data-_gt properties to their corresponding React props\n */\nexport const HTML_CONTENT_PROPS = {\n pl: 'placeholder',\n ti: 'title',\n alt: 'alt',\n arl: 'aria-label',\n arb: 'aria-labelledby',\n ard: 'aria-describedby',\n} as const;\n\nexport type HtmlContentPropKeysRecord = Partial<\n Record<keyof typeof HTML_CONTENT_PROPS, string>\n>;\nexport type HtmlContentPropValuesRecord = Partial<\n Record<(typeof HTML_CONTENT_PROPS)[keyof typeof HTML_CONTENT_PROPS], string>\n>;\n\n/**\n * Transformations are made from a prefix and a suffix.\n */\nexport type Transformation =\n | 'translate-client'\n | 'translate-server'\n | 'variable-variable'\n | 'variable-currency'\n | 'variable-datetime'\n | 'variable-number'\n | 'plural'\n | 'branch';\nexport type TransformationPrefix =\n | 'translate'\n | 'variable'\n | 'plural'\n | 'branch'\n | 'fragment';\nexport type VariableTransformationSuffix =\n | 'variable'\n | 'number'\n | 'datetime'\n | 'currency';\n\n/**\n * GTProp is an internal property used to contain data for translating and rendering elements.\n * note, transformations are only read on the server side if they are 'plural' or 'branch'\n */\nexport type GTProp = {\n b?: Record<string, JsxChildren>; // Branches\n t?: 'p' | 'b'; // Branch Transformation\n} & HtmlContentPropKeysRecord;\n\nexport type JsxElement = {\n type: string;\n i?: number; // id\n props: {\n d?: GTProp;\n children?: JsxChildren;\n };\n};\n\nexport type JsxChild = string | JsxElement | Variable;\nexport type JsxChildren = JsxChild | JsxChild[];\n\nexport type Metadata = {\n context?: string;\n id?: string;\n sourceLocale?: string;\n actionType?: 'standard' | 'fast' | string;\n [key: string]: any;\n};\n\nexport type DataFormat = 'JSX' | 'ICU' | 'I18NEXT';\n\nexport type FormatVariables = Record<\n string,\n string | number | boolean | null | undefined | Date\n>;\n\nexport type Update =\n | {\n type: 'content';\n data: {\n source: Content;\n metadata: Metadata;\n };\n }\n | {\n type: 'jsx';\n data: {\n source: JsxChildren;\n metadata: Metadata;\n };\n };\n\nexport type Request =\n | {\n type: 'content';\n data: {\n source: Content;\n targetLocale: string;\n metadata: Metadata;\n };\n }\n | {\n type: 'jsx';\n data: {\n source: JsxChildren;\n targetLocale: string;\n metadata: Metadata;\n };\n };\n\nexport type ContentTranslationResult = {\n translation: Content;\n locale: string;\n reference?: {\n id: string;\n key: string;\n };\n};\n\nexport type IcuTranslationResult = {\n translation: string;\n locale: string;\n reference?: {\n id: string;\n key: string;\n };\n};\n\nexport type JsxTranslationResult = {\n translation: JsxChildren;\n locale: string;\n reference?: {\n id: string;\n key: string;\n };\n};\n\nexport type TranslationError = {\n error: string;\n code: number;\n reference?: {\n id: string;\n key: string;\n };\n};\n\nexport type { CustomMapping } from './locales/customLocaleMapping';\n\n// ----- VARIABLES ----- //\n\nexport type VariableType =\n | 'v' // Variable\n | 'n' // Number\n | 'd' // Date\n | 'c'; // Currency\n\n/**\n * Variables are used to store the variable name and type.\n */\nexport type Variable = {\n k: string;\n i?: number;\n v?: VariableType;\n};\n"],"names":["HTML_CONTENT_PROPS","pl","ti","alt","arl","arb","ard"],"mappings":"AASa,IAAAA,EAAqB,CAChCC,GAAI,cACJC,GAAI,QACJC,IAAK,MACLC,IAAK,aACLC,IAAK,kBACLC,IAAK"}
@@ -1,2 +0,0 @@
1
- import { Variable } from '../types';
2
- export default function isVariable(obj: unknown): obj is Variable;
@@ -1,2 +0,0 @@
1
- import { VariableTransformationSuffix, VariableType } from '../types';
2
- export declare function minifyVariableType(variableType: VariableTransformationSuffix): VariableType;