From c16d77029be97cb2a9bedd79fb5b8d23e615d335 Mon Sep 17 00:00:00 2001 From: Mykhailo Rohalskyy Date: Fri, 24 Jan 2025 17:00:49 +0200 Subject: [PATCH 1/2] docs(developer): In-Context --- .../developer/capabilities/in-context.mdx | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/content/docs/developer/capabilities/in-context.mdx b/src/content/docs/developer/capabilities/in-context.mdx index aba981e5..9bf26589 100644 --- a/src/content/docs/developer/capabilities/in-context.mdx +++ b/src/content/docs/developer/capabilities/in-context.mdx @@ -174,6 +174,55 @@ If defined, users can close the In-Context overlay if they don't want to transla Close Login Window +### Start Type + +```js +_jipt.push(['start_type', 'manual']); +``` + +Defines how In-Context is initialized. +Acceptable values: +- **`default`** – In-Context starts automatically after the script loads. +- **`manual`** – In-Context starts only when you call [`window.jipt.start()`](#start-and-stop-methods). + +Use `manual` if you need greater control. For example, in single-page apps where you want to switch In-Context on or off based on user actions. + +## Optional Functions + +You can call various functions on the global `window.jipt` object to manage or customize In-Context in real time. + +### Start and Stop Methods + +```js +window.jipt.start(); +``` +Manually activates In-Context for the current page. +Use this if you set `start_type` to `manual` or if you want to re-activate In-Context after stopping it. + +```js +window.jipt.stop(); +``` +Stops the In-Context overlay. All interactive translation elements are removed until you call `start()` again. + +**Usage Example: Single-Page Application** + +In a single-page application, you might switch In-Context on or off when a user changes the language: + +```js +const handleLanguageChange = (event) => { + const language = event.target.value; + setSelectedLanguage(language); + + if (language === inContextLanguage) { + window.jipt.start(); + } else { + window.jipt.stop(); + } +}; +``` + +In the above snippet, whenever the user selects the In-Context pseudo-language, In-Context is triggered. When they select any other language, In-Context is stopped. + ## Adding Screenshots via In-Context This feature allows you to take a screenshot of the opened website page, upload it to the Crowdin project and automatically tag all strings used on the page. From 441b0053241be52822e8814ec2934e432ab50dc7 Mon Sep 17 00:00:00 2001 From: Mykhailo Rohalskyy Date: Fri, 24 Jan 2025 18:39:01 +0200 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Andrii Bodnar --- src/content/docs/developer/capabilities/in-context.mdx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/content/docs/developer/capabilities/in-context.mdx b/src/content/docs/developer/capabilities/in-context.mdx index 9bf26589..01f56b8d 100644 --- a/src/content/docs/developer/capabilities/in-context.mdx +++ b/src/content/docs/developer/capabilities/in-context.mdx @@ -180,8 +180,8 @@ If defined, users can close the In-Context overlay if they don't want to transla _jipt.push(['start_type', 'manual']); ``` -Defines how In-Context is initialized. -Acceptable values: +Defines how In-Context is initialized. Acceptable values: + - **`default`** – In-Context starts automatically after the script loads. - **`manual`** – In-Context starts only when you call [`window.jipt.start()`](#start-and-stop-methods). @@ -196,12 +196,13 @@ You can call various functions on the global `window.jipt` object to manage or c ```js window.jipt.start(); ``` -Manually activates In-Context for the current page. -Use this if you set `start_type` to `manual` or if you want to re-activate In-Context after stopping it. + +Manually activates In-Context for the current page. Use this if you set `start_type` to `manual` or if you want to re-activate In-Context after stopping it. ```js window.jipt.stop(); ``` + Stops the In-Context overlay. All interactive translation elements are removed until you call `start()` again. **Usage Example: Single-Page Application**