Framer

Integrate LingoJS into Framer using a custom script to handle translations and language selection.

LingoJs react integration

1. Install the LingoJS Script

To begin, you need to add the LingoJS script to your Framer site. You can do this by adding the <script> tag via Framer’s Embed component..

Steps:

  1. Open your Framer project.

  2. In the left panel, click the Insert (+) icon.

  3. Search for and add an Embed component to your canvas.

  4. In the right panel, open the </> HTML tab.

  5. Paste the following code inside:

<script src="https://cdn.jsdelivr.net/gh/Flowcodelab/LingoJs/lingo-snippet.obf.js"></script>
<script>
  window.onload = function() {
    if (window.Lingojs && window.Lingojs.initialize) {
      window.Lingojs.initialize({
        projectKey: 'Your project key',
        targetLanguage: 'de', // Define your target language or function to get the current language
        baseLanguage: 'en',
        rememberLanguage: true, // Decide whether to remember the user's language setting
        showWidget: true // Decide whether to display the language change widget
      });
    }
  }
</script>

2. Initialize LingoJS on Page Load

In the above code, we have initialized LingoJS when the page is loaded. The projectKey, targetLanguage, and other options are configured when the script is loaded on the page.

3. Change Language Dynamically

To allow users to dynamically change the language without the lingoJs widget, you can add a JavaScript function that interacts with the LingoJS API. Here’s how to add a button or any other mechanism to trigger the language change.

Example: Add a Language Switcher

You can add this functionality inside your theme's template files or through a custom widget.

  • Add another Embed component.

  • In the HTML section, paste this code:

<button onclick="changeLanguage('fr')">Change Language to French</button>

<script>
  function changeLanguage(lang) {
    if (window.Lingojs) {
      window.Lingojs.changeLanguage(lang);
    }
  }
</script>

This creates a button that, when clicked, changes the language to French.

4. Handling Dynamic Content

LingoJS automatically detects text content on your page and sends it to the dashboard for translation. However, if you have content that should not be translated, you can use the translate attribute to control translation behavior.

Disabling Translation for an Element:

To prevent certain elements from being translated, you can add the translate="no" attribute to them:

<p translate="no">This text will not be translated.</p>

Handling Dynamic Variables:

For dynamic variables (content that shouldn't be translated within a sentence), use the <var></var> tag. This allows the dynamic content to be shown in the dashboard but keeps it empty for translation purposes.

<p>This is a sentence with a dynamic value: <var>dynamicValue</var></p>

5. Additional Setup Options

  • Remember Language: If you want the language choice to persist (i.e., for users to see the same language on returning visits), you can set rememberLanguage: true in the initialization.

  • Translation Widget: If you want to display a translation widget (for users to change the language on their own), you can enable it by setting showWidget: true.

6. Important Notes:

  • Do not modify HTML tags in the LingoJS dashboard. The translations are automatically generated to ensure they retain the proper attributes (e.g., classes, styles) from the DOM.

  • Ensure that your projectKey is correctly configured for your LingoJS project.

⚠️ Attention: Modifying HTML Tags in the Dashboard

Why is this Important?

LingoJS automatically generates these HTML elements in the translation process, which are then reused in your website’s DOM once the translations are applied. Modifying these tags in the dashboard would disrupt this process, causing translations to break or misalign with the intended design.


Conclusion

By following these steps, you can successfully integrate LingoJS into your Framer site. LingoJS will handle text translations and allow dynamic language switching through the API, providing a seamless multilingual experience for your users.

Last updated