Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multilingual alert messages in JavaScript

I have a php Web Application Multilingual, I have a php variable which can tell the current language of the Web Application,

I need to validate user inputs in client side, and error messages are shown with JavaScript alerts

for example if the php language variable is "french", I need the alert as "bonjour" if the php language variable is "english", I need the alert as "hello"

any ideas


1 Answers

Use your own namespace

en.js

MyApp.lang = {
    greeting: "Hello",
    warning: "Attention"
};

de.js

MyApp.lang = {
    greeting: "Hallo",
    warning: "Achtung"
};

Use it like alert(MyApp.lang.greeting) then depending on your php variable include the right .js file in the header

like image 89
jitter Avatar answered May 30 '26 11:05

jitter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!