How to set Seo title for main pages according to language with JS-file

Hello
I need to make my seo title and seo description according to language chose on site

Created code plugin with chat gpt for seo title depending on Language.

Set the SEO title- Am i doing it right

What should i change to make it work

Hard for me to test but I would do something like this in “Files”:

// Get the active language and title translations (replace these with actual data retrieval methods)
let activeLanguage = "${language->get('active')}";  // This gets the active language dynamically
let englishTitle = "English title translation";
let polishTitle = "polish title translation";

// Initialize the title variable
let title;

// Check if the active language is Polish ('PL')
if (activeLanguage === "PL") {
    // If Polish, use the Polish title
    title = polishTitle;
} else {
    // If not Polish, use the English title (default)
    title = englishTitle;
}

// Return the title (you can also manipulate the DOM or other elements with this title if needed)
return title;

Then call it as you did and append the function file…

as said: it’s untested but I had success using this method instead of using functions in “Files” when manipulating data

@MixxMaster thanks for your help

-What type of “js-file” should i chose ? Plugin? Or any other ?

-How it should be chose as a variable from site setting? As I set it in the image or should I change something?