@everymatrix/player-email-verification 1.30.0 → 1.31.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@everymatrix/player-email-verification",
3
- "version": "1.30.0",
3
+ "version": "1.31.0",
4
4
  "main": "dist/player-email-verification",
5
5
  "svelte": "src/index.ts",
6
6
  "scripts": {
@@ -35,5 +35,5 @@
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "gitHead": "b9795b320e7d96e10963f25cdea2d9300029d8d7"
38
+ "gitHead": "2cd63cac8a1345eb832337233e848d196c3d9a7b"
39
39
  }
@@ -1,8 +1,38 @@
1
1
  <svelte:options tag={null} />
2
2
 
3
3
  <script lang="ts">
4
+ import { _, addNewMessages, setLocale } from './i18n';
5
+ import { TRANSLATIONS } from './translations';
6
+
7
+ export let lang:string = 'en';
4
8
  export let endpoint:string = '';
5
9
  export let key:string = '';
10
+ export let translationurl:string = '';
11
+
12
+ const setTranslationUrl = ():void => {
13
+ let url:string = translationurl;
14
+
15
+ fetch(url).then((res:any) => res.json())
16
+ .then((res) => {
17
+ Object.keys(res).forEach((item:any):void => {
18
+ addNewMessages(item, res[item]);
19
+ });
20
+ }).catch((err:any) => {
21
+ console.log(err);
22
+ });
23
+ }
24
+
25
+ Object.keys(TRANSLATIONS).forEach((item:any):void => {
26
+ addNewMessages(item, TRANSLATIONS[item]);
27
+ });
28
+
29
+ const goToHome = ():void => {
30
+ window.postMessage({ type: 'GoToHomepage' }, window.location.href);
31
+ }
32
+
33
+ const setActiveLanguage = ():void => {
34
+ setLocale(lang);
35
+ }
6
36
 
7
37
  const sendKey = ():void => {
8
38
  let url:URL = new URL(`${endpoint}/v1/player/activatePlayerByHashKey`);
@@ -26,41 +56,37 @@
26
56
  window.postMessage({ type: 'ActivatePlayerResponseFailed' }, window.location.href);
27
57
  window.postMessage({ type: 'WidgetNotification', data: {
28
58
  type: 'error',
29
- message: 'Server unavailable'
59
+ message: $_('errServerUnavailable')
30
60
  }}, window.location.href);
31
61
  }
32
62
  return res.json();
33
63
  })
34
64
  .then((data:any) => {
35
- let message;
36
65
 
37
66
  window.postMessage({ type: 'ActivatePlayerResponse', data }, window.location.href);
38
67
 
39
68
  if (data.error) {
40
- // Parsing GMCore message 'cuz it's stupid and it doesn't know how to send error messages in 2021 ffs
41
- // LE: Yea, I'm adding this here too :) I won't let anyone forget that GMCore doesn't know how to send an error over the API, in 2022!!!
42
- message = data.error.substring(data.error.indexOf('errorMessage') + 13, data.error.length);
43
- message = message.substring(0, message.indexOf('errorCode'));
44
-
45
69
  window.postMessage({ type: 'WidgetNotification', data: {
46
70
  type: 'error',
47
- message: 'Sorry! Your e-mail could not be verified. Please try again.'
71
+ message: $_('errEmailVerification')
48
72
  }}, window.location.href);
49
73
  window.postMessage({ type: 'WidgetNotification', data: {
50
74
  type: 'info',
51
- message
75
+ message: $_('infoInvalidHashKey')
52
76
  }}, window.location.href);
53
77
  }
54
78
 
55
79
  if (data.SESSION_ID) {
56
80
  window.postMessage({ type: 'WidgetNotification', data: {
57
81
  type: 'success',
58
- message: 'Success! Your e-mail has been successfully verified.'
82
+ message: $_('msgEmailVerificationSuccess')
59
83
  }}, window.location.href);
60
84
  }
61
85
  });
62
86
  }
63
87
 
88
+ $: lang && setActiveLanguage();
89
+ $: translationurl && setTranslationUrl();
64
90
  $: endpoint && key && sendKey();
65
91
  </script>
66
92
 
package/src/i18n.js ADDED
@@ -0,0 +1,27 @@
1
+ import {
2
+ dictionary,
3
+ locale,
4
+ addMessages,
5
+ _
6
+ } from 'svelte-i18n';
7
+
8
+ function setupI18n({ withLocale: _locale, translations }) {
9
+ locale.subscribe((data) => {
10
+ if (data == null) {
11
+ dictionary.set(translations);
12
+ locale.set(_locale);
13
+ }
14
+ }); // maybe we will need this to make sure that the i18n is set up only once
15
+ /*dictionary.set(translations);
16
+ locale.set(_locale);*/
17
+ }
18
+
19
+ function addNewMessages(lang, dict) {
20
+ addMessages(lang, dict);
21
+ }
22
+
23
+ function setLocale(_locale) {
24
+ locale.set(_locale);
25
+ }
26
+
27
+ export { _, setupI18n, addNewMessages, setLocale };
@@ -0,0 +1,14 @@
1
+ export const TRANSLATIONS = {
2
+ "en": {
3
+ "errServerUnavailable": "Server unavailable",
4
+ "errEmailVerification": "Sorry! Your e-mail could not be verified. Please try again",
5
+ "infoInvalidHashKey": "Invalid, used or expired hash key",
6
+ "msgEmailVerificationSuccess": "Success! Your e-mail has been successfully verified",
7
+ },
8
+ "ro": {
9
+ "errServerUnavailable": "Server indisponibil",
10
+ "errEmailVerification": "Ne pare rău! E-mailul tău nu a putut fi verificat. Te rugăm să încerci din nou",
11
+ "infoInvalidHashKey": "Cheie hash invalidă, utilizată sau expirată",
12
+ "msgEmailVerificationSuccess": "Succes! E-mailul tău a fost verificat cu succes"
13
+ }
14
+ }