@tolgee/svelte 3.6.0 → 4.0.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.
- package/CHANGELOG.md +16 -0
- package/README.md +1 -1
- package/T.svelte +28 -42
- package/T.svelte.d.ts +3 -4
- package/TolgeeProvider.svelte +4 -1
- package/getTranslate.js +25 -4
- package/package.json +6 -5
- package/types.d.ts +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [4.0.0](https://github.com/tolgee/tolgee-js/compare/v3.6.0...v4.0.0) (2022-03-10)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Use invisible wrapping instead of span component ([3848cda](https://github.com/tolgee/tolgee-js/commit/3848cdaf70fe9c76fd56c88d3c7399b87ff0f88b))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### BREAKING CHANGES
|
|
15
|
+
|
|
16
|
+
* default invisible mode, defaultValue
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
# [3.6.0](https://github.com/tolgee/tolgee-js/compare/v3.5.0...v3.6.0) (2022-02-28)
|
|
7
23
|
|
|
8
24
|
**Note:** Version bump only for package @tolgee/svelte
|
package/README.md
CHANGED
package/T.svelte
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
|
-
<script >import getTolgeeContext from
|
|
2
|
-
import { onDestroy } from
|
|
1
|
+
<script >import getTolgeeContext from './getTolgeeContext';
|
|
2
|
+
import { onDestroy } from 'svelte';
|
|
3
3
|
export let keyName;
|
|
4
4
|
export let parameters = undefined;
|
|
5
|
-
export let
|
|
5
|
+
export let noWrap = false;
|
|
6
|
+
export let defaultValue = undefined;
|
|
6
7
|
if (!keyName) {
|
|
7
|
-
console.error(
|
|
8
|
-
// show the error in the DOM
|
|
9
|
-
keyName = "Tolgee: Missing key name prop!";
|
|
10
|
-
strategy = "NO_WRAP";
|
|
8
|
+
console.error('Missing keyName prop!');
|
|
11
9
|
}
|
|
12
|
-
const translationFnNoWrap = strategy === "NO_WRAP" || strategy === "ELEMENT_WRAP";
|
|
13
10
|
const tolgeeContext = getTolgeeContext();
|
|
14
|
-
let translated =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
let translated = keyName
|
|
12
|
+
? tolgeeContext.tolgee.instant(keyName, parameters, noWrap, true)
|
|
13
|
+
: '';
|
|
14
|
+
const translate = () => {
|
|
15
|
+
if (keyName) {
|
|
16
|
+
tolgeeContext.tolgee
|
|
17
|
+
.translate({
|
|
18
|
+
key: keyName,
|
|
19
|
+
params: parameters,
|
|
20
|
+
noWrap,
|
|
21
|
+
defaultValue,
|
|
22
|
+
})
|
|
23
|
+
.then((result) => {
|
|
24
|
+
translated = result;
|
|
25
|
+
})
|
|
26
|
+
.catch(() => {
|
|
27
|
+
console.error('Failed to resolve translation for key: ', keyName);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
25
31
|
const onTranslationChangeSubscription = tolgeeContext.tolgee.onTranslationChange.subscribe((changeData) => {
|
|
26
32
|
if (changeData.key === keyName) {
|
|
27
33
|
translate();
|
|
@@ -30,33 +36,13 @@ const onTranslationChangeSubscription = tolgeeContext.tolgee.onTranslationChange
|
|
|
30
36
|
const onLangChangeSubscription = tolgeeContext.tolgee.onLangChange.subscribe(() => {
|
|
31
37
|
translate();
|
|
32
38
|
});
|
|
33
|
-
if (typeof window !==
|
|
39
|
+
if (typeof window !== 'undefined') {
|
|
34
40
|
onDestroy(() => {
|
|
35
41
|
onTranslationChangeSubscription.unsubscribe();
|
|
36
42
|
onLangChangeSubscription.unsubscribe();
|
|
37
43
|
});
|
|
38
44
|
}
|
|
39
|
-
$:
|
|
45
|
+
$: translate();
|
|
40
46
|
</script>
|
|
41
47
|
|
|
42
|
-
{
|
|
43
|
-
<span data-tolgee-key-only={keyName} bind:this={spanWrapperRef}>
|
|
44
|
-
{#if !translated}
|
|
45
|
-
{#if $$slots.default}
|
|
46
|
-
<slot />
|
|
47
|
-
{:else}
|
|
48
|
-
{keyName}
|
|
49
|
-
{/if}
|
|
50
|
-
{:else}
|
|
51
|
-
{translated}
|
|
52
|
-
{/if}
|
|
53
|
-
</span>
|
|
54
|
-
{:else if !translated}
|
|
55
|
-
{#if $$slots.default}
|
|
56
|
-
<slot />
|
|
57
|
-
{:else}
|
|
58
|
-
{keyName}
|
|
59
|
-
{/if}
|
|
60
|
-
{:else}
|
|
61
|
-
{translated}
|
|
62
|
-
{/if}
|
|
48
|
+
{translated}
|
package/T.svelte.d.ts
CHANGED
|
@@ -3,14 +3,13 @@ declare const __propDef: {
|
|
|
3
3
|
props: {
|
|
4
4
|
keyName: string;
|
|
5
5
|
parameters?: Record<string, any> | undefined;
|
|
6
|
-
|
|
6
|
+
noWrap?: boolean;
|
|
7
|
+
defaultValue?: any;
|
|
7
8
|
};
|
|
8
9
|
events: {
|
|
9
10
|
[evt: string]: CustomEvent<any>;
|
|
10
11
|
};
|
|
11
|
-
slots: {
|
|
12
|
-
default: {};
|
|
13
|
-
};
|
|
12
|
+
slots: {};
|
|
14
13
|
};
|
|
15
14
|
export declare type TProps = typeof __propDef.props;
|
|
16
15
|
export declare type TEvents = typeof __propDef.events;
|
package/TolgeeProvider.svelte
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
<script >import { onDestroy, onMount, setContext } from 'svelte';
|
|
2
2
|
import { IcuFormatter, Tolgee, TolgeeConfig } from '@tolgee/core';
|
|
3
3
|
export let config;
|
|
4
|
-
const tolgee = Tolgee.use(IcuFormatter).init(
|
|
4
|
+
const tolgee = Tolgee.use(IcuFormatter).init({
|
|
5
|
+
wrapperMode: 'invisible',
|
|
6
|
+
...(config || new TolgeeConfig()),
|
|
7
|
+
});
|
|
5
8
|
let tolgeeRunPromise;
|
|
6
9
|
setContext('tolgeeContext', {
|
|
7
10
|
tolgee,
|
package/getTranslate.js
CHANGED
|
@@ -58,11 +58,32 @@ const getTranslate = () => {
|
|
|
58
58
|
// return new translate method when something is changed
|
|
59
59
|
return derived(
|
|
60
60
|
// when updateStore changes, translate function gets changed as well
|
|
61
|
-
updateStore, () => (
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
updateStore, () => (keyOrProps, ...params) => {
|
|
62
|
+
let parameters = undefined;
|
|
63
|
+
let noWrap = undefined;
|
|
64
|
+
let defaultValue = undefined;
|
|
65
|
+
// allow user to pass object of params and make the code cleaner
|
|
66
|
+
const key = typeof keyOrProps === 'object' ? keyOrProps.key : keyOrProps;
|
|
67
|
+
if (typeof keyOrProps === 'object') {
|
|
68
|
+
parameters = keyOrProps.parameters;
|
|
69
|
+
noWrap = keyOrProps.noWrap;
|
|
70
|
+
defaultValue = keyOrProps.defaultValue;
|
|
64
71
|
}
|
|
65
|
-
|
|
72
|
+
else {
|
|
73
|
+
params.forEach((param) => {
|
|
74
|
+
switch (typeof param) {
|
|
75
|
+
case 'object':
|
|
76
|
+
parameters = param;
|
|
77
|
+
break;
|
|
78
|
+
case 'boolean':
|
|
79
|
+
noWrap = param;
|
|
80
|
+
break;
|
|
81
|
+
case 'string':
|
|
82
|
+
defaultValue = param;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return translate(key, parameters, noWrap, defaultValue);
|
|
66
87
|
});
|
|
67
88
|
};
|
|
68
89
|
export default getTranslate;
|
package/package.json
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tolgee/svelte",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"
|
|
5
|
+
"jest-fetch-mock": "^3.0.3"
|
|
6
6
|
},
|
|
7
7
|
"devDependencies": {
|
|
8
8
|
"@sveltejs/kit": "next",
|
|
9
9
|
"@testing-library/jest-dom": "5.16.2",
|
|
10
10
|
"@testing-library/svelte": "3.0.3",
|
|
11
|
+
"@tolgee/core": "^4.0.0",
|
|
11
12
|
"@types/jest": "27.4.1",
|
|
12
13
|
"@typescript-eslint/eslint-plugin": "^5.12.1",
|
|
13
|
-
"@typescript-eslint/parser": "^5.
|
|
14
|
+
"@typescript-eslint/parser": "^5.14.0",
|
|
14
15
|
"eslint": "^8.10.0",
|
|
15
|
-
"eslint-config-prettier": "^8.
|
|
16
|
+
"eslint-config-prettier": "^8.5.0",
|
|
16
17
|
"eslint-plugin-svelte3": "^3.4.1",
|
|
17
18
|
"jest": "27.5.1",
|
|
18
19
|
"nodemon": "^2.0.15",
|
|
@@ -25,7 +26,7 @@
|
|
|
25
26
|
"svelte2tsx": "0.5.5",
|
|
26
27
|
"ts-jest": "27.1.3",
|
|
27
28
|
"tslib": "^2.3.1",
|
|
28
|
-
"typescript": "^4.
|
|
29
|
+
"typescript": "^4.6.2"
|
|
29
30
|
},
|
|
30
31
|
"type": "module",
|
|
31
32
|
"publishConfig": {
|
package/types.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import type { TranslationParams } from '@tolgee/core';
|
|
1
2
|
import type { Readable } from 'svelte/store';
|
|
2
|
-
export declare type TranslationParameters = {
|
|
3
|
-
[key: string]: string;
|
|
4
|
-
};
|
|
5
3
|
export declare type GetTranslateResultFnProps = {
|
|
6
4
|
key: string;
|
|
7
|
-
parameters?:
|
|
5
|
+
parameters?: TranslationParams;
|
|
8
6
|
noWrap?: boolean;
|
|
9
7
|
defaultValue?: string;
|
|
10
8
|
};
|
|
11
9
|
export declare type GetTranslateType = () => Readable<{
|
|
12
10
|
(props: GetTranslateResultFnProps): string;
|
|
13
|
-
(key: string,
|
|
11
|
+
(key: string, defaultValue?: string, noWrap?: boolean): string;
|
|
12
|
+
(key: string, defaultValue?: string, parameters?: TranslationParams): string;
|
|
13
|
+
(key: string, parameters?: TranslationParams, defaultValue?: string): string;
|
|
14
|
+
(key: string, parameters?: TranslationParams, noWrap?: boolean, defaultValue?: string): string;
|
|
14
15
|
}>;
|