@candidosales/svelte-google-translate 0.0.3 → 0.0.4
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/.eslintignore +13 -0
- package/.eslintrc.cjs +20 -0
- package/.prettierignore +13 -0
- package/.prettierrc +9 -0
- package/docs/screenshot-svelte-google-translate.png +0 -0
- package/package.json +55 -47
- package/src/app.d.ts +11 -0
- package/src/app.html +12 -0
- package/src/lib/GoogleTranslate.svelte +89 -0
- package/src/lib/index.js +2 -0
- package/src/routes/+page.svelte +12 -0
- package/static/favicon.png +0 -0
- package/svelte.config.js +15 -0
- package/tsconfig.json +17 -0
- package/vite.config.js +8 -0
- /package/{GoogleTranslate.svelte → dist/GoogleTranslate.svelte} +0 -0
- /package/{GoogleTranslate.svelte.d.ts → dist/GoogleTranslate.svelte.d.ts} +0 -0
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{index.js → dist/index.js} +0 -0
package/.eslintignore
ADDED
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
parser: '@typescript-eslint/parser',
|
|
4
|
+
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
|
|
5
|
+
plugins: ['svelte3', '@typescript-eslint'],
|
|
6
|
+
ignorePatterns: ['*.cjs'],
|
|
7
|
+
overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }],
|
|
8
|
+
settings: {
|
|
9
|
+
'svelte3/typescript': () => require('typescript')
|
|
10
|
+
},
|
|
11
|
+
parserOptions: {
|
|
12
|
+
sourceType: 'module',
|
|
13
|
+
ecmaVersion: 2020
|
|
14
|
+
},
|
|
15
|
+
env: {
|
|
16
|
+
browser: true,
|
|
17
|
+
es2017: true,
|
|
18
|
+
node: true
|
|
19
|
+
}
|
|
20
|
+
};
|
package/.prettierignore
ADDED
package/.prettierrc
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,48 +1,56 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
2
|
+
"name": "@candidosales/svelte-google-translate",
|
|
3
|
+
"description": "Google Translate component for Svelte",
|
|
4
|
+
"version": "0.0.4",
|
|
5
|
+
"author": {
|
|
6
|
+
"email": "candidosg@gmail.com",
|
|
7
|
+
"name": "Cândido Sales Gomes"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"dev": "vite dev",
|
|
11
|
+
"preview": "vite preview",
|
|
12
|
+
"build": "vite build && svelte-kit sync && svelte-package",
|
|
13
|
+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
14
|
+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
|
15
|
+
"lint": "prettier --plugin-search-dir . --check . && eslint .",
|
|
16
|
+
"format": "prettier --plugin-search-dir . --write .",
|
|
17
|
+
"package": "svelte-package"
|
|
18
|
+
},
|
|
19
|
+
"main": "index.js",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"svelte": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"svelte",
|
|
28
|
+
"sveltekit",
|
|
29
|
+
"google-translate"
|
|
30
|
+
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"svelte": "^3.56.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@sveltejs/adapter-auto": "^2.0.0",
|
|
36
|
+
"@sveltejs/kit": "next",
|
|
37
|
+
"@sveltejs/package": "^2.0.2",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^5.55.0",
|
|
39
|
+
"@typescript-eslint/parser": "^5.55.0",
|
|
40
|
+
"eslint": "^8.36.0",
|
|
41
|
+
"eslint-config-prettier": "^8.7.0",
|
|
42
|
+
"eslint-plugin-svelte3": "^4.0.0",
|
|
43
|
+
"prettier": "^2.8.4",
|
|
44
|
+
"prettier-plugin-svelte": "^2.9.0",
|
|
45
|
+
"svelte-check": "^3.1.4",
|
|
46
|
+
"svelte2tsx": "^0.6.9",
|
|
47
|
+
"tslib": "^2.5.0",
|
|
48
|
+
"typescript": "^4.9.5",
|
|
49
|
+
"vite": "^4.1.4"
|
|
50
|
+
},
|
|
51
|
+
"type": "module",
|
|
52
|
+
"bugs": {
|
|
53
|
+
"url": "https://github.com/candidosales/svelte-google-translate/issues"
|
|
54
|
+
},
|
|
55
|
+
"license": "MIT"
|
|
56
|
+
}
|
package/src/app.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="@sveltejs/kit" />
|
|
2
|
+
|
|
3
|
+
// See https://kit.svelte.dev/docs/types#app
|
|
4
|
+
// for information about these interfaces
|
|
5
|
+
// and what to do when importing types
|
|
6
|
+
declare namespace App {
|
|
7
|
+
// interface Error {}
|
|
8
|
+
// interface Locals {}
|
|
9
|
+
// interface PageData {}
|
|
10
|
+
// interface Platform {}
|
|
11
|
+
}
|
package/src/app.html
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
|
+
%sveltekit.head%
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div>%sveltekit.body%</div>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount } from 'svelte';
|
|
3
|
+
|
|
4
|
+
type InlineLayout = 'horizontal' | 'vertical' | 'dropdown';
|
|
5
|
+
type FloatPosition = 'TOP_LEFT' | 'TOP_RIGHT' | 'BOTTOM_LEFT' | 'BOTTOM_RIGHT';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Interface for a TranslateElementOptions object.
|
|
9
|
+
*/
|
|
10
|
+
interface TranslateElementOptions {
|
|
11
|
+
/**
|
|
12
|
+
* This option specifies the language of the page that you want to translate. The default value is "auto", which means that Google will detect the language automatically.
|
|
13
|
+
*/
|
|
14
|
+
pageLanguage?: string;
|
|
15
|
+
/**
|
|
16
|
+
* This option is an array of language codes that you want to include in the language selector. If you don't specify this option, Google will include all languages that are supported by the API.
|
|
17
|
+
* Supported languages: https://cloud.google.com/translate/docs/languages
|
|
18
|
+
*/
|
|
19
|
+
includedLanguages?: string;
|
|
20
|
+
/**
|
|
21
|
+
* This option specifies the layout of the language selector. The default value is "horizontal", which displays the language names in a row. Other options include "vertical" (displays the language names in a column) and "dropdown" (displays the language names in a dropdown menu).
|
|
22
|
+
*/
|
|
23
|
+
layout?: InlineLayout;
|
|
24
|
+
/**
|
|
25
|
+
* This option specifies whether or not to display the language selector automatically. The default value is true.
|
|
26
|
+
*/
|
|
27
|
+
autoDisplay?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* This option specifies whether or not the page being translated contains multiple languages. The default value is false.
|
|
30
|
+
*/
|
|
31
|
+
multilanguagePage?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* This option specifies whether or not to track translation events using Google Analytics. The default value is false.
|
|
34
|
+
*/
|
|
35
|
+
gaTrack?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* This option specifies the Google Analytics tracking ID to use if gaTrack is set to true.
|
|
38
|
+
*/
|
|
39
|
+
gaId?: string;
|
|
40
|
+
/**
|
|
41
|
+
* This option specifies whether to use a compact layout for the language selector. The default value is false.
|
|
42
|
+
*/
|
|
43
|
+
layoutCompact?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* This option specifies the position of the language selector if layoutCompact is set to true. The default value is "TOP_LEFT", other options include "TOP_RIGHT", "BOTTOM_LEFT", and "BOTTOM_RIGHT".
|
|
46
|
+
*/
|
|
47
|
+
floatPosition?: FloatPosition;
|
|
48
|
+
/**
|
|
49
|
+
* This option specifies the time in milliseconds before the API returns an error if it fails to load. The default value is 5000.
|
|
50
|
+
*/
|
|
51
|
+
timeout?: number;
|
|
52
|
+
/**
|
|
53
|
+
* This option specifies whether to use the new version of the Google Translate API. The default value is false.
|
|
54
|
+
*/
|
|
55
|
+
newVersion?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* This option specifies whether to display the "Powered by Google Translate" attribution. The default value is true.
|
|
58
|
+
*/
|
|
59
|
+
attribution?: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export let elementId: HTMLElement | string = 'google-translate-element';
|
|
63
|
+
|
|
64
|
+
export let options: TranslateElementOptions = {
|
|
65
|
+
pageLanguage: 'pt',
|
|
66
|
+
includedLanguages: 'pt,en,es,fr,nl,ja,zh-CN',
|
|
67
|
+
autoDisplay: false
|
|
68
|
+
};
|
|
69
|
+
onMount(() => {
|
|
70
|
+
googleTranslateInit();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
function googleTranslateInit() {
|
|
74
|
+
setTimeout(function () {
|
|
75
|
+
if (
|
|
76
|
+
typeof google !== 'undefined' &&
|
|
77
|
+
google != null &&
|
|
78
|
+
google.translate != null &&
|
|
79
|
+
google.translate.TranslateElement != null
|
|
80
|
+
) {
|
|
81
|
+
new google.translate.TranslateElement(options, elementId);
|
|
82
|
+
}
|
|
83
|
+
}, 300);
|
|
84
|
+
}
|
|
85
|
+
</script>
|
|
86
|
+
|
|
87
|
+
<svelte:head>
|
|
88
|
+
<script async src="https://translate.google.com/translate_a/element.js"></script>
|
|
89
|
+
</svelte:head>
|
package/src/lib/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import GoogleTranslate from '$lib/GoogleTranslate.svelte';
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<h1>Svelte Google Translate</h1>
|
|
6
|
+
<GoogleTranslate
|
|
7
|
+
elementId="google-translate-element"
|
|
8
|
+
options={{ pageLanguage: 'pt', includedLanguages: 'pt,en' }}
|
|
9
|
+
/>
|
|
10
|
+
<div id="google-translate-element">
|
|
11
|
+
<p>Test</p>
|
|
12
|
+
</div>
|
|
Binary file
|
package/svelte.config.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import adapter from '@sveltejs/adapter-auto';
|
|
2
|
+
import { vitePreprocess } from '@sveltejs/kit/vite';
|
|
3
|
+
|
|
4
|
+
/** @type {import('@sveltejs/kit').Config} */
|
|
5
|
+
const config = {
|
|
6
|
+
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
|
|
7
|
+
// for more information about preprocessors
|
|
8
|
+
preprocess: vitePreprocess(),
|
|
9
|
+
|
|
10
|
+
kit: {
|
|
11
|
+
adapter: adapter()
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default config;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./.svelte-kit/tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"allowJs": true,
|
|
5
|
+
"checkJs": true,
|
|
6
|
+
"esModuleInterop": true,
|
|
7
|
+
"forceConsistentCasingInFileNames": true,
|
|
8
|
+
"resolveJsonModule": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"strict": true
|
|
12
|
+
}
|
|
13
|
+
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
|
|
14
|
+
//
|
|
15
|
+
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
|
|
16
|
+
// from the referenced tsconfig.json - TypeScript does not merge them in
|
|
17
|
+
}
|
package/vite.config.js
ADDED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|