lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | (function ($) {
|
| 2 | $.fn.translate = function () {
|
| 3 | var $this = $(this);
|
| 4 | $this.each(function(){
|
| 5 | var item = $(this);
|
| 6 | var trans = item.attr("data-trans");
|
| 7 | if(!!trans){
|
| 8 | translateElement(this, trans);
|
| 9 | }
|
| 10 |
|
| 11 | var placeholder = item.attr("data-placeholder");
|
| 12 | if(!!placeholder){
|
| 13 | placeholderElement(this, placeholder);
|
| 14 | }
|
| 15 | });
|
| 16 |
|
| 17 | $this.find("*[data-trans], *[data-placeholder]").each(function () {
|
| 18 | var self = $(this);
|
| 19 | if(self.attr("id") == 'chosen-search-field-input'){
|
| 20 | var val = $("#chosenUserSelect").val();
|
| 21 | if(val && val.length > 0){
|
| 22 | return;
|
| 23 | }
|
| 24 | }
|
| 25 | var trans = self.attr("data-trans");
|
| 26 | var transData = self.attr("data-trans-data");
|
| 27 | if (trans != "") {
|
| 28 | translateElement(this, trans, transData);
|
| 29 | }
|
| 30 |
|
| 31 | var placeholder = self.attr("data-placeholder");
|
| 32 | if(!!placeholder){
|
| 33 | placeholderElement(this, placeholder);
|
| 34 | }
|
| 35 | });
|
| 36 |
|
| 37 | //翻译国家码
|
| 38 | $('*[data-transid]', $this).each(function () {
|
| 39 | var ele = $(this);
|
| 40 | var transid = ele.attr('data-transid');
|
| 41 | if(ele.attr("name") == "channel"){
|
| 42 | ele.find('option').each(function () {
|
| 43 | var item = $(this);
|
| 44 | if (item.val() != 0) {
|
| 45 | var val = item.val().split("_");
|
| 46 | item.html( val[1] + "MHz " + $.i18n.prop(transid + '_' + val[0]) );
|
| 47 | } else {
|
| 48 | item.html( $.i18n.prop(transid + '_0') );
|
| 49 | }
|
| 50 | });
|
| 51 | }else{
|
| 52 | ele.find('option').each(function () {
|
| 53 | $(this).html($.i18n.prop(transid + '_' + $(this).attr('value')));
|
| 54 | });
|
| 55 | }
|
| 56 | });
|
| 57 |
|
| 58 | function translateElement(ele, trans, transData){
|
| 59 | var word;
|
| 60 | if(transData == undefined) {
|
| 61 | word = $.i18n.prop(trans);
|
| 62 | } else {
|
| 63 | word = $.i18n.prop.apply(null, [trans].concat(transData.split(",")));
|
| 64 | }
|
| 65 | var nodeName = ele.nodeName.toUpperCase();
|
| 66 | if (nodeName == 'INPUT' || nodeName == 'SELECT' || nodeName == 'TEXTAREA') {
|
| 67 | $(ele).val(word);
|
| 68 | } else if (nodeName == 'BUTTON') {
|
| 69 | $(ele).text(word);
|
| 70 | } else {
|
| 71 | $(ele).html(word);
|
| 72 | }
|
| 73 | }
|
| 74 |
|
| 75 | function placeholderElement(ele, trans){
|
| 76 | var word = $.i18n.prop(trans);
|
| 77 | var nodeName = ele.nodeName.toUpperCase();
|
| 78 | if (nodeName == 'INPUT') {
|
| 79 | $(ele).attr('placeholder', word);
|
| 80 | }
|
| 81 | }
|
| 82 |
|
| 83 | $('.content div.row', $this).each(function () {
|
| 84 | var $row = $(this);
|
| 85 | if ($row.has('.required').length > 0) {
|
| 86 | $("label:first-child", $row).append("<i class='colorRed'> *</i>");
|
| 87 | } else {
|
| 88 | $("label:first-child", $row).append("<i class='colorRed' style='visibility: hidden;'> *</i>");
|
| 89 | }
|
| 90 | });
|
| 91 |
|
| 92 | return $this;
|
| 93 | };
|
| 94 | })(jQuery);
|