Basic Translation Tutorial

This tutorial shows you the basics of PixieBrix and will help you understand how to create a mod (what's a mod?), interact with an API, and display that response in the sidebar.

You'll learn how to :

  • Initiate or launch a mod

  • Reference input from a starter brick

  • Add bricks to a mod

  • Make an API call in PixieBrix

  • Reference output from a brick in other bricks

  • Use Text Templates to inject dynamic values into text

  • Create interactive displays with dynamic data (such as responses from APIs)

This tutorial should take about 10 minutes. If you have any questions, click the purple live chat button in the bottom left corner or reach out to support.

If you get stuck and cannot move forward, activate this mod to see the final solution. Follow these docs if you need help Activating Mods. Once you've activated it, you'll find it in the Page Editor on the first panel, the Mod Listing Panel.

Prefer to watch?

Watch the video for a walkthrough of this tutorial.

Prefer the text version? Skip the video and keep reading!

PreReqs

Before getting started, you'll need:

You're ready to start the tutorial if your screen looks something like this.

At the end of each step, you'll see a 🏁 that shows you how to know if you're ready to move to the next step. There will be screenshots indicating how you should have configured the brick for that step.

Step 1: Start your mod with a context menu brick

Every mod begins with a Starter Brick, which is one of 5 types of mods that determine how and where a mod runs. (Learn more about Types of Mods.)

For this mod, we'll use the Context Menu starter brick.

1.1 Add the context menu brick

To do this click the Add button in the top left of the Page Editor, then choose the Context Menu option. (What's a context menu?)

Once you click that, configuration options appear in the middle of your Page Editor, this is the Brick Configuration Panel.

1.2 Update the Name and Title

The Name field is the mod component in the first panel, the Mod Listings Panel.

The Title is the text that appears on the context menu. You may call it something like "Greek Translate" (or whatever language you'd like to translate to). You can also dynamically show the selected text by including %s in the Title.

If a title starts with an emoji, it will appear on the Visual Popover element when you select text.

1.3 Change Menu context to selection

In the Menu context dropdown, choose selection and remove all by clicking the x after the text.

This ensures the context menu action only appears when you have text selected.

1.4 Choose All URLs for Sites

Specify which sites you'd like to be able to run this mod on. By default, PixieBrix will set the current site, but if you want to run on any URL, click the All URLs option.

You can then remove the docs.pixiebrix.com url by clicking the ABC at the end of the field and choosing X.

🏁 Checkpoint

You're ready to move on to the next step if your brick looks like this:

You should also see an action in the context menu if you highlight text on the page and then right-click.

Clicking that action runs the Brick Pipeline, so let's add more bricks.

Step 2: Make an API Call

Now that we can trigger our mod, we must tell it to do something. In this case, we want to connect to an API to translate the selected text.

2.1 Click the + button below Context Menu to add a brick

In the Brick Actions Pipeline, you'll see a + icon just below the Context Menu brick. Click the + button to open the Add a Brick modal.

2.2 Add the HTTP Request brick

In the Add a Brick modal, search for HTTP and you should see the HTTP Request brick appear. Hover over it and click the blue Add button to add to your brick pipeline.

2.3 Set the endpoint and choose the built-in Rapid API integration.

We'll use Rapid API's Google Translation API to translate the text.

In the middle Brick Configuration Panel, set the endpoint URL to https://google-translate1.p.rapidapi.com/language/translate/v2

PixieBrix has a built-in Rapid API integration, so select the Integration Configuration field and search for translate or rapid and choose the Google Translate (RapidAPI) -- ✨ Built-in option.

2.4 Set the Header object

Some APIs will require a header object; Rapid API is no exception. To add a Header object, click the X at the end of the Headers field and choose the Object Properties option.

Click the blue Add Property button and set the Property Name to content-type and the Value to application/x-www-form-urlencoded

This is provided to let the server know how to parse the data we'll be sending and can help catch issues ahead of time if you're sending something in the wrong format. Follow your specific APIs documentation to see if you need to use this.

2.5 Set the Data object with the query and target language

You'll also typically pass data to an API when performing a request. Just like the Header object, you'll create a Data object by clicking the X at the end of the JSON Data field and choosing the Object Properties option.

This API requires two properties:

  • q (the text you want to translate)

  • target (the language you want to translate the text to)

To add these, click Add Property and set the Property name of q . To reference the text that we selected when triggering the mod, in the value field, type @input.selectionText.

PixieBrix allows you to reference data from inputs, such as selected text, URL, title, description, and more. You can view these by clicking the Preview panel in the Data Panel on the Starter Brick, the first brick in the mod's pipeline. You can view these by typing @input and the variable popover will appear with available options.

Lastly, add another property by clicking Add Property and set the name to target and the value to EL (or the two-letter code of another language you prefer).

🏁 Checkpoint

You're ready to move on to the next step if your brick looks like this:

Step 3: View the output of your response

You're ready to run your mod and check the API returns the expected response.

3.1 Select text on the page above the Page Editor

Highlight text on the webpage, and right-click to open the context menu. Click the PixieBrix icon with the Translate action to run your mod.

3.2 View the Output in the Data Panel

You might have noticed some checkmarks appear next to brick in your Brick Actions Panel (second panel in the Page Editor). This lets you know your steps succeeded.

Confirm you have selected the HTTP Request brick (it will have a blue background in the Brick Actions Panel), then confirm you have selected the Output tab on the Data Panel (last panel on the right).

This is where you can view the response from the API. Click the > before @response to open the object and view the response.

This response can be used in any bricks that come afterward, giving you a way to provide dynamic values to other bricks, such as displaying the response. We'll do this in the next step.

🏁 Checkpoint

You're ready to move on if you can successfully see the translatedText response in the Data Panel of your sidebar, like the screenshot above.

If you have any errors, confirm you've configured your brick according to the screenshot in Step 2.

Step 4: Display the Response in a Sidebar

Lastly, we will add a brick to display our response in a sidebar.

4.1 Add the Display Temporary Information brick

Click the + button below the HTTP Response brick in the Brick Actions Panel and search for the Display Temporary Information brick. Hover over it, then click the blue Add button.

You'll see that two bricks were added to your Brick Actions Panel:

  • Display Temporary Information

  • Render Document

4.2 Give the Display Temporary Information Brick a title

In the brick Configuration Panel for the Display Temporary Information Brick, rename the Title to Translate

You can also choose to move the location from Sidebar to a Modal or Popover. We'll leave this as a Sidebar.

4.3 Click the Render Document brick in the Brick Actions Panel

Now, click the Render Document brick to style the Sidebar. Once you click the Render Document brick in the Brick Actions Panel, you'll see a preview appear on the far right panel (the Data Panel)

Click any element in the Preview panel to edit.

4.4 Rename Example Document to Translate

Click the Example document text on the Preview Panel, and the middle Brick Configuration Panel will display options for modifying that element.

In this case, the element is a Header type. So, the configuration options include the text itself, which you can rename in the Title field.

Replace the text with "Translate" instead of "Example document".

You can also change the size of the header. There are other optional settings for styling and setting criteria to hide the element dynamically. You can leave these as is for this tutorial.

4.5 Replace the Example text element with the response

Now click the Example text element in the preview panel.

New configuration options appear for the Text element. Replace the Text value with the following:

Your translated text: {{ @response.data.translations[0].translatedText }}

Notice we can reference the output from the HTTP Request brick by providing the variable path and wrapping it in {{ }} to inject the value in hardcoded strings.

You can access the property by using the variable popover, which displays available variables once you start typing @, or you can copy the path by viewing the output from the brick and clicking the copy icon next to the item you want to reference.

🏁 Checkpoint

You're ready to move to the next step when your sidebar preview panel looks like this:

Step 5: Save your mod and try it out

Your mod is built, so it's time to save and test it.

5.1 Click Save in the Mod Listing Panel

On the first panel on the left, the Mod Listing Panel, click the Save icon on your translate mod.

You can now close your Page Editor and test out your mod!

5.2 Select text, right-click, and choose the Translate action

Select any text on the page (like this paragraph!), right-click, and then choose the Translate action.

You should see a sidebar with your translated text a moment later.

🎉 Congrats!! You just built a mod.

If it's not working, you can activate the template to see how it's meant to be structured, and compare your build to the template mod. You can also reach out to our support team or click the live chat button in the bottom left corner of this page.

Last updated