gt-react-native 0.0.1-alpha.10 → 0.0.1-alpha.11

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,6 +1,5 @@
1
1
  "use strict";
2
2
 
3
- import "./utils/polyfill.js";
4
3
  import GtReactNative from "./NativeGtReactNative.js";
5
4
  import { GTProvider } from "./provider/GTProvider.js";
6
5
  export function multiply(a, b) {
@@ -1 +1 @@
1
- {"version":3,"names":["GtReactNative","GTProvider","multiply","a","b","T","useGT","useTranslations","useDefaultLocale","useLocale","useRegion","Var","Num","Currency","DateTime","Plural","Branch","useLocales","useLocaleSelector","useSetLocale","useGTClass","useLocaleProperties","useRegionSelector","useLocaleDirection","useMessages","msg","decodeMsg","decodeOptions"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAO,qBAAkB;AACzB,OAAOA,aAAa,MAAM,0BAAuB;AAEjD,SAASC,UAAU,QAAQ,0BAAuB;AAClD,OAAO,SAASC,QAAQA,CAACC,CAAS,EAAEC,CAAS,EAAU;EACrD,OAAOJ,aAAa,CAACE,QAAQ,CAACC,CAAC,EAAEC,CAAC,CAAC;AACrC;AAEA,SACEC,CAAC,EACDC,KAAK,EACLC,eAAe,EACfC,gBAAgB,EAChBC,SAAS,EACTC,SAAS,EACTC,GAAG,EACHC,GAAG,EACHC,QAAQ,EACRC,QAAQ,EACRC,MAAM,EACNC,MAAM,EACNC,UAAU,EACVC,iBAAiB,EACjBC,YAAY,EACZC,UAAU,EACVC,mBAAmB,EACnBC,iBAAiB,EACjBC,kBAAkB,EAClBC,WAAW,EACXC,GAAG,EACHC,SAAS,EACTC,aAAa,QACR,gCAAgC;AAOvC,SACEhB,GAAG,EACHC,GAAG,EACHC,QAAQ,EACRC,QAAQ,EACRT,CAAC,EACDJ,UAAU,EACVc,MAAM,EACNC,MAAM,EACNV,KAAK,EACLC,eAAe,EACfC,gBAAgB,EAChBC,SAAS,EACTQ,UAAU,EACVE,YAAY,EACZD,iBAAiB,EACjBR,SAAS,EACTY,iBAAiB,EACjBF,UAAU,EACVC,mBAAmB,EACnBE,kBAAkB,EAIlBE,GAAG,EACHC,SAAS,EACTC,aAAa,EACbH,WAAW","ignoreList":[]}
1
+ {"version":3,"names":["GtReactNative","GTProvider","multiply","a","b","T","useGT","useTranslations","useDefaultLocale","useLocale","useRegion","Var","Num","Currency","DateTime","Plural","Branch","useLocales","useLocaleSelector","useSetLocale","useGTClass","useLocaleProperties","useRegionSelector","useLocaleDirection","useMessages","msg","decodeMsg","decodeOptions"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,aAAa,MAAM,0BAAuB;AAEjD,SAASC,UAAU,QAAQ,0BAAuB;AAClD,OAAO,SAASC,QAAQA,CAACC,CAAS,EAAEC,CAAS,EAAU;EACrD,OAAOJ,aAAa,CAACE,QAAQ,CAACC,CAAC,EAAEC,CAAC,CAAC;AACrC;AAEA,SACEC,CAAC,EACDC,KAAK,EACLC,eAAe,EACfC,gBAAgB,EAChBC,SAAS,EACTC,SAAS,EACTC,GAAG,EACHC,GAAG,EACHC,QAAQ,EACRC,QAAQ,EACRC,MAAM,EACNC,MAAM,EACNC,UAAU,EACVC,iBAAiB,EACjBC,YAAY,EACZC,UAAU,EACVC,mBAAmB,EACnBC,iBAAiB,EACjBC,kBAAkB,EAClBC,WAAW,EACXC,GAAG,EACHC,SAAS,EACTC,aAAa,QACR,gCAAgC;AAOvC,SACEhB,GAAG,EACHC,GAAG,EACHC,QAAQ,EACRC,QAAQ,EACRT,CAAC,EACDJ,UAAU,EACVc,MAAM,EACNC,MAAM,EACNV,KAAK,EACLC,eAAe,EACfC,gBAAgB,EAChBC,SAAS,EACTQ,UAAU,EACVE,YAAY,EACZD,iBAAiB,EACjBR,SAAS,EACTY,iBAAiB,EACjBF,UAAU,EACVC,mBAAmB,EACnBE,kBAAkB,EAIlBE,GAAG,EACHC,SAAS,EACTC,aAAa,EACbH,WAAW","ignoreList":[]}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ import * as path from 'path';
4
+ export default function (babel, {
5
+ targetFile,
6
+ locales
7
+ }) {
8
+ const {
9
+ types: t
10
+ } = babel;
11
+ const targetFilePath = targetFile;
12
+ console.log('plugin', targetFilePath);
13
+ return {
14
+ name: 'gt-react-native/plugin',
15
+ visitor: {
16
+ Program(programPath, state) {
17
+ const currentFilePath = path.resolve(state.filename || state.file.opts.filename || '');
18
+ if (!targetFilePath || currentFilePath !== path.resolve(targetFilePath)) {
19
+ return;
20
+ }
21
+ const imports = ['@formatjs/intl-getcanonicallocales/polyfill', '@formatjs/intl-locale/polyfill', '@formatjs/intl-displaynames/polyfill', '@formatjs/intl-listformat/polyfill', '@formatjs/intl-pluralrules/polyfill-force',
22
+ // https://github.com/formatjs/formatjs/issues/4463
23
+ '@formatjs/intl-numberformat/polyfill', '@formatjs/intl-relativetimeformat/polyfill', '@formatjs/intl-datetimeformat/polyfill', '@formatjs/intl-datetimeformat/add-all-tz', ...locales.flatMap(locale => [`@formatjs/intl-displaynames/locale-data/${locale}`, `@formatjs/intl-listformat/locale-data/${locale}`, `@formatjs/intl-pluralrules/locale-data/${locale}`, `@formatjs/intl-numberformat/locale-data/${locale}`, `@formatjs/intl-relativetimeformat/locale-data/${locale}`, `@formatjs/intl-datetimeformat/locale-data/${locale}`])];
24
+ const existingImports = new Set();
25
+ programPath.node.body.forEach(node => {
26
+ if (t.isImportDeclaration(node) && typeof node.source.value === 'string' && imports.includes(node.source.value)) {
27
+ existingImports.add(node.source.value);
28
+ }
29
+ });
30
+ const importsToAdd = imports.filter(imp => !existingImports.has(imp));
31
+ if (importsToAdd.length > 0) {
32
+ const newImports = importsToAdd.map(importPath => t.importDeclaration([], t.stringLiteral(importPath)));
33
+ programPath.node.body.unshift(...newImports);
34
+ }
35
+ }
36
+ }
37
+ };
38
+ }
39
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["path","babel","targetFile","locales","types","t","targetFilePath","console","log","name","visitor","Program","programPath","state","currentFilePath","resolve","filename","file","opts","imports","flatMap","locale","existingImports","Set","node","body","forEach","isImportDeclaration","source","value","includes","add","importsToAdd","filter","imp","has","length","newImports","map","importPath","importDeclaration","stringLiteral","unshift"],"sourceRoot":"../../src","sources":["plugin.ts"],"mappings":";;AAAA,OAAO,KAAKA,IAAI,MAAM,MAAM;AAQ5B,eAAe,UACbC,KAA8B,EAC9B;EAAEC,UAAU;EAAEC;AAAuB,CAAC,EAC3B;EACX,MAAM;IAAEC,KAAK,EAAEC;EAAE,CAAC,GAAGJ,KAAK;EAC1B,MAAMK,cAAc,GAAGJ,UAAU;EAEjCK,OAAO,CAACC,GAAG,CAAC,QAAQ,EAAEF,cAAc,CAAC;EAErC,OAAO;IACLG,IAAI,EAAE,wBAAwB;IAC9BC,OAAO,EAAE;MACPC,OAAOA,CAACC,WAAW,EAAEC,KAAK,EAAE;QAC1B,MAAMC,eAAe,GAAGd,IAAI,CAACe,OAAO,CAClCF,KAAK,CAACG,QAAQ,IAAIH,KAAK,CAACI,IAAI,CAACC,IAAI,CAACF,QAAQ,IAAI,EAChD,CAAC;QAED,IACE,CAACV,cAAc,IACfQ,eAAe,KAAKd,IAAI,CAACe,OAAO,CAACT,cAAc,CAAC,EAChD;UACA;QACF;QAEA,MAAMa,OAAO,GAAG,CACd,6CAA6C,EAC7C,gCAAgC,EAChC,sCAAsC,EACtC,oCAAoC,EACpC,2CAA2C;QAAE;QAC7C,sCAAsC,EACtC,4CAA4C,EAC5C,wCAAwC,EACxC,0CAA0C,EAC1C,GAAGhB,OAAO,CAACiB,OAAO,CAAEC,MAAM,IAAK,CAC7B,2CAA2CA,MAAM,EAAE,EACnD,yCAAyCA,MAAM,EAAE,EACjD,0CAA0CA,MAAM,EAAE,EAClD,2CAA2CA,MAAM,EAAE,EACnD,iDAAiDA,MAAM,EAAE,EACzD,6CAA6CA,MAAM,EAAE,CACtD,CAAC,CACH;QAED,MAAMC,eAAe,GAAG,IAAIC,GAAG,CAAS,CAAC;QACzCX,WAAW,CAACY,IAAI,CAACC,IAAI,CAACC,OAAO,CAAEF,IAAI,IAAK;UACtC,IACEnB,CAAC,CAACsB,mBAAmB,CAACH,IAAI,CAAC,IAC3B,OAAOA,IAAI,CAACI,MAAM,CAACC,KAAK,KAAK,QAAQ,IACrCV,OAAO,CAACW,QAAQ,CAACN,IAAI,CAACI,MAAM,CAACC,KAAK,CAAC,EACnC;YACAP,eAAe,CAACS,GAAG,CAACP,IAAI,CAACI,MAAM,CAACC,KAAK,CAAC;UACxC;QACF,CAAC,CAAC;QAEF,MAAMG,YAAY,GAAGb,OAAO,CAACc,MAAM,CAAEC,GAAG,IAAK,CAACZ,eAAe,CAACa,GAAG,CAACD,GAAG,CAAC,CAAC;QAEvE,IAAIF,YAAY,CAACI,MAAM,GAAG,CAAC,EAAE;UAC3B,MAAMC,UAAU,GAAGL,YAAY,CAACM,GAAG,CAAEC,UAAU,IAC7ClC,CAAC,CAACmC,iBAAiB,CAAC,EAAE,EAAEnC,CAAC,CAACoC,aAAa,CAACF,UAAU,CAAC,CACrD,CAAC;UAED3B,WAAW,CAACY,IAAI,CAACC,IAAI,CAACiB,OAAO,CAAC,GAAGL,UAAU,CAAC;QAC9C;MACF;IACF;EACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ export function testLocalePolyfill(locale = 'en-US') {
4
+ const problems = [];
5
+
6
+ // 1. basic presence
7
+ if (!global.Intl) problems.push('Intl missing entirely');
8
+ const apis = ['Locale', 'NumberFormat', 'DateTimeFormat', 'PluralRules', 'RelativeTimeFormat', 'ListFormat', 'DisplayNames'];
9
+ apis.forEach(a => {
10
+ // @ts-ignore
11
+ if (!Intl[a]) problems.push(`Intl.${a} missing`);
12
+ });
13
+
14
+ // 2. locale actually supported (no silent fallback)
15
+ const dtfSupported = Intl.DateTimeFormat.supportedLocalesOf([locale])[0] === locale;
16
+ const nfSupported = Intl.NumberFormat.supportedLocalesOf([locale])[0] === locale;
17
+ if (!dtfSupported) problems.push(`${locale} not supported by DateTimeFormat`);
18
+ if (!nfSupported) problems.push(`${locale} not supported by NumberFormat`);
19
+
20
+ // 3. numeric separators sanity
21
+ let group, decimal;
22
+ try {
23
+ const parts = new Intl.NumberFormat(locale).formatToParts(1234.5);
24
+ group = parts.find(p => p.type === 'group')?.value;
25
+ decimal = parts.find(p => p.type === 'decimal')?.value;
26
+ if (!group || !decimal) problems.push('formatToParts missing group/decimal separators');
27
+ } catch (e) {
28
+ problems.push(`NumberFormat threw: ${e instanceof Error ? e.message : String(e)}`);
29
+ }
30
+
31
+ // 4. plural rules sanity
32
+ try {
33
+ const pr = new Intl.PluralRules(locale);
34
+ const sample = pr.select(5);
35
+ if (!sample) problems.push('PluralRules returned undefined');
36
+ } catch (e) {
37
+ problems.push(`PluralRules threw: ${e instanceof Error ? e.message : String(e)}`);
38
+ }
39
+
40
+ // 5. show example formatted values
41
+ const example = {
42
+ number: new Intl.NumberFormat(locale).format(1234.5),
43
+ date: new Intl.DateTimeFormat(locale, {
44
+ dateStyle: 'long'
45
+ }).format(new Date('2020-01-02')),
46
+ weekday: new Intl.DateTimeFormat(locale, {
47
+ weekday: 'long'
48
+ }).format(new Date('2020-01-02'))
49
+ };
50
+ const result = {
51
+ ok: problems.length === 0,
52
+ problems,
53
+ group,
54
+ decimal,
55
+ example
56
+ };
57
+ if (result.ok) {
58
+ console.log(`✅ Locale polyfill looks OK for ${locale}`, example);
59
+ } else {
60
+ console.warn(`❌ Locale polyfill check failed for ${locale}:`, problems, example);
61
+ }
62
+ return result;
63
+ }
64
+ //# sourceMappingURL=testLocalePolyfill.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["testLocalePolyfill","locale","problems","global","Intl","push","apis","forEach","a","dtfSupported","DateTimeFormat","supportedLocalesOf","nfSupported","NumberFormat","group","decimal","parts","formatToParts","find","p","type","value","e","Error","message","String","pr","PluralRules","sample","select","example","number","format","date","dateStyle","Date","weekday","result","ok","length","console","log","warn"],"sourceRoot":"../../src","sources":["testLocalePolyfill.ts"],"mappings":"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","ignoreList":[]}
@@ -1,4 +1,3 @@
1
- import './utils/polyfill';
2
1
  import { GTProvider } from './provider/GTProvider';
3
2
  export declare function multiply(a: number, b: number): number;
4
3
  import { T, useGT, useTranslations, useDefaultLocale, useLocale, useRegion, Var, Num, Currency, DateTime, Plural, Branch, useLocales, useLocaleSelector, useSetLocale, useGTClass, useLocaleProperties, useRegionSelector, useLocaleDirection, useMessages, msg, decodeMsg, decodeOptions } from '@generaltranslation/react-core';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAG1B,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,OAAO,EACL,CAAC,EACD,KAAK,EACL,eAAe,EACf,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,GAAG,EACH,GAAG,EACH,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,YAAY,EACZ,UAAU,EACV,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,GAAG,EACH,SAAS,EACT,aAAa,EACd,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EACV,4BAA4B,EAC5B,wBAAwB,EACxB,yBAAyB,EAC1B,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EACL,GAAG,EACH,GAAG,EACH,QAAQ,EACR,QAAQ,EACR,CAAC,EACD,UAAU,EACV,MAAM,EACN,MAAM,EACN,KAAK,EACL,eAAe,EACf,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,UAAU,EACV,mBAAmB,EACnB,kBAAkB,EAClB,KAAK,4BAA4B,EACjC,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,GAAG,EACH,SAAS,EACT,aAAa,EACb,WAAW,GACZ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,OAAO,EACL,CAAC,EACD,KAAK,EACL,eAAe,EACf,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,GAAG,EACH,GAAG,EACH,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,YAAY,EACZ,UAAU,EACV,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,GAAG,EACH,SAAS,EACT,aAAa,EACd,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EACV,4BAA4B,EAC5B,wBAAwB,EACxB,yBAAyB,EAC1B,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EACL,GAAG,EACH,GAAG,EACH,QAAQ,EACR,QAAQ,EACR,CAAC,EACD,UAAU,EACV,MAAM,EACN,MAAM,EACN,KAAK,EACL,eAAe,EACf,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,UAAU,EACV,mBAAmB,EACnB,kBAAkB,EAClB,KAAK,4BAA4B,EACjC,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,GAAG,EACH,SAAS,EACT,aAAa,EACb,WAAW,GACZ,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { PluginObj, types } from '@babel/core';
2
+ interface PluginOptions {
3
+ targetFile: string;
4
+ locales: string[];
5
+ }
6
+ export default function (babel: {
7
+ types: typeof types;
8
+ }, { targetFile, locales }: PluginOptions): PluginObj;
9
+ export {};
10
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpD,UAAU,aAAa;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,CAAC,OAAO,WACZ,KAAK,EAAE;IAAE,KAAK,EAAE,OAAO,KAAK,CAAA;CAAE,EAC9B,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,aAAa,GACrC,SAAS,CAgEX"}
@@ -0,0 +1,12 @@
1
+ export declare function testLocalePolyfill(locale?: string): {
2
+ ok: boolean;
3
+ problems: string[];
4
+ group: string | undefined;
5
+ decimal: string | undefined;
6
+ example: {
7
+ number: string;
8
+ date: string;
9
+ weekday: string;
10
+ };
11
+ };
12
+ //# sourceMappingURL=testLocalePolyfill.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testLocalePolyfill.d.ts","sourceRoot":"","sources":["../../../src/testLocalePolyfill.ts"],"names":[],"mappings":"AAAA,wBAAgB,kBAAkB,CAAC,MAAM,SAAU;;;;;;;;;;EAiFlD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gt-react-native",
3
- "version": "0.0.1-alpha.10",
3
+ "version": "0.0.1-alpha.11",
4
4
  "description": "An i18n package for React Native",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -10,6 +10,16 @@
10
10
  "types": "./lib/typescript/src/index.d.ts",
11
11
  "default": "./lib/module/index.js"
12
12
  },
13
+ "./plugin": {
14
+ "source": "./src/plugin.ts",
15
+ "types": "./lib/typescript/src/plugin.d.ts",
16
+ "default": "./lib/module/plugin.js"
17
+ },
18
+ "./_utils/testLocalePolyfill": {
19
+ "source": "./src/testLocalePolyfill.ts",
20
+ "types": "./lib/typescript/src/testLocalePolyfill.d.ts",
21
+ "default": "./lib/module/testLocalePolyfill.js"
22
+ },
13
23
  "./package.json": "./package.json"
14
24
  },
15
25
  "files": [
@@ -59,6 +69,8 @@
59
69
  "registry": "https://registry.npmjs.org/"
60
70
  },
61
71
  "devDependencies": {
72
+ "@babel/core": "^7.28.4",
73
+ "@babel/types": "^7.28.4",
62
74
  "@commitlint/config-conventional": "^19.8.1",
63
75
  "@eslint/compat": "^1.3.2",
64
76
  "@eslint/eslintrc": "^3.3.1",
package/src/index.tsx CHANGED
@@ -1,4 +1,3 @@
1
- import './utils/polyfill';
2
1
  import GtReactNative from './NativeGtReactNative';
3
2
 
4
3
  import { GTProvider } from './provider/GTProvider';
package/src/plugin.ts ADDED
@@ -0,0 +1,76 @@
1
+ import * as path from 'path';
2
+ import type { PluginObj, types } from '@babel/core';
3
+
4
+ interface PluginOptions {
5
+ targetFile: string;
6
+ locales: string[];
7
+ }
8
+
9
+ export default function (
10
+ babel: { types: typeof types },
11
+ { targetFile, locales }: PluginOptions
12
+ ): PluginObj {
13
+ const { types: t } = babel;
14
+ const targetFilePath = targetFile;
15
+
16
+ console.log('plugin', targetFilePath);
17
+
18
+ return {
19
+ name: 'gt-react-native/plugin',
20
+ visitor: {
21
+ Program(programPath, state) {
22
+ const currentFilePath = path.resolve(
23
+ state.filename || state.file.opts.filename || ''
24
+ );
25
+
26
+ if (
27
+ !targetFilePath ||
28
+ currentFilePath !== path.resolve(targetFilePath)
29
+ ) {
30
+ return;
31
+ }
32
+
33
+ const imports = [
34
+ '@formatjs/intl-getcanonicallocales/polyfill',
35
+ '@formatjs/intl-locale/polyfill',
36
+ '@formatjs/intl-displaynames/polyfill',
37
+ '@formatjs/intl-listformat/polyfill',
38
+ '@formatjs/intl-pluralrules/polyfill-force', // https://github.com/formatjs/formatjs/issues/4463
39
+ '@formatjs/intl-numberformat/polyfill',
40
+ '@formatjs/intl-relativetimeformat/polyfill',
41
+ '@formatjs/intl-datetimeformat/polyfill',
42
+ '@formatjs/intl-datetimeformat/add-all-tz',
43
+ ...locales.flatMap((locale) => [
44
+ `@formatjs/intl-displaynames/locale-data/${locale}`,
45
+ `@formatjs/intl-listformat/locale-data/${locale}`,
46
+ `@formatjs/intl-pluralrules/locale-data/${locale}`,
47
+ `@formatjs/intl-numberformat/locale-data/${locale}`,
48
+ `@formatjs/intl-relativetimeformat/locale-data/${locale}`,
49
+ `@formatjs/intl-datetimeformat/locale-data/${locale}`,
50
+ ]),
51
+ ];
52
+
53
+ const existingImports = new Set<string>();
54
+ programPath.node.body.forEach((node) => {
55
+ if (
56
+ t.isImportDeclaration(node) &&
57
+ typeof node.source.value === 'string' &&
58
+ imports.includes(node.source.value)
59
+ ) {
60
+ existingImports.add(node.source.value);
61
+ }
62
+ });
63
+
64
+ const importsToAdd = imports.filter((imp) => !existingImports.has(imp));
65
+
66
+ if (importsToAdd.length > 0) {
67
+ const newImports = importsToAdd.map((importPath) =>
68
+ t.importDeclaration([], t.stringLiteral(importPath))
69
+ );
70
+
71
+ programPath.node.body.unshift(...newImports);
72
+ }
73
+ },
74
+ },
75
+ };
76
+ }
@@ -0,0 +1,82 @@
1
+ export function testLocalePolyfill(locale = 'en-US') {
2
+ const problems = [];
3
+
4
+ // 1. basic presence
5
+ if (!global.Intl) problems.push('Intl missing entirely');
6
+ const apis = [
7
+ 'Locale',
8
+ 'NumberFormat',
9
+ 'DateTimeFormat',
10
+ 'PluralRules',
11
+ 'RelativeTimeFormat',
12
+ 'ListFormat',
13
+ 'DisplayNames',
14
+ ];
15
+ apis.forEach((a) => {
16
+ // @ts-ignore
17
+ if (!Intl[a]) problems.push(`Intl.${a} missing`);
18
+ });
19
+
20
+ // 2. locale actually supported (no silent fallback)
21
+ const dtfSupported =
22
+ Intl.DateTimeFormat.supportedLocalesOf([locale])[0] === locale;
23
+ const nfSupported =
24
+ Intl.NumberFormat.supportedLocalesOf([locale])[0] === locale;
25
+ if (!dtfSupported) problems.push(`${locale} not supported by DateTimeFormat`);
26
+ if (!nfSupported) problems.push(`${locale} not supported by NumberFormat`);
27
+
28
+ // 3. numeric separators sanity
29
+ let group, decimal;
30
+ try {
31
+ const parts = new Intl.NumberFormat(locale).formatToParts(1234.5);
32
+ group = parts.find((p) => p.type === 'group')?.value;
33
+ decimal = parts.find((p) => p.type === 'decimal')?.value;
34
+ if (!group || !decimal)
35
+ problems.push('formatToParts missing group/decimal separators');
36
+ } catch (e) {
37
+ problems.push(
38
+ `NumberFormat threw: ${e instanceof Error ? e.message : String(e)}`
39
+ );
40
+ }
41
+
42
+ // 4. plural rules sanity
43
+ try {
44
+ const pr = new Intl.PluralRules(locale);
45
+ const sample = pr.select(5);
46
+ if (!sample) problems.push('PluralRules returned undefined');
47
+ } catch (e) {
48
+ problems.push(
49
+ `PluralRules threw: ${e instanceof Error ? e.message : String(e)}`
50
+ );
51
+ }
52
+
53
+ // 5. show example formatted values
54
+ const example = {
55
+ number: new Intl.NumberFormat(locale).format(1234.5),
56
+ date: new Intl.DateTimeFormat(locale, { dateStyle: 'long' }).format(
57
+ new Date('2020-01-02')
58
+ ),
59
+ weekday: new Intl.DateTimeFormat(locale, { weekday: 'long' }).format(
60
+ new Date('2020-01-02')
61
+ ),
62
+ };
63
+
64
+ const result = {
65
+ ok: problems.length === 0,
66
+ problems,
67
+ group,
68
+ decimal,
69
+ example,
70
+ };
71
+
72
+ if (result.ok) {
73
+ console.log(`✅ Locale polyfill looks OK for ${locale}`, example);
74
+ } else {
75
+ console.warn(
76
+ `❌ Locale polyfill check failed for ${locale}:`,
77
+ problems,
78
+ example
79
+ );
80
+ }
81
+ return result;
82
+ }
@@ -1,33 +0,0 @@
1
- "use strict";
2
-
3
- // Intl object not natively supported, see: https://formatjs.github.io/docs/polyfills
4
- // See also: The Ultimate Guide to React Native Optimization - page 124
5
-
6
- import '@formatjs/intl-getcanonicallocales/polyfill';
7
- import '@formatjs/intl-locale/polyfill';
8
- import '@formatjs/intl-displaynames/polyfill';
9
- import '@formatjs/intl-listformat/polyfill';
10
- import '@formatjs/intl-pluralrules/polyfill-force'; // https://github.com/formatjs/formatjs/issues/4463
11
- import '@formatjs/intl-numberformat/polyfill';
12
- import '@formatjs/intl-relativetimeformat/polyfill';
13
- import '@formatjs/intl-datetimeformat/polyfill';
14
- import '@formatjs/intl-datetimeformat/add-all-tz';
15
- import '@formatjs/intl-displaynames/locale-data/en';
16
- import '@formatjs/intl-displaynames/locale-data/zh';
17
- import '@formatjs/intl-displaynames/locale-data/es';
18
- import '@formatjs/intl-listformat/locale-data/en';
19
- import '@formatjs/intl-listformat/locale-data/zh';
20
- import '@formatjs/intl-listformat/locale-data/es';
21
- import '@formatjs/intl-pluralrules/locale-data/en';
22
- import '@formatjs/intl-pluralrules/locale-data/zh';
23
- import '@formatjs/intl-pluralrules/locale-data/es';
24
- import '@formatjs/intl-numberformat/locale-data/en';
25
- import '@formatjs/intl-numberformat/locale-data/zh';
26
- import '@formatjs/intl-numberformat/locale-data/es';
27
- import '@formatjs/intl-relativetimeformat/locale-data/en';
28
- import '@formatjs/intl-relativetimeformat/locale-data/zh';
29
- import '@formatjs/intl-relativetimeformat/locale-data/es';
30
- import '@formatjs/intl-datetimeformat/locale-data/en';
31
- import '@formatjs/intl-datetimeformat/locale-data/zh';
32
- import '@formatjs/intl-datetimeformat/locale-data/es';
33
- //# sourceMappingURL=polyfill.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../src","sources":["utils/polyfill.ts"],"mappings":";;AAAA;AACA;;AAEA,OAAO,6CAA6C;AACpD,OAAO,gCAAgC;AACvC,OAAO,sCAAsC;AAC7C,OAAO,oCAAoC;AAC3C,OAAO,2CAA2C,CAAC,CAAC;AACpD,OAAO,sCAAsC;AAC7C,OAAO,4CAA4C;AACnD,OAAO,wCAAwC;AAC/C,OAAO,0CAA0C;AAEjD,OAAO,4CAA4C;AACnD,OAAO,4CAA4C;AACnD,OAAO,4CAA4C;AAEnD,OAAO,0CAA0C;AACjD,OAAO,0CAA0C;AACjD,OAAO,0CAA0C;AAEjD,OAAO,2CAA2C;AAClD,OAAO,2CAA2C;AAClD,OAAO,2CAA2C;AAElD,OAAO,4CAA4C;AACnD,OAAO,4CAA4C;AACnD,OAAO,4CAA4C;AAEnD,OAAO,kDAAkD;AACzD,OAAO,kDAAkD;AACzD,OAAO,kDAAkD;AAEzD,OAAO,8CAA8C;AACrD,OAAO,8CAA8C;AACrD,OAAO,8CAA8C","ignoreList":[]}
@@ -1,28 +0,0 @@
1
- import '@formatjs/intl-getcanonicallocales/polyfill';
2
- import '@formatjs/intl-locale/polyfill';
3
- import '@formatjs/intl-displaynames/polyfill';
4
- import '@formatjs/intl-listformat/polyfill';
5
- import '@formatjs/intl-pluralrules/polyfill-force';
6
- import '@formatjs/intl-numberformat/polyfill';
7
- import '@formatjs/intl-relativetimeformat/polyfill';
8
- import '@formatjs/intl-datetimeformat/polyfill';
9
- import '@formatjs/intl-datetimeformat/add-all-tz';
10
- import '@formatjs/intl-displaynames/locale-data/en';
11
- import '@formatjs/intl-displaynames/locale-data/zh';
12
- import '@formatjs/intl-displaynames/locale-data/es';
13
- import '@formatjs/intl-listformat/locale-data/en';
14
- import '@formatjs/intl-listformat/locale-data/zh';
15
- import '@formatjs/intl-listformat/locale-data/es';
16
- import '@formatjs/intl-pluralrules/locale-data/en';
17
- import '@formatjs/intl-pluralrules/locale-data/zh';
18
- import '@formatjs/intl-pluralrules/locale-data/es';
19
- import '@formatjs/intl-numberformat/locale-data/en';
20
- import '@formatjs/intl-numberformat/locale-data/zh';
21
- import '@formatjs/intl-numberformat/locale-data/es';
22
- import '@formatjs/intl-relativetimeformat/locale-data/en';
23
- import '@formatjs/intl-relativetimeformat/locale-data/zh';
24
- import '@formatjs/intl-relativetimeformat/locale-data/es';
25
- import '@formatjs/intl-datetimeformat/locale-data/en';
26
- import '@formatjs/intl-datetimeformat/locale-data/zh';
27
- import '@formatjs/intl-datetimeformat/locale-data/es';
28
- //# sourceMappingURL=polyfill.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../../../../src/utils/polyfill.ts"],"names":[],"mappings":"AAGA,OAAO,6CAA6C,CAAC;AACrD,OAAO,gCAAgC,CAAC;AACxC,OAAO,sCAAsC,CAAC;AAC9C,OAAO,oCAAoC,CAAC;AAC5C,OAAO,2CAA2C,CAAC;AACnD,OAAO,sCAAsC,CAAC;AAC9C,OAAO,4CAA4C,CAAC;AACpD,OAAO,wCAAwC,CAAC;AAChD,OAAO,0CAA0C,CAAC;AAElD,OAAO,4CAA4C,CAAC;AACpD,OAAO,4CAA4C,CAAC;AACpD,OAAO,4CAA4C,CAAC;AAEpD,OAAO,0CAA0C,CAAC;AAClD,OAAO,0CAA0C,CAAC;AAClD,OAAO,0CAA0C,CAAC;AAElD,OAAO,2CAA2C,CAAC;AACnD,OAAO,2CAA2C,CAAC;AACnD,OAAO,2CAA2C,CAAC;AAEnD,OAAO,4CAA4C,CAAC;AACpD,OAAO,4CAA4C,CAAC;AACpD,OAAO,4CAA4C,CAAC;AAEpD,OAAO,kDAAkD,CAAC;AAC1D,OAAO,kDAAkD,CAAC;AAC1D,OAAO,kDAAkD,CAAC;AAE1D,OAAO,8CAA8C,CAAC;AACtD,OAAO,8CAA8C,CAAC;AACtD,OAAO,8CAA8C,CAAC"}
@@ -1,36 +0,0 @@
1
- // Intl object not natively supported, see: https://formatjs.github.io/docs/polyfills
2
- // See also: The Ultimate Guide to React Native Optimization - page 124
3
-
4
- import '@formatjs/intl-getcanonicallocales/polyfill';
5
- import '@formatjs/intl-locale/polyfill';
6
- import '@formatjs/intl-displaynames/polyfill';
7
- import '@formatjs/intl-listformat/polyfill';
8
- import '@formatjs/intl-pluralrules/polyfill-force'; // https://github.com/formatjs/formatjs/issues/4463
9
- import '@formatjs/intl-numberformat/polyfill';
10
- import '@formatjs/intl-relativetimeformat/polyfill';
11
- import '@formatjs/intl-datetimeformat/polyfill';
12
- import '@formatjs/intl-datetimeformat/add-all-tz';
13
-
14
- import '@formatjs/intl-displaynames/locale-data/en';
15
- import '@formatjs/intl-displaynames/locale-data/zh';
16
- import '@formatjs/intl-displaynames/locale-data/es';
17
-
18
- import '@formatjs/intl-listformat/locale-data/en';
19
- import '@formatjs/intl-listformat/locale-data/zh';
20
- import '@formatjs/intl-listformat/locale-data/es';
21
-
22
- import '@formatjs/intl-pluralrules/locale-data/en';
23
- import '@formatjs/intl-pluralrules/locale-data/zh';
24
- import '@formatjs/intl-pluralrules/locale-data/es';
25
-
26
- import '@formatjs/intl-numberformat/locale-data/en';
27
- import '@formatjs/intl-numberformat/locale-data/zh';
28
- import '@formatjs/intl-numberformat/locale-data/es';
29
-
30
- import '@formatjs/intl-relativetimeformat/locale-data/en';
31
- import '@formatjs/intl-relativetimeformat/locale-data/zh';
32
- import '@formatjs/intl-relativetimeformat/locale-data/es';
33
-
34
- import '@formatjs/intl-datetimeformat/locale-data/en';
35
- import '@formatjs/intl-datetimeformat/locale-data/zh';
36
- import '@formatjs/intl-datetimeformat/locale-data/es';