基于Modern工具包的本地化方式(下)

Posted 上将军

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基于Modern工具包的本地化方式(下)相关的知识,希望对你有一定的参考价值。

上文完虽已完成了组件的本地化,但Ext JS中还有验证类和插件类这些类需要实现本地化。通过研究发现这些类都有一个父类,这就好办了,和组件类一样,在父类中添加监听就可以实现全部子类的本地化了。

下面是插件类的重写代码:

Ext.define('CommonOverrides.shared.plugin.Abstract',
    override: 'Ext.plugin.Abstract',

    constructor: function(config) 
        const me = this;
        if (config) 
            me.cmp = config.cmp;
            me.pluginConfig = config;
            me.initConfig(config);
        
        if(LocalizedService && LocalizedService.isReady)
            me.onLocalized();
        else
            Ext.on('localizedready', me.onLocalized, me);
        
    ,

    onLocalized()
        const me = this,
            type = me.type;
        if(type === 'gridrowdragdrop')
            me.dragText =  LocalizedService.get(me.dragText);
            return
        ;
        if(type === 'listpaging')
            LocalizedService.localized(me , 'loadMoreText');
            LocalizedService.localized(me , 'noMoreRecordsText');
        
    ,

);

插件类只有两个类需要实现本地化,但怎么找这两个类费了一点功夫,最好找到了type这个属性可以标识这个类,这就解决问题了。在gridrowdragdrop这个类中还有点小麻烦,属性dragText 性居然没有set`方法,因而这里会有个小bug。

下面是验证类的重写代码:

Ext.define('CommonOverrides.shared.data.validator.Validator',
    override: 'Ext.data.validator.Validator',

  
    constructor: function(config) 
        const me = this;
        if (typeof config === 'function') 
            me.fnOnly = true;
            me.validate = config;
        
        else 
            me.initConfig(config);
        
        if(LocalizedService && LocalizedService.isReady)
            me.onLocalized();
        else
            Ext.on('localizedready', me.onLocalized, me);
        
    ,

    onLocalized()
        const me = this,
            type = me.type,
             resourceName = 'ExtResource';
        if(type === 'bound' || type === 'length' || type === 'range')
            if(type === 'bound') LocalizedService.localized(me ,'emptyMessage',resourceName);
            if(type === 'range') LocalizedService.localized(me ,'nanMessage',resourceName);
            LocalizedService.localized(me ,'minOnlyMessage', resourceName);
            LocalizedService.localized(me ,'maxOnlyMessage', resourceName);
            LocalizedService.localized(me ,'bothMessage', resourceName);
            return;
        
        LocalizedService.localized(me ,'message', resourceName);
    ,


)

验证类就比较简单了,大部分类都是通过message属性来返回错误信息的,只有三个类比较特殊。

至此,新的本地化方式就已经完成了。下面两个json文件是目前Ext JS包中全部的本地化信息:
en.json


  "culture": "en",
  "texts": 
    "Welcome to login": "Welcome to login.",
    "Username/Email/Phone": "Username/Email/Phone",
    "Password": "Password",
    "Remember Me": "Remember Me",
    "Forgot password": "<a href='#ForgotPassword' class='link-forgot-password'>Forgot password</a>",
    "Login": "Login",
    "DefaultMessageTitle": "Information",
    "Sunday": "Sunday",
    "Monday": "Monday",
    "Tuesday": "Tuesday",
    "Wednesday": "Wednesday",
    "Thursday": "Thursday",
    "Friday": "Friday",
    "Saturday": "Saturday",
    "January": "January",
    "February": "February",
    "March": "March",
    "April": "April",
    "May": "May",
    "June": "June",
    "July": "July",
    "August": "August",
    "September": "September",
    "October": "October",
    "November": "November",
    "December": "December",
    "AM": "AM",
    "PM": "PM",
    "Next Month (Control+Right)": "Next Month (Control+Right)",
    "Previous Month (Control+Left)": "Previous Month (Control+Left)",
    "Sort Ascending": "Sort Ascending",
    "Sort Descending": "Sort Descending",
    "Filter": "Filter",
    "Is not a valid email address": "Is not a valid email address",
    "Must be present": "Must be present,",
    "Value must be greater than 0": "Value must be greater than 0",
    "Value must be less than 0": "Value must be less than 0",
    "Value must be between 0 and 1": "Value must be between 0 and 1",
    "Is not a valid CIDR block": "Is not a valid CIDR block",
    "Is not a valid currency amount": "Is not a valid currency amount",
    "Is not a valid date": "Is not a valid date",
    "Is not a valid date and time": "Is not a valid date and time",
    "Is a value that has been excluded": "Is a value that has been excluded",
    "Is in the wrong format": "Is in the wrong format",
    "Is not in the list of acceptable values": "Is not in the list of acceptable values",
    "Is not a valid IP address": "Is not a valid IP address",
    "Length must be at least 0": "Length must be at least 0",
    "Length must be no more than 0": "Length must be no more than 0",
    "Length must be between 0 and 1": "Length must be between 0 and 1",
    "Is not a valid number": "Is not a valid number",
    "Is not a valid phone number": "Is not a valid phone number",
    "Must be numeric": "Must be numeric",
    "Must be at least 0": "Must be at least 0",
    "Must be no more than than 0": "Must be no more than than 0",
    "Must be between 0 and 1": "Must be between 0 and 1",
    "Is not a valid time": "Is not a valid time",
    "Is not a valid URL": "Is not a valid URL",
    "0 selected row1": "0 selected row1",
    "Load More...": "Load More...",
    "No More Records": "No More Records",
    "Loading...": "Loading...",
    "No data to display": "No data to display",
    "The date in this field must be equal to or after 0": "The date in this field must be equal to or after 0",
    "The date in this field must be equal to or before 0": "The date in this field must be equal to or before 0",
    "This field is required": "This field is required",
    "Browse...": "Browse...",
    "The minimum value for this field is 0": "The minimum value for this field is 0",
    "The maximum value for this field is 0": "The maximum value for this field is 0",
    "The maximum decimal places is 0": "The maximum decimal places is 0",
    "Value is not a valid number": "Value is not a valid number",
    "Locked (Left)": "Locked (Left)",
    "Unlocked": "Unlocked",
    "Locked (Right)": "Locked (Right)",
    "Locked": "Locked",
    "Columns": "Columns",
    "Group by this field": "Group by this field",
    "Show in groups": "Show in groups",
    "Collapse panel": "Collapse panel",
    "Expand panel": "'Expand panel",
    "OK": "OK",
    "Abort": "Abort",
    "Retry": "Retry",
    "Ignore": "Ignore",
    "Yes": "Yes",
    "No": "No",
    "Cancel": "Cancel",
    "Apply": "Apply",
    "Save": "Save",
    "Submit": "Submit",
    "Help": "Help",
    "Close": "Close",
    "Maximize to fullscreen": "Maximize to fullscreen",
    "Restore to original size": "Restore to original size",
    "Today": "Today"
  

  

zh-Hans.json


  "culture": "zh-Hans",
  "texts": 
    "Welcome to login": "欢迎登录",
    "Username/Email/Phone": "用户名/邮箱/手机",
    "Password": "密码",
    "Remember Me": "记住我",
    "Forgot password": "<a href='#ForgotPassword' class='link-forgot-password'>忘记密码</a>",
    "Login": "登录",
    "DefaultMessageTitle": "信息",
    "Sunday": "日",
    "Monday": "一",
    "Tuesday": "二",
    "Wednesday": "三",
    "Thursday": "四",
    "Friday": "五",
    "Saturday": "六",
    "January": "一月",
    "February": "二月",
    "March": "三月",
    "April": "四月",
    "May": "五月",
    "June": "六月",
    "July": "七月",
    "August": "八月",
    "September": "九月",
    "October": "十月",
    "November": "十一月",
    "December": "十二月",
    "AM": "上午",
    "PM": "下午",
    "Next Month (Control+Right)": "下月 (Ctrl+→)",
    "Previous Month (Control+Left)": "上月 (Ctrl+←)",
    "Sort Ascending": "正序",
    "Sort Descending": "倒序",
    "Filter": "过滤器",
    "Is not a valid email address": "不是有效的电子邮件地址",
    "Must be present": "值必须存在",
    "Value must be greater than 0": "值必须至少为0",
    "Value must be less than 0": "值必须不超过0",
    "Value must be between 0 and 1": "值必须在 0 和 1 之间",
    "Is not a valid CIDR block": "不是有效的CIDR块",
    "Is not a valid currency amount": "不是有效的货币金额",
    "Is not a valid date": "不是有效日期",
    "Is not a valid date and time": "不是有效的日期和时间",
    "Is a value that has been excluded": "是已排除的值",
    "Is in the wrong format": "格式错误",
    "Is not in the list of acceptable values": "值不在接受列表中",
    "Is not a valid IP address": "不是有效的IP地址",
    "Length must be at least 0": "长度必须至少为0",
    "Length must be no more than 0": "长度不得超过0",
    "Length must be between 0 and 1": "长度必须介于0和1之间",
    "Must be numeric": "必须是数字",
    "Is not a valid number": "不是有效的数字",
    "Is not a valid phone number": "不是有效的电话号码",
    "Must be at least 0": "必须至少为0",
    "Must be no more than than 0": "必须不超过0",
    "Must be between 0 and 1": "必须在 0 和 1 之间",
    "Is not a valid time": "不是有效时间",
    "Is not a valid URL": "不是有效的URL",
    "0 selected row1": "选择了 0 行",
    "Load More...": "加载更多...",
    "No More Records": "没有更多记录",
    "Loading...": "加载中...",
    "No data to display": "没有要显示的数据",
    "The date in this field must be equal to or after 0": "此字段中的日期必须在 0 之后",
    "The date in this field must be equal to or before 0": "此字段中的日期必须为 0",
    "This field is required": "此字段是必填字段",
    "Browse...": "浏览中...",
    "The minimum value for this field is 0": "该输入项的最小值是 0",
    "The maximum value for this field is 0": "该输入项的最大值是 0",
    "The maximum decimal places is 0": "最大十进制数 (0)",
    "Value is not a valid number": "0 不是有效数值",
    "Locked (Left)": "锁定(左)",
    "Unlocked": "解锁",
    "Locked (Right)": "锁定(右)",
    "Locked": "区域",
    "Columns": "列",
    "Group by this field": "以此分组",
    "Show in groups": "分组显示",
    "Collapse panel": "折叠面板",
    "Expand panel": "'展开面板",
    "OK": "确定",
    "Abort": "退出",
    "Retry": "重试",
    "Ignore": "忽略",
    "Yes": "是",
    "No": "否",
    "Cancel": "取消",
    "Apply": "应用",
    "Save": "保存",
    "Submit": "提交",
    "Help": "帮助",
    "Close": "关闭",
    "Maximize to fullscreen": "最大化到全屏",
    "Restore to original size": "恢复到原始大小",
    "Today": "今天" 
  

以上两个文件可以通过本地加载的方式加载,也可以通过服务器加载,这个看项目需要。

以上是关于基于Modern工具包的本地化方式(下)的主要内容,如果未能解决你的问题,请参考以下文章

基于Modern工具包的本地化方式(上)

《基于Modern工具包的本地化方式》的重构

内置的HTTP服务器Modern PHP

基于 Woocommerce 中的运输方式的不同电子邮件标题

解决Modern工具包中Ext.field.Date的提交值问题

谁有人工智能:一种现代化方法(ARTIFICIAL INTELLIGENCE A MODERN APPROACH)电子版书,要中文的。