@lookit/templates 1.1.0 → 2.1.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": "@lookit/templates",
3
- "version": "1.1.0",
3
+ "version": "2.1.0",
4
4
  "description": "CHS jsPsych trial templates and their translations",
5
5
  "homepage": "https://github.com/lookit/lookit-jspsych#readme",
6
6
  "bugs": {
@@ -24,18 +24,21 @@
24
24
  "dev": "rollup --config rollup.config.dev.mjs --watch",
25
25
  "test": "jest --coverage"
26
26
  },
27
- "devDependencies": {
28
- "@jspsych/config": "^2.0.0",
29
- "@types/js-yaml": "^4.0.9",
27
+ "dependencies": {
30
28
  "handlebars": "^4.7.8",
31
29
  "i18next": "^23.16.4",
32
30
  "i18next-icu": "^2.3.0",
33
- "js-yaml": "^4.1.0",
31
+ "js-yaml": "^4.1.0"
32
+ },
33
+ "devDependencies": {
34
+ "@jspsych/config": "^3.0.1",
35
+ "@rollup/plugin-node-resolve": "^15.3.0",
36
+ "@types/js-yaml": "^4.0.9",
34
37
  "rollup-plugin-dotenv": "^0.5.1",
35
- "rollup-plugin-polyfill-node": "^0.13.0"
38
+ "rollup-plugin-string": "^3.0.0"
36
39
  },
37
40
  "peerDependencies": {
38
- "@lookit/data": "^0.1.0",
39
- "jspsych": "^8.0.2"
41
+ "@lookit/data": "^0.2.0",
42
+ "jspsych": "^8.0.3"
40
43
  }
41
44
  }
@@ -10,6 +10,7 @@ import { setLocale } from "./utils";
10
10
  declare const window: LookitWindow;
11
11
 
12
12
  const video_container_id = "lookit-jspsych-video-container";
13
+ const msg_container_id = "lookit-jspsych-video-msg-container";
13
14
 
14
15
  /**
15
16
  * Translate, render, and get consent document HTML.
@@ -36,6 +37,7 @@ export const consentVideo = (trial: TrialType<PluginInfo>) => {
36
37
  ...trial,
37
38
  consent,
38
39
  video_container_id,
40
+ msg_container_id,
39
41
  });
40
42
  };
41
43
 
package/src/index.ts CHANGED
@@ -1,6 +1,13 @@
1
1
  import { consentVideo } from "./consentVideoTemplate";
2
2
  import { exitSurvey } from "./exitSurveyTemplate";
3
3
  import { uploadingVideo } from "./uploadingVideoTemplate";
4
+ import { translateString } from "./utils";
4
5
  import { videoConfig } from "./videoConfigTemplate";
5
6
 
6
- export default { consentVideo, videoConfig, uploadingVideo, exitSurvey };
7
+ export default {
8
+ consentVideo,
9
+ videoConfig,
10
+ uploadingVideo,
11
+ exitSurvey,
12
+ translateString,
13
+ };
package/src/utils.spec.ts CHANGED
@@ -1,6 +1,7 @@
1
+ import i18next from "i18next";
1
2
  import { PluginInfo, TrialType } from "jspsych";
2
3
  import { LocaleNotFoundError } from "./errors";
3
- import { expFormat, setLocale } from "./utils";
4
+ import { expFormat, setLocale, translateString } from "./utils";
4
5
 
5
6
  test("expFormat convert written text to format well in HTML", () => {
6
7
  expect(expFormat("abcdefg")).toStrictEqual("abcdefg");
@@ -25,3 +26,12 @@ test("setLocale throw error with non-existing locale", () => {
25
26
  const trial = { locale: "non-existing" } as unknown as TrialType<PluginInfo>;
26
27
  expect(() => setLocale(trial)).toThrow(LocaleNotFoundError);
27
28
  });
29
+
30
+ test("translateString translates the string with the appropriate locale", () => {
31
+ const en = new Intl.Locale("en-us");
32
+ i18next.changeLanguage(en.baseName);
33
+ expect(translateString("Continue")).toBe("Continue");
34
+ const fr = new Intl.Locale("fr");
35
+ i18next.changeLanguage(fr.baseName);
36
+ expect(translateString("Continue")).toBe("Continuer");
37
+ });
package/src/utils.ts CHANGED
@@ -92,3 +92,15 @@ Handlebars.registerHelper("t", (context, { hash }) => {
92
92
  const txt = String(i18next.t(context, hash));
93
93
  return hash.htmlSafe ? new Handlebars.SafeString(txt) : txt;
94
94
  });
95
+
96
+ /**
97
+ * Public method for directly translating a string, without a corresponding
98
+ * template.
99
+ *
100
+ * @param messageIdStr - Message ID string to be looked up in the translation
101
+ * files.
102
+ * @returns Translated string
103
+ */
104
+ export const translateString = (messageIdStr: string) => {
105
+ return i18next.t(messageIdStr);
106
+ };
@@ -1,8 +0,0 @@
1
- import { PluginInfo, TrialType } from "jspsych";
2
- /**
3
- * Translate, render, and get consent document HTML.
4
- *
5
- * @param trial - JsPsych trial object containing trial params
6
- * @returns Consent document HTML
7
- */
8
- export declare const consentVideo: (trial: TrialType<PluginInfo>) => string;
package/dist/errors.d.ts DELETED
@@ -1,18 +0,0 @@
1
- /** Error thrown when specified language isn't found */
2
- export declare class LocaleNotFoundError extends Error {
3
- /**
4
- * This will be thrown when attempting to init i18n
5
- *
6
- * @param baseName - Language a2code with region
7
- */
8
- constructor(baseName: string);
9
- }
10
- /** Error thrown when researcher selects template that isn't available. */
11
- export declare class ConsentTemplateNotFound extends Error {
12
- /**
13
- * This will let the researcher know that their template isn't found.
14
- *
15
- * @param template - Supplied name of consent template.
16
- */
17
- constructor(template: string);
18
- }
@@ -1,95 +0,0 @@
1
- import { PluginInfo, TrialType } from "jspsych";
2
- /**
3
- * Translate survey text to desired locale.
4
- *
5
- * @param trial - Trial data including user supplied parameters.
6
- * @returns Survey json
7
- */
8
- export declare const exitSurvey: (trial: TrialType<PluginInfo>) => {
9
- pages: {
10
- elements: ({
11
- description: string;
12
- inputType: string;
13
- isRequired: boolean;
14
- maxValueExpression: string;
15
- name: "birthDate";
16
- title: string;
17
- type: string;
18
- enableIf?: undefined;
19
- valueFalse?: undefined;
20
- valueTrue?: undefined;
21
- choices?: undefined;
22
- defaultValue?: undefined;
23
- autoGrow?: undefined;
24
- rows?: undefined;
25
- } | {
26
- description: string;
27
- enableIf: string;
28
- isRequired: boolean;
29
- name: "databraryShare";
30
- title: string;
31
- type: string;
32
- valueFalse: string;
33
- valueTrue: string;
34
- inputType?: undefined;
35
- maxValueExpression?: undefined;
36
- choices?: undefined;
37
- defaultValue?: undefined;
38
- autoGrow?: undefined;
39
- rows?: undefined;
40
- } | {
41
- choices: {
42
- text: string;
43
- value: string;
44
- }[];
45
- description: string;
46
- enableIf: string;
47
- isRequired: boolean;
48
- name: "useOfMedia";
49
- title: string;
50
- type: string;
51
- inputType?: undefined;
52
- maxValueExpression?: undefined;
53
- valueFalse?: undefined;
54
- valueTrue?: undefined;
55
- defaultValue?: undefined;
56
- autoGrow?: undefined;
57
- rows?: undefined;
58
- } | {
59
- choices: {
60
- text: string;
61
- value: boolean;
62
- }[];
63
- defaultValue: never[];
64
- isRequired: boolean;
65
- name: "withdrawal";
66
- title: string;
67
- type: string;
68
- description?: undefined;
69
- inputType?: undefined;
70
- maxValueExpression?: undefined;
71
- enableIf?: undefined;
72
- valueFalse?: undefined;
73
- valueTrue?: undefined;
74
- autoGrow?: undefined;
75
- rows?: undefined;
76
- } | {
77
- autoGrow: boolean;
78
- name: "feedback";
79
- rows: number;
80
- title: string;
81
- type: string;
82
- description?: undefined;
83
- inputType?: undefined;
84
- isRequired?: undefined;
85
- maxValueExpression?: undefined;
86
- enableIf?: undefined;
87
- valueFalse?: undefined;
88
- valueTrue?: undefined;
89
- choices?: undefined;
90
- defaultValue?: undefined;
91
- })[];
92
- name: string;
93
- }[];
94
- showQuestionNumbers: string;
95
- };
@@ -1,8 +0,0 @@
1
- import { PluginInfo, TrialType } from "jspsych";
2
- /**
3
- * Get translated template for uploading video message.
4
- *
5
- * @param trial - JsPsych trial object containing trial params
6
- * @returns Uploading video message HTML
7
- */
8
- export declare const uploadingVideo: (trial: TrialType<PluginInfo>) => string;
package/dist/utils.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import { PluginInfo, TrialType } from "jspsych";
2
- /**
3
- * Pulled from EFP. Function to convert researcher's text to HTML.
4
- *
5
- * @param text - Text
6
- * @returns Formatted string
7
- */
8
- export declare const expFormat: (text?: string | string[]) => string;
9
- /**
10
- * Initialize i18next with parameters from trial.
11
- *
12
- * @param trial - Trial data including user supplied parameters.
13
- */
14
- export declare const setLocale: (trial: TrialType<PluginInfo>) => void;
@@ -1,33 +0,0 @@
1
- import { PluginInfo, TrialType } from "jspsych";
2
- type VideoConfigTemplateParams = {
3
- webcam_container_id: string;
4
- reload_button_id_cam: string;
5
- camera_selection_id: string;
6
- mic_selection_id: string;
7
- step1_id: string;
8
- step2_id: string;
9
- step3_id: string;
10
- step_complete_class: string;
11
- reload_button_id_text: string;
12
- next_button_id: string;
13
- waiting_for_access_msg_id: string;
14
- checking_mic_msg_id: string;
15
- access_problem_msg_id: string;
16
- setup_problem_msg_id: string;
17
- chromeInitialPrompt: string;
18
- chromeAlwaysAllow: string;
19
- chromePermissions: string;
20
- firefoxInitialPrompt: string;
21
- firefoxChooseDevice: string;
22
- firefoxDevicesBlocked: string;
23
- checkmarkIcon: string;
24
- };
25
- /**
26
- * Get translated template for video config.
27
- *
28
- * @param trial - JsPsych trial object containing trial params
29
- * @param html_params - Additional context variables for the template.
30
- * @returns Video config HTML
31
- */
32
- export declare const videoConfig: (trial: TrialType<PluginInfo>, html_params: VideoConfigTemplateParams) => string;
33
- export {};