Show more/show less code multilingual

Hello! After 3 days of trying and no previous code-writing experience, I managed to install ‘Read more/ Read less’ buttons. Then I transferred all this into German ‘Mehr lesen’, where I could simply translate what it says on the button. However, I have no access in the editor to translate the ‘Read less’ Button, and the code just has it in English anyway, even in the German version… Any suggestions how I can access the ‘Read Less’ button for translation?

Many thanks! Jaya

let fullText; // variable to hold the full text
let shortText; // variable to hold the short version of the text

$w.onReady( function () {
// how many characters to include in the shortened version
const shortTextLength = 695; // you can change this number
// read the full text and store it in the fullText variable
fullText = $w(“#text17”).text;
// grab the number of characters defined in shortTextLength and store them in the shortText variable
shortText = fullText.substr(0, shortTextLength) + “…”;
// set the contents of the text element to be the short text
$w(“#text17”).text = shortText;
});

export function button15_click(event) {
// display the full text
// check the contents of the text element
if ($w(“#text17”).text === shortText) {
// if currently displaying short text, display the full text
$w(“#text17”).text = fullText;
$w(“#button15”).label = “Read less”;
} else {
// if currently displaying full text, display the short text
$w(“#text17”).text = shortText;
$w(“#button15”).label = “Read more”;
}

You would need another conditional statement (if else) inside your button_click that changes the label based on the current language using Multilingual - Velo API Reference - Wix.com .

Many thanks David - skeptisch.net, it looks like that is what I need. Could I ask you to explain a little more in detail on what to enter where? I am a newbie … Thank You!

Sure. It would look something like this:

import wixWindow from 'wix-window';

export function button15_click(event) {
 if ($w("#text17").text === shortText) {
  $w("#text17").text = fullText;
  if (wixWindow.multilingual.currentLanguage === 'en') {
   $w("#button15").label = "Read less";
  } else if (wixWindow.multilingual.currentLanguage === 'de') {
   $w("#button15").label = "Weniger lesen";
  }
 } else {
  $w("#text17").text = shortText;
  if (wixWindow.multilingual.currentLanguage === 'en') {
   $w("#button15").label = "Read more";
  } else if (wixWindow.multilingual.currentLanguage === 'de') {
   $w("#button15").label = "Mehr lesen";
  }
 } 

Thanks very much for your help David, but my luck has run out … not able to integrate your suggestion (is this below part of what I need to put in) - and now I am unable to what I had before … mmmmh need to try again another day …

import wixWindow from 'wix-window'; 

Yes, you need the whole snippet, just delete your previous button15_click function.

Dear David, many thanks for your support. You are a star! I messed around with it a few times and got error code, but now it actually works! Hooray!!! Thanks very much!