Skip to main content
Inspiring
January 29, 2025
Answered

Localize language

  • January 29, 2025
  • 1 reply
  • 372 views

I've reached a dead end
I would like to make the panel change the language based on the country of use,
unfortunately I stopped and I can't go on,
up to now I have managed to set 2 languages,
I would like to set another 2 or 3
this is my starting script.

 const host = require('uxp').host;
    const locale = host.uiLocale;
    if (locale == "en_US" ){
        english();
    }else{
        france();
    }

 

I tried this method but had no luck

 

    const host = require('uxp').host;
    const locale = host.uiLocale;
    if (locale == "en_US" ){
        english();
    }else{
        france();
 }else{
espana();
}

 

I hope there is a solution

Correct answer Ciccillotto

 

 

if (locale == "en_US") {
    english();
} else if (locale == "it_IT") {
    italy();
} else if (locale == "es_ES") {
    spanish();
} else {
    defaultLanguage();
}

}

@pfaffenbichler
thanks to your help I solved it this way
thanks 

1 reply

c.pfaffenbichler
Community Expert
Community Expert
January 29, 2025

I am not up to speed with USP Scripting but you seem to have one if-clause and two else-clauses.

So the numbers don’t seem to add up and you may need a second if-clause to verify »frenchness« before »defaulting« to Spanish. 

 

Edit: Alternatively you could try using a switch-clause. 

Inspiring
January 29, 2025

I tried this way but it doesn't work

    const host = require('uxp').host;
    const locale = host.uiLocale;
    if (locale == "en_US" ){
        english();
    }else{
        france();
 }
if (locale == "es_ES" ){
espana();
}
}

 

do you have an example of how to set a second if

CiccillottoAuthorCorrect answer
Inspiring
January 29, 2025

 

 

if (locale == "en_US") {
    english();
} else if (locale == "it_IT") {
    italy();
} else if (locale == "es_ES") {
    spanish();
} else {
    defaultLanguage();
}

}

@pfaffenbichler
thanks to your help I solved it this way
thanks