gt-react 10.3.2-alpha.3 → 10.4.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.
Files changed (33) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/client.cjs.min.cjs +3 -3
  3. package/dist/client.d.ts +63 -8
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/client.esm.min.mjs +3 -3
  6. package/dist/dictionaries/getDictionaryEntry.d.ts.map +1 -1
  7. package/dist/errors/createErrors.d.ts +1 -0
  8. package/dist/errors/createErrors.d.ts.map +1 -1
  9. package/dist/index.cjs.min.cjs +3 -3
  10. package/dist/index.d.ts +2 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.esm.min.mjs +3 -3
  13. package/dist/internal.cjs.min.cjs +3 -3
  14. package/dist/internal.esm.min.mjs +3 -3
  15. package/dist/messages/messages.d.ts +19 -12
  16. package/dist/messages/messages.d.ts.map +1 -1
  17. package/dist/provider/ClientProvider.d.ts.map +1 -1
  18. package/dist/provider/GTProvider.d.ts.map +1 -1
  19. package/dist/provider/hooks/{useCreateInternalUseGTFunction.d.ts → translation/useCreateInternalUseGTFunction.d.ts} +3 -2
  20. package/dist/provider/hooks/translation/useCreateInternalUseGTFunction.d.ts.map +1 -0
  21. package/dist/provider/hooks/translation/useCreateInternalUseTranslationsFunction.d.ts +6 -0
  22. package/dist/provider/hooks/translation/useCreateInternalUseTranslationsFunction.d.ts.map +1 -0
  23. package/dist/provider/hooks/useCreateInternalUseTranslationsFunction.d.ts.map +1 -1
  24. package/dist/translation/hooks/useGT.d.ts +2 -7
  25. package/dist/translation/hooks/useGT.d.ts.map +1 -1
  26. package/dist/translation/hooks/useMessages.d.ts +18 -0
  27. package/dist/translation/hooks/useMessages.d.ts.map +1 -0
  28. package/dist/types/context.d.ts +1 -0
  29. package/dist/types/context.d.ts.map +1 -1
  30. package/dist/types/types.d.ts +1 -0
  31. package/dist/types/types.d.ts.map +1 -1
  32. package/package.json +1 -1
  33. package/dist/provider/hooks/useCreateInternalUseGTFunction.d.ts.map +0 -1
package/dist/client.d.ts CHANGED
@@ -38,6 +38,7 @@ type InlineTranslationOptions = DictionaryTranslationOptions & {
38
38
  $context?: string;
39
39
  $id?: string;
40
40
  $_hash?: string;
41
+ $_source?: string;
41
42
  };
42
43
  type VariableProps = {
43
44
  variableType: VariableType;
@@ -78,6 +79,7 @@ type GTContextType = {
78
79
  registerIcuForTranslation: TranslateIcuCallback;
79
80
  registerJsxForTranslation: TranslateChildrenCallback;
80
81
  _tFunction: (message: string, options?: InlineTranslationOptions, preloadedTranslations?: Translations) => string;
82
+ _mFunction: (message: string, options?: Record<string, any>, preloadedTranslations?: Translations) => string;
81
83
  _filterMessagesForPreload: (_messages: _Messages) => _Messages;
82
84
  _preloadMessages: (_messages: _Messages) => Promise<Translations>;
83
85
  _dictionaryFunction: (id: string, options?: DictionaryTranslationOptions) => string;
@@ -121,6 +123,47 @@ defaultLocale, runtimeUrl, renderSettings, setTranslations, ...additionalMetadat
121
123
 
122
124
  declare const renderVariable: RenderVariable;
123
125
 
126
+ /**
127
+ * Encodes content into a message that contains important translation metadata
128
+ * @param message The message to encode.
129
+ * @param options The options to encode.
130
+ * @returns The encoded message.
131
+ *
132
+ * @note - Message format
133
+ * A message is broken into two parts separated by colons:
134
+ * - interpolated content - the content with interpolated variables
135
+ * - hash + options - a unique identifier for the source content and options for the translation
136
+ *
137
+ * @example - Basic usage
138
+ *
139
+ * ```jsx
140
+ * import { msg } from 'gt-react';
141
+ * const message = msg('Hello, {name}!', { name: 'Brian' });
142
+ * console.log(message); // "Hello, Brian:eyIkX2hhc2giOiAiMHgxMjMiLCAiJF9zb3VyY2UiOiAiSGVsbG8sIHtuYW1lfSEiLCAibmFtZSI6ICJCcmlhbiJ9"
143
+ * ```
144
+ * eyIkX2hhc2giOiAiMHgxMjMiLCAiJF9zb3VyY2UiOiAiSGVsbG8sIHtuYW1lfSEiLCAibmFtZSI6ICJCcmlhbiJ9
145
+ * encodes to {"$_hash": "0x123", "$_source": "Hello, {name}!", "name": "Brian"}
146
+ *
147
+ */
148
+ declare function msg(message: string, options?: InlineTranslationOptions): string;
149
+ /**
150
+ * Extracts the original interpolated message string.
151
+ * If the message cannot be decoded (i.e., it does not contain a colon separator),
152
+ * the input is returned as-is.
153
+ * @param encodedMsg The message to decode.
154
+ * @returns The decoded message, or the input if it cannot be decoded.
155
+ */
156
+ declare function decodeMsg(encodedMsg: string): string;
157
+ /**
158
+ * Decodes the options from an encoded message.
159
+ * @param encodedMsg The message to decode.
160
+ * @returns The decoded options.
161
+ */
162
+ declare function decodeOptions(encodedMsg: string): ({
163
+ $_source: string;
164
+ $_hash: string;
165
+ } & InlineTranslationOptions) | null;
166
+
124
167
  type GTConfig = {
125
168
  projectId?: string;
126
169
  devApiKey?: string;
@@ -268,7 +311,7 @@ declare namespace Plural {
268
311
  /**
269
312
  * Gets the translation function `t` provided by `<GTProvider>`.
270
313
  *
271
- * @returns {Function} A translation function that accepts a key string and returns the translated value.
314
+ * @returns {Function} A translation function that accepts an ICU message format string and returns the translation of that string.
272
315
  *
273
316
  * @example
274
317
  * const t = useGT();
@@ -276,12 +319,7 @@ declare namespace Plural {
276
319
  *
277
320
  * @example
278
321
  * const t = useGT();
279
- * return (<>
280
- * {
281
- * t('My name is {customName}', { customName: "Brian", id: 'my-name', context: 'a proper noun' } )
282
- * }
283
- * </>);
284
- *
322
+ * t('My name is {customName}', { customName: "Brian", id: 'my-name', context: 'a proper noun' } )
285
323
  */
286
324
  declare function useGT(_messages?: _Messages): (string: string, options?: Record<string, any> & {
287
325
  $id?: string;
@@ -739,4 +777,21 @@ declare function useRegionSelector({ regions: _regions, customMapping, prioritiz
739
777
  */
740
778
  declare function useLocaleDirection(locale?: string): 'ltr' | 'rtl';
741
779
 
742
- export { Branch, ClientProvider, Currency, DateTime, GTContext, GTProvider, LocaleSelector, Num, Plural, RegionSelector, T, Var, renderVariable, useDefaultLocale, useGT, useGTClass, useLocale, useLocaleDirection, useLocaleProperties, useLocaleSelector, useLocales, useRegion, useRegionSelector, useRuntimeTranslation, useSetLocale, useTranslations };
780
+ /**
781
+ * Gets the message decoding and translation function `m` provided by `<GTProvider>`.
782
+ *
783
+ * @returns {Function} A translation function that accepts an encoded message, decodes it, and returns the translated value.
784
+ *
785
+ * @example
786
+ * const encodedMessage = msg("Hello, world")
787
+ * const m = useMessages();
788
+ * m(encodedMessage) // returns "Hello, world" translated
789
+ *
790
+ * @example
791
+ * const encodedMessage = msg("My name is {name}", { name: "Brian" });
792
+ * const m = useMessages();
793
+ * m(encodedMessage) // returns "My name is Brian" translated
794
+ */
795
+ declare function useMessages(_messages?: _Messages): (encodedMsg: string, options?: Record<string, any>) => string;
796
+
797
+ export { Branch, ClientProvider, Currency, DateTime, GTContext, GTProvider, LocaleSelector, Num, Plural, RegionSelector, T, Var, decodeMsg, decodeOptions, msg, renderVariable, useDefaultLocale, useGT, useGTClass, useLocale, useLocaleDirection, useLocaleProperties, useLocaleSelector, useLocales, useMessages, useRegion, useRegionSelector, useRuntimeTranslation, useSetLocale, useTranslations };
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,qBAAqB,MAAM,wCAAwC,CAAC;AAC3E,OAAO,cAAc,MAAM,4BAA4B,CAAC;AACxD,OAAO,cAAc,MAAM,2BAA2B,CAAC;AACvD,OAAO,MAAM,MAAM,mBAAmB,CAAC;AACvC,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,KAAK,MAAM,2BAA2B,CAAC;AAC9C,OAAO,gBAAgB,MAAM,0BAA0B,CAAC;AACxD,OAAO,eAAe,MAAM,qCAAqC,CAAC;AAClE,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAC1C,OAAO,CAAC,MAAM,wBAAwB,CAAC;AACvC,OAAO,QAAQ,MAA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