# Right-click Translate Language

{% hint style="info" %}
🍎 Before you begin this tutorial, make sure you've completed the [Developer Quick Start Guide](https://docs.pixiebrix.com/quick-start/mod-developer).
{% endhint %}

In this tutorial, you'll build a mod that translates the language of text you highlight.

You’ll build the mod on this page: [la Repubblica](https://www.repubblica.it/dossier/sport/olimpiadi-tokyo-2020/2021/08/03/news/warholm_oro_400_ostacoli_record_del_mondo-312767996/) (an Italian newspaper)

### 1. Open the Page Editor <a href="#block-9d73dd78b62640aaa8e8e69dc414ef73" id="block-9d73dd78b62640aaa8e8e69dc414ef73"></a>

Start by navigating your browser to [la Repubblica](https://www.repubblica.it/dossier/sport/olimpiadi-tokyo-2020/2021/08/03/news/warholm_oro_400_ostacoli_record_del_mondo-312767996/). Then, [open the PixieBrix Page Editor](https://docs.pixiebrix.com/platform-overview/page-editor/open-the-page-editor).

#### Grant PixieBrix Access to the Page <a href="#block-71a4f184be414749af2c20efa97f54cd" id="block-71a4f184be414749af2c20efa97f54cd"></a>

PixieBrix does not have access to any of the web pages you view by default.

Therefore, the first time you open the Page Editor on any new webpage, you need to grant PixieBrix access to the page.

You can grant access by clicking **Enable PixieBrix on \[Webpage]** in the Page Editor:

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/e124902e-e20d-4a82-b88b-f2408d3ad9f5/Screen_Shot_2022-07-23_at_11.25.30_AM/w=640,quality=80" alt="" width="375"><figcaption></figcaption></figure>

### 2. Add a Context Menu <a href="#block-436bd1fde4b6433989c1ae9c073e67a5" id="block-436bd1fde4b6433989c1ae9c073e67a5"></a>

Click **New Mod** in the top left of the Page Editor and choose **Context Menu**<br>

<figure><img src="https://2274778196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq123bF1HPQPV35s5vHa1%2Fuploads%2FwExjluCOkiy2QLoP6bYN%2FCleanShot%202024-10-16%20at%2009.38.47.png?alt=media&#x26;token=c9e4e8d4-9125-4f4c-9ead-2d5d981dde89" alt=""><figcaption></figcaption></figure>

#### Give your action a Name <a href="#block-1d885b3179564181923085622c87ccc2" id="block-1d885b3179564181923085622c87ccc2"></a>

In the Brick Configuration Panel, change the Name to “Quick Start Guide”.

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/ac64a8ed-d76e-4af7-823f-591dcf9f4f07/Screen_Shot_2022-07-23_at_11.35.39_AM/w=828,quality=80" alt="" width="375"><figcaption></figcaption></figure>

Then, in the Mods Panel, click save icon:

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/036f6f99-ed3a-41fa-a3dc-e2e640748518/Untitled/w=750,quality=80" alt="" width="375"><figcaption></figcaption></figure>

Clicking the **Save** icon will bring up a modal for [packaging-a-mod](https://docs.pixiebrix.com/developing-mods/sharing-mods/packaging-a-mod "mention"). Set an alias (like a username) if you haven't already and give the mod a unique ID and description, then click **Create**.

#### Configure the Menu Item Title <a href="#block-8d6b5a198c9b4cdfb99f6fb76c5953e5" id="block-8d6b5a198c9b4cdfb99f6fb76c5953e5"></a>

In the brick configuration Title input, replace `Context Menu Item` with `Translate: %s`

{% hint style="info" %}
💡The "%s" placeholder configure the caption so that it dynamically changes based on the text you highlight. Note this convention is different than the mustache braces `{{` used in other places in PixieBrix. It's because for context menu items, Chrome is filling in the selected text, not PixieBrix.
{% endhint %}

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/850ccc5d-05dc-4fb2-beea-95f3ffe54bc5/Screen_Shot_2022-07-23_at_11.50.01_AM/w=828,quality=80" alt=""><figcaption></figcaption></figure>

To test your context menu configuration:

* Highlight `oro e record del mondo nei 400 ostacoli` on the webpage
* Right-click to expand the context menu. It should look like this; do not click it yet - as nothing will happen until we add more bricks.

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/ae363042-6069-4d72-a129-a737df56400b/Screen_Shot_2021-08-04_at_1.44.29_PM/w=1200,quality=80" alt=""><figcaption></figcaption></figure>

#### Configure where the Context Menu Appears <a href="#block-7122eab2bda54fd2bdd5f51749a54db4" id="block-7122eab2bda54fd2bdd5f51749a54db4"></a>

* In the Sites field, click **All URLs**. This tells PixieBrix to show the context menu item on any webpage you visit.
* You can remove the match pattern configuration that defaulted to `https://www.repubblica.it/*` given it’s included in **All URLs**. Do this by clicking the **ABC** entry mode dropdown and choosing **Remove**

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/23e321c4-f636-4b7d-a699-a64bb075e5d5/Screen_Shot_2022-07-23_at_11.57.16_AM/w=3840,quality=80" alt=""><figcaption></figcaption></figure>

#### Automatic Permissions <a href="#block-a76cd67a2a91461eae4cc0dea649ec81" id="block-a76cd67a2a91461eae4cc0dea649ec81"></a>

{% hint style="info" %}
💡When creating a Context Menu, configuring Automatic Permissions grants PixieBrix access to pages without you first clicking the context menu. For context menus, this helps ensure PixieBrix knows which text you have selected
{% endhint %}

* Scroll down to the **Advanced** configuration. In the Automatic Permissions section, click **All URLs**
* Once again, remove the match pattern configuration that defaulted to `https://www.repubblica.it/*` as you did above

The Page Editor Configuration should now look like this:

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/ab3cb3fb-2500-4f21-bc1d-ea20a3ebd90a/Screen_Shot_2022-07-23_at_12.01.50_PM/w=3840,quality=80" alt=""><figcaption></figcaption></figure>

#### 👏👏👏 Nice job! You’ve configured your first context menu! Let’s keep going… <a href="#block-ae4f14be101b46a29224ab93b14b5889" id="block-ae4f14be101b46a29224ab93b14b5889"></a>

### 3. Add the Google Translate API Integration <a href="#block-db2c41b812e94db580ce0477de4c5f02" id="block-db2c41b812e94db580ce0477de4c5f02"></a>

#### Add the Integration <a href="#block-3fd217b7329840d39afd309648f2acee" id="block-3fd217b7329840d39afd309648f2acee"></a>

We'll first need to add the **Translate** brick. Click the "Add Button"

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/4e0e485e-74ae-44a1-bc66-6996f2fb0e56/Untitled/w=3840,quality=80" alt=""><figcaption></figcaption></figure>

Search "translate" and **+Add** the Translate brick

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/ea21a66f-d348-42ee-87f6-6a162f5654d3/Screen_Shot_2022-07-23_at_12.10.31_PM/w=3840,quality=80" alt=""><figcaption></figcaption></figure>

#### Choose the Integration Configuration <a href="#block-be9e4f104db348b393810f8bd0cfc4d0" id="block-be9e4f104db348b393810f8bd0cfc4d0"></a>

In the Integration dropdown, choose "**Google Translate (RapidAPI) - ✨ Built-In**"

{% hint style="info" %}
💡Integrations can have multiple configurations (e.g., because you have multiple accounts with the service). The integration dropdown lets you choose the appropriate configuration for a given a given actions or enhancement.
{% endhint %}

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/cb33cc4d-5c3d-4f25-817e-a712a1704ffb/Screen_Shot_2022-07-23_at_12.13.23_PM/w=3840,quality=80" alt=""><figcaption></figcaption></figure>

Learn more about [Configuring Integrations](https://docs.pixiebrix.com/integrations/configuring-integrations).

#### Configure the Brick Inputs <a href="#block-9dba84ed4d9147eabacb35f59b7579e3" id="block-9dba84ed4d9147eabacb35f59b7579e3"></a>

You build mods by composing bricks, adding one brick after another to create the desired workflow.

Each brick passes information to the next brick. In other words, an “**Output**” from the proceeding brick can be referenced as as the “**Input**” to a subsequent brick.

#### The Data Panel <a href="#block-1aee82edb4a04d1aa15e4a69d72aa9ea" id="block-1aee82edb4a04d1aa15e4a69d72aa9ea"></a>

To understand this concept, it’s helpful to become familiar with the **Data Panel.** The **Data Panel** is on the right-hand side of the Page Editor.

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/2df1baa0-67b6-4b30-9cf4-218adeba703f/Untitled/w=3840,quality=80" alt=""><figcaption></figcaption></figure>

* By default, the **Data Panel** is blank. To populate it, you’ll need to run your context menu.
* You can run the context menu by highlighting any text on the webpage, such as "oro e record del mondo nei 400 ostacoli," right-click, and then click the PixieBrix context menu action.
* Now the **Data Panel’s** tabs are populated with information to help you configure the brick

#### Use the Context tab to view available brick inputs <a href="#block-857f754a959e4a9a9ac1e42aef8a5614" id="block-857f754a959e4a9a9ac1e42aef8a5614"></a>

* You can use the **Data Panel’s** **Context** tab to show the available inputs for the brick.
* Click the **Context** tab, and you should see two input keys:

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/f98d5b0e-a68b-42d7-8b57-1f4b3e2d9718/Screen_Shot_2022-07-23_at_1.03.59_PM/w=640,quality=80" alt="" width="375"><figcaption></figcaption></figure>

* Click the **@input** key to see all the available values.

#### Use selectionText to configure the query input <a href="#block-335123e40d134ab4840ce93b2546ccb7" id="block-335123e40d134ab4840ce93b2546ccb7"></a>

* For this tutorial, you’ll use **selectionText**, which contains the text you highlighted. Scroll down to find it:

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/d3a9edce-ddb1-47aa-bae3-206292a0cd80/Screen_Shot_2022-07-23_at_1.10.51_PM/w=828,quality=80" alt="" width="375"><figcaption></figcaption></figure>

* Click the page icon next to **selectionText** to copy its property path to your clipboard: `@input.selectionText`

{% hint style="info" %}
💡Notice the “**@**” in `@input.selectionText`. In PixieBrix, the “**@**” denotes a variable. Therefore, `@input.selectionText` is a variable whose value will change dynamically based on the text you highlight.
{% endhint %}

#### Configure the “target” language <a href="#block-d002b8afbee54b37a312c2e9e440d522" id="block-d002b8afbee54b37a312c2e9e440d522"></a>

* The "source" and "target" fields represent the source and target languages for the translation. If you leave the "source" field blank, the API will try to detect it.
* For this tutorial, I'll leave the "source" field blank, and change the target to "en" which is the two-letter abbreviation for English.
* Click **Save**.

{% hint style="info" %}
💡Here's Wikipedia's list of two letter language abbreviations: [List of ISO 639-1 codes](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)
{% endhint %}

#### Test the Google Translate API integration <a href="#block-66bb00def7b040e08d383b31d6cd0d51" id="block-66bb00def7b040e08d383b31d6cd0d51"></a>

* Highlight any text on the web page, such as "oro e record del mondo nei 400 ostacoli," right-click, and then click the PixieBrix context menu action.
* The **Data Panel** will refresh. Navigate to its **Output** tab, and you should see that your highlighted text has been translated to English<br>

  <figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/d425a61c-0b48-4bdc-b69d-52eade8f869c/Screen_Shot_2022-07-23_at_1.39.24_PM/w=750,quality=80" alt="" width="375"><figcaption></figcaption></figure>

### 4. Display the Translation in a Window Alert <a href="#block-1d99a6cb15f9421b9b42f092381a5466" id="block-1d99a6cb15f9421b9b42f092381a5466"></a>

#### Add the Window Alert brick <a href="#block-375e644374b2480bb181ff4f28084c9d" id="block-375e644374b2480bb181ff4f28084c9d"></a>

* Let’s display the translated text in a Window Alert.
* Click **Add Brick**, search "window alert" and **+Add** it

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/1e781283-1592-424c-b675-13623ee2622b/Screen_Shot_2022-07-23_at_1.45.38_PM/w=3840,quality=80" alt=""><figcaption></figcaption></figure>

#### Configure the Window Alert <a href="#block-fb967c9675a94ab5bfa9517a24264ffc" id="block-fb967c9675a94ab5bfa9517a24264ffc"></a>

* Once again, execute the mod to populate the **Data Panel**
* Go to the **Context** tab, and click the **@transformed** key to expand it<br>

  <figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/89c6623e-384c-4118-9ff9-b975bb66b824/Screen_Shot_2022-07-23_at_1.57.29_PM/w=640,quality=80" alt="" width="375"><figcaption></figcaption></figure>
* Click the page icon next to **translatedText** to copy its property path to your clipboard: `@transformed.translatedText` (Look familiar? We just saw this when viewing the brick output in the prior step)

Finally, **Save** your mod…

### 5. Test your mod <a href="#block-51e7769af3224d4c811e0ab0bc9901bb" id="block-51e7769af3224d4c811e0ab0bc9901bb"></a>

You’ve created a mod made up of three bricks:

1. **Context Menu**: used to select text from the page
2. **Translate**: translates the text from a source to a target language
3. **Window Alert**: displays the translation in a popup alert

Since you saved the mod, you can close the Page Editor and test it out!

* Highlight any text on the page, such as “Prestazione pazzesca del norvegese”
* Right-click, and select the PixieBrix context menu

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/9d7ad201-500a-4bbe-8253-b2d220cf27ff/Screen_Shot_2022-07-23_at_2.09.11_PM/w=1080,quality=80" alt=""><figcaption></figcaption></figure>

* PixieBrix should show a pop-up with the translated text

<figure><img src="https://images.spr.so/cdn-cgi/imagedelivery/j42No7y-dcokJuNgXeA0ig/e47af04b-7477-4bb5-8376-84ce29abb432/Screen_Shot_2022-07-23_at_2.10.57_PM/w=1080,quality=80" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
🙋Need some help with building? [Head over to the Slack Community](https://slack.pixiebrix.com/), and we’ll gladly help you!
{% endhint %}
