JavaScript中的多语言警报消息 [英] Multilingual alert messages in JavaScript

查看:109
本文介绍了JavaScript中的多语言警报消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多语言的php Web应用程序, 我有一个php变量,可以告诉Web应用程序的当前语言,

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

我需要在客户端验证用户输入,并且错误消息与JavaScript警报一起显示

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

例如,如果php语言变量为法语",则我需要将警报设为"bonjour" 如果php语言变量是"english",则我需要将警报设置为"hello"

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"

任何想法

推荐答案

为您支持的每种语言制作某种字典/数组,并根据其中的一种语言,添加相关文件或将相关部分吐出字典.

Make some sort of dictionary/array for each language you support and depending on which one, include the relevant file or spit out the relevant part in the dictionary.

<?php $lang = 'fr'; ?>
<script>
messagesDictionary = {
    en: {
    message:'Hi'
    },

    fr: {
    message:'Bonjour'
    }

}

alert( messagesDictionary['<?php echo $lang;?>']['message'] );
</script>

这篇关于JavaScript中的多语言警报消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆