gt-i18n 1.0.0 → 1.0.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.
- package/CHANGELOG.md +19 -0
- package/dist/{LocalesCache-6hJpulfR.d.cts → LocalesCache-BrqsSW3K.d.cts} +2 -1
- package/dist/{LocalesCache-CO3aKdqI.d.mts → LocalesCache-Cgg8OjSV.d.mts} +2 -1
- package/dist/internal-types.d.cts +1 -1
- package/dist/internal-types.d.mts +1 -1
- package/dist/internal.cjs +32 -0
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +13 -2
- package/dist/internal.d.mts +13 -2
- package/dist/internal.mjs +31 -1
- package/dist/internal.mjs.map +1 -1
- package/package.json +1 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# gt-i18n
|
|
2
2
|
|
|
3
|
+
## 1.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1858](https://github.com/generaltranslation/gt/pull/1858) [`006e071`](https://github.com/generaltranslation/gt/commit/006e071bf87ffe80f2d18958ddfa8f18cc2d85d2) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - Accept parsed `gt.config.json` objects in the compiler and React SPA configuration types.
|
|
8
|
+
|
|
9
|
+
- [#1846](https://github.com/generaltranslation/gt/pull/1846) [`7fb4a74`](https://github.com/generaltranslation/gt/commit/7fb4a74c52065694a40deafcf4596acc09e17f58) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - Add `parseLocale(request)` to resolve server-rendered React locales from the configured cookie, the `Accept-Language` header, or the default locale.
|
|
10
|
+
|
|
11
|
+
Share cookie and `Accept-Language` parsing across the framework packages.
|
|
12
|
+
|
|
13
|
+
- [#1848](https://github.com/generaltranslation/gt/pull/1848) [`1f33d5f`](https://github.com/generaltranslation/gt/commit/1f33d5f76ffc879d2d21aa2508e07e1d3b66c4e3) Thanks [@bgub](https://github.com/bgub)! - Remove unused dependencies: `@generaltranslation/supported-locales` from gt-react, gt-next, gt-i18n, and @generaltranslation/react-core, and `@generaltranslation/format` from gt-react. Nothing in these packages imports them, so this only reduces install weight.
|
|
14
|
+
|
|
15
|
+
## 1.0.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [[`7db86bd`](https://github.com/generaltranslation/gt/commit/7db86bd92be5d09a2da10133dbb873248b0e5a5c)]:
|
|
20
|
+
- @generaltranslation/supported-locales@2.1.3
|
|
21
|
+
|
|
3
22
|
## 1.0.0
|
|
4
23
|
|
|
5
24
|
### Major Changes
|
|
@@ -40,6 +40,7 @@ type GTConfig = {
|
|
|
40
40
|
_disableDevHotReload?: boolean;
|
|
41
41
|
files?: {
|
|
42
42
|
gt?: {
|
|
43
|
+
output?: string;
|
|
43
44
|
parsingFlags?: {
|
|
44
45
|
/**
|
|
45
46
|
* Dev hot reload config, gt-react browser runtime only.
|
|
@@ -237,4 +238,4 @@ declare class WritableConditionStore extends ReadonlyConditionStore implements W
|
|
|
237
238
|
type Locale = string;
|
|
238
239
|
//#endregion
|
|
239
240
|
export { TranslationsLoader as _, ReadonlyConditionStoreParams as a, LocaleCandidates as c, I18nCacheConfig as d, I18nCacheConstructorParams as f, WritableConditionStoreInterface as g, ScopedConditionStoreInterface as h, ReadonlyConditionStore as i, AsyncReadonlyConditionStoreInterface as l, ReadonlyConditionStoreInterface as m, WritableConditionStore as n, I18nConfig as o, LocaleResolverConfig as p, WritableConditionStoreParams as r, I18nConfigParams as s, Locale as t, DictionaryConfig as u, Hash as v, GTConfig as y };
|
|
240
|
-
//# sourceMappingURL=LocalesCache-
|
|
241
|
+
//# sourceMappingURL=LocalesCache-BrqsSW3K.d.cts.map
|
|
@@ -39,6 +39,7 @@ type GTConfig = {
|
|
|
39
39
|
_disableDevHotReload?: boolean;
|
|
40
40
|
files?: {
|
|
41
41
|
gt?: {
|
|
42
|
+
output?: string;
|
|
42
43
|
parsingFlags?: {
|
|
43
44
|
/**
|
|
44
45
|
* Dev hot reload config, gt-react browser runtime only.
|
|
@@ -236,4 +237,4 @@ declare class WritableConditionStore extends ReadonlyConditionStore implements W
|
|
|
236
237
|
type Locale = string;
|
|
237
238
|
//#endregion
|
|
238
239
|
export { TranslationsLoader as _, ReadonlyConditionStoreParams as a, LocaleCandidates as c, I18nCacheConfig as d, I18nCacheConstructorParams as f, WritableConditionStoreInterface as g, ScopedConditionStoreInterface as h, ReadonlyConditionStore as i, AsyncReadonlyConditionStoreInterface as l, ReadonlyConditionStoreInterface as m, WritableConditionStore as n, I18nConfig as o, LocaleResolverConfig as p, WritableConditionStoreParams as r, I18nConfigParams as s, Locale as t, DictionaryConfig as u, Hash as v, GTConfig as y };
|
|
239
|
-
//# sourceMappingURL=LocalesCache-
|
|
240
|
+
//# sourceMappingURL=LocalesCache-Cgg8OjSV.d.mts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { a as JsxTranslationOptions, c as NormalizedLookupOptions, d as TranslationOptions, f as TranslationVariables, i as GTTranslationOptions, l as RuntimeTranslationOptions, n as DictionaryLookupOptions, o as LookupOptions, r as EncodedTranslationOptions, s as LookupOptionsFor, t as DictionaryEntryOptions, u as TranslationMetadata } from "./options-BXeFwN0R.cjs";
|
|
2
|
-
import { _ as TranslationsLoader, a as ReadonlyConditionStoreParams, c as LocaleCandidates, d as I18nCacheConfig, f as I18nCacheConstructorParams, g as WritableConditionStoreInterface, h as ScopedConditionStoreInterface, l as AsyncReadonlyConditionStoreInterface, m as ReadonlyConditionStoreInterface, p as LocaleResolverConfig, r as WritableConditionStoreParams, s as I18nConfigParams, t as Locale, u as DictionaryConfig, v as Hash, y as GTConfig } from "./LocalesCache-
|
|
2
|
+
import { _ as TranslationsLoader, a as ReadonlyConditionStoreParams, c as LocaleCandidates, d as I18nCacheConfig, f as I18nCacheConstructorParams, g as WritableConditionStoreInterface, h as ScopedConditionStoreInterface, l as AsyncReadonlyConditionStoreInterface, m as ReadonlyConditionStoreInterface, p as LocaleResolverConfig, r as WritableConditionStoreParams, s as I18nConfigParams, t as Locale, u as DictionaryConfig, v as Hash, y as GTConfig } from "./LocalesCache-BrqsSW3K.cjs";
|
|
3
3
|
import { a as DictionaryLeaf, c as DictionaryValue, i as DictionaryKey, n as Dictionary, o as DictionaryObject, r as DictionaryEntry, s as DictionaryPath, t as DictionaryLoader } from "./DictionaryCache-DjAdDNiM.cjs";
|
|
4
4
|
export { type AsyncReadonlyConditionStoreInterface, type Dictionary, type DictionaryConfig, type DictionaryEntry, DictionaryEntryOptions, type DictionaryKey, type DictionaryLeaf, type DictionaryLoader, DictionaryLookupOptions, type DictionaryObject, type DictionaryPath, type DictionaryValue, EncodedTranslationOptions, type GTConfig, GTTranslationOptions, type Hash, type I18nCacheConfig, type I18nCacheConstructorParams, type I18nConfigParams, JsxTranslationOptions, type Locale, type LocaleCandidates, type LocaleResolverConfig, LookupOptions, LookupOptionsFor, NormalizedLookupOptions, type ReadonlyConditionStoreInterface, type ReadonlyConditionStoreParams, RuntimeTranslationOptions, type ScopedConditionStoreInterface, TranslationMetadata, TranslationOptions, TranslationVariables, type TranslationsLoader, type WritableConditionStoreInterface, type WritableConditionStoreParams };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { a as JsxTranslationOptions, c as NormalizedLookupOptions, d as TranslationOptions, f as TranslationVariables, i as GTTranslationOptions, l as RuntimeTranslationOptions, n as DictionaryLookupOptions, o as LookupOptions, r as EncodedTranslationOptions, s as LookupOptionsFor, t as DictionaryEntryOptions, u as TranslationMetadata } from "./options-DDUyXaLT.mjs";
|
|
2
|
-
import { _ as TranslationsLoader, a as ReadonlyConditionStoreParams, c as LocaleCandidates, d as I18nCacheConfig, f as I18nCacheConstructorParams, g as WritableConditionStoreInterface, h as ScopedConditionStoreInterface, l as AsyncReadonlyConditionStoreInterface, m as ReadonlyConditionStoreInterface, p as LocaleResolverConfig, r as WritableConditionStoreParams, s as I18nConfigParams, t as Locale, u as DictionaryConfig, v as Hash, y as GTConfig } from "./LocalesCache-
|
|
2
|
+
import { _ as TranslationsLoader, a as ReadonlyConditionStoreParams, c as LocaleCandidates, d as I18nCacheConfig, f as I18nCacheConstructorParams, g as WritableConditionStoreInterface, h as ScopedConditionStoreInterface, l as AsyncReadonlyConditionStoreInterface, m as ReadonlyConditionStoreInterface, p as LocaleResolverConfig, r as WritableConditionStoreParams, s as I18nConfigParams, t as Locale, u as DictionaryConfig, v as Hash, y as GTConfig } from "./LocalesCache-Cgg8OjSV.mjs";
|
|
3
3
|
import { a as DictionaryLeaf, c as DictionaryValue, i as DictionaryKey, n as Dictionary, o as DictionaryObject, r as DictionaryEntry, s as DictionaryPath, t as DictionaryLoader } from "./DictionaryCache-B7oTBs5W.mjs";
|
|
4
4
|
export { type AsyncReadonlyConditionStoreInterface, type Dictionary, type DictionaryConfig, type DictionaryEntry, DictionaryEntryOptions, type DictionaryKey, type DictionaryLeaf, type DictionaryLoader, DictionaryLookupOptions, type DictionaryObject, type DictionaryPath, type DictionaryValue, EncodedTranslationOptions, type GTConfig, GTTranslationOptions, type Hash, type I18nCacheConfig, type I18nCacheConstructorParams, type I18nConfigParams, JsxTranslationOptions, type Locale, type LocaleCandidates, type LocaleResolverConfig, LookupOptions, LookupOptionsFor, NormalizedLookupOptions, type ReadonlyConditionStoreInterface, type ReadonlyConditionStoreParams, RuntimeTranslationOptions, type ScopedConditionStoreInterface, TranslationMetadata, TranslationOptions, TranslationVariables, type TranslationsLoader, type WritableConditionStoreInterface, type WritableConditionStoreParams };
|
package/dist/internal.cjs
CHANGED
|
@@ -1463,6 +1463,36 @@ function getDictionaryListenerKey({ locale, id }) {
|
|
|
1463
1463
|
return `${locale}:${id}`;
|
|
1464
1464
|
}
|
|
1465
1465
|
//#endregion
|
|
1466
|
+
//#region src/utils/request.ts
|
|
1467
|
+
/**
|
|
1468
|
+
* Parse an Accept-Language header into locale candidates by preference.
|
|
1469
|
+
*/
|
|
1470
|
+
function parseAcceptLanguage(header) {
|
|
1471
|
+
return (Array.isArray(header) ? header : [header]).flatMap((value) => value?.split(",") ?? []).map((entry, index) => {
|
|
1472
|
+
const [locale = "", ...parameters] = entry.split(";").map((value) => value.trim());
|
|
1473
|
+
const qualityParameter = parameters.find((parameter) => parameter.toLowerCase().startsWith("q="));
|
|
1474
|
+
return {
|
|
1475
|
+
locale,
|
|
1476
|
+
quality: Number(qualityParameter?.slice(2) ?? 1),
|
|
1477
|
+
index
|
|
1478
|
+
};
|
|
1479
|
+
}).filter(({ locale, quality }) => locale !== "" && locale !== "*" && quality > 0 && quality <= 1).sort((a, b) => b.quality - a.quality || a.index - b.index).map(({ locale }) => locale);
|
|
1480
|
+
}
|
|
1481
|
+
/**
|
|
1482
|
+
* Read and decode a value from a Cookie header or document.cookie string.
|
|
1483
|
+
*/
|
|
1484
|
+
function getCookieValue(cookieHeader, cookieName) {
|
|
1485
|
+
const prefix = `${cookieName}=`;
|
|
1486
|
+
const cookie = cookieHeader?.split(";").map((value) => value.trim()).find((value) => value.startsWith(prefix));
|
|
1487
|
+
if (!cookie) return void 0;
|
|
1488
|
+
const value = cookie.slice(prefix.length);
|
|
1489
|
+
try {
|
|
1490
|
+
return decodeURIComponent(value);
|
|
1491
|
+
} catch {
|
|
1492
|
+
return value;
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
//#endregion
|
|
1466
1496
|
exports.GtInternalRuntimeTranslateJsx = GtInternalRuntimeTranslateJsx;
|
|
1467
1497
|
exports.GtInternalRuntimeTranslateString = GtInternalRuntimeTranslateString;
|
|
1468
1498
|
exports.I18nCache = I18nCache;
|
|
@@ -1473,6 +1503,7 @@ exports.createConditionStoreSingleton = require_versionId.createConditionStoreSi
|
|
|
1473
1503
|
exports.createGlobalSingleton = require_versionId.createGlobalSingleton;
|
|
1474
1504
|
exports.createLookupOptions = require_versionId.createLookupOptions;
|
|
1475
1505
|
exports.extractVariables = require_versionId.extractVariables;
|
|
1506
|
+
exports.getCookieValue = getCookieValue;
|
|
1476
1507
|
exports.getDictionaryEntry = getDictionaryEntry;
|
|
1477
1508
|
exports.getDictionaryListenerKey = getDictionaryListenerKey;
|
|
1478
1509
|
exports.getDictionaryValue = getDictionaryValue;
|
|
@@ -1492,6 +1523,7 @@ exports.initializeI18nConfig = require_versionId.initializeI18nConfig;
|
|
|
1492
1523
|
exports.interpolateMessage = require_versionId.interpolateMessage;
|
|
1493
1524
|
exports.isDictionaryValue = isDictionaryValue;
|
|
1494
1525
|
exports.isEncodedTranslationOptions = require_versionId.isEncodedTranslationOptions;
|
|
1526
|
+
exports.parseAcceptLanguage = parseAcceptLanguage;
|
|
1495
1527
|
exports.renderDictionaryEntry = renderDictionaryEntry;
|
|
1496
1528
|
exports.renderDictionaryObject = renderDictionaryObject;
|
|
1497
1529
|
exports.resolveDictionaryLookupOptions = resolveDictionaryLookupOptions;
|