@tolgee/core 5.7.3 → 5.8.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.
@@ -5,7 +5,7 @@ declare type StateServiceProps = {
5
5
  export declare const Controller: ({ options }: StateServiceProps) => Readonly<{
6
6
  init: (options: Partial<TolgeeOptions>) => void;
7
7
  changeLanguage: (language: string) => Promise<void>;
8
- getTranslation: ({ key, ns }: KeyAndNamespacesInternal) => string | undefined;
8
+ getTranslation: ({ key, ns, language }: KeyAndNamespacesInternal) => string | undefined;
9
9
  changeTranslation: (descriptor: CacheDescriptor, key: string, value: string) => {
10
10
  revert: () => void;
11
11
  };
@@ -12,6 +12,7 @@ export declare type TranslateOptions = {
12
12
  ns?: NsType | null;
13
13
  noWrap?: boolean;
14
14
  orEmpty?: boolean;
15
+ language?: string;
15
16
  };
16
17
  export declare type TranslateProps<T = DefaultParamType, K extends string = TranslationKey> = {
17
18
  key: K;
@@ -30,5 +31,5 @@ export declare type TFnType<T = DefaultParamType, R = string, K extends string =
30
31
  (key: K, options?: CombinedOptions<T>): R;
31
32
  (props: TranslateProps<T, K>): R;
32
33
  };
33
- export declare type KeyAndNamespacesInternal = Pick<TranslatePropsInternal, 'key' | 'ns'>;
34
+ export declare type KeyAndNamespacesInternal = Pick<TranslatePropsInternal, 'key' | 'ns' | 'language'>;
34
35
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolgee/core",
3
- "version": "5.7.3",
3
+ "version": "5.8.0",
4
4
  "description": "Library providing ability to translate messages directly in context of developed application.",
5
5
  "main": "./dist/tolgee.cjs.js",
6
6
  "module": "./dist/tolgee.esm.js",
@@ -67,5 +67,5 @@
67
67
  "access": "public"
68
68
  },
69
69
  "sideEffects": false,
70
- "gitHead": "fde08c663fc22333a09c1a6f8e976d16c500e79e"
70
+ "gitHead": "a6185bf50f9319a81cbd4d768daf56417427d14e"
71
71
  }
@@ -195,9 +195,9 @@ export const Controller = ({ options }: StateServiceProps) => {
195
195
  return cache.getTranslationNs(namespaces, languages, key);
196
196
  }
197
197
 
198
- function getTranslation({ key, ns }: KeyAndNamespacesInternal) {
198
+ function getTranslation({ key, ns, language }: KeyAndNamespacesInternal) {
199
199
  const namespaces = getDefaultAndFallbackNs(ns || undefined);
200
- const languages = state.getFallbackLangs();
200
+ const languages = state.getFallbackLangs(language);
201
201
  return cache.getTranslationFallback(namespaces, languages, key);
202
202
  }
203
203
 
@@ -10,12 +10,14 @@ function parseCombinedOptions({
10
10
  noWrap,
11
11
  orEmpty,
12
12
  params,
13
+ language,
13
14
  ...rest
14
15
  }: Partial<TranslateProps>): Partial<TranslateProps> {
15
16
  const options: Required<TranslateOptions> = {
16
17
  ns: ns!,
17
18
  noWrap: noWrap!,
18
19
  orEmpty: orEmpty!,
20
+ language: language!,
19
21
  };
20
22
  return {
21
23
  ...options,
@@ -187,4 +187,17 @@ describe('cache', () => {
187
187
  await Promise.resolve();
188
188
  expect(tolgee.t('test.sub')).toEqual('en.default');
189
189
  });
190
+
191
+ it('language prop overrides current language', () => {
192
+ tolgee = TolgeeCore().init({
193
+ language: 'en',
194
+ staticData: {
195
+ en: { hello: 'Hello' },
196
+ cs: { hello: 'Ahoj' },
197
+ },
198
+ });
199
+
200
+ expect(tolgee.t('hello')).toEqual('Hello');
201
+ expect(tolgee.t('hello', { language: 'cs' })).toEqual('Ahoj');
202
+ });
190
203
  });
@@ -22,6 +22,7 @@ export type TranslateOptions = {
22
22
  ns?: NsType | null;
23
23
  noWrap?: boolean;
24
24
  orEmpty?: boolean;
25
+ language?: string;
25
26
  };
26
27
 
27
28
  export type TranslateProps<
@@ -55,5 +56,5 @@ export type TFnType<
55
56
 
56
57
  export type KeyAndNamespacesInternal = Pick<
57
58
  TranslatePropsInternal,
58
- 'key' | 'ns'
59
+ 'key' | 'ns' | 'language'
59
60
  >;