* 遍历节点 * * @param {Element} node 节点
(node)
| 40 | * @param {Element} node 节点 |
| 41 | */ |
| 42 | function walk(node) { |
| 43 | var nodes = node.childNodes; |
| 44 | |
| 45 | for (var i = 0, len = nodes.length; i < len; i++) { |
| 46 | var el = nodes[i]; |
| 47 | // todo 1. 修复多属性翻译问题; 2. 添加事件翻译, 如论预览信息; |
| 48 | |
| 49 | if (el.nodeType === Node.ELEMENT_NODE) { // 元素节点处理 |
| 50 | |
| 51 | // 元素节点属性翻译 |
| 52 | if (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA') { // 输入框 按钮 文本域 |
| 53 | if (el.type === 'button' || el.type === 'submit') { |
| 54 | transElement(el, 'value'); |
| 55 | } else { |
| 56 | transElement(el, 'placeholder'); |
| 57 | } |
| 58 | } else if (el.hasAttribute('aria-label')) { // 带提示的元素,类似 tooltip 效果的 |
| 59 | transElement(el, 'aria-label', true); |
| 60 | |
| 61 | if (el.hasAttribute('data-copied-hint')) { // 复制成功提示 |
| 62 | transElement(el.dataset, 'copiedHint'); |
| 63 | } |
| 64 | } else if (el.tagName === 'OPTGROUP') { // 翻译 <optgroup> 的 label 属性 |
| 65 | transElement(el, 'label'); |
| 66 | } |
| 67 | |
| 68 | // 跳过 readme, 文件列表, 代码显示 |
| 69 | if (el.id !== 'readme' && !I18N.conf.reIgnore.test(el.className)) { |
| 70 | walk(el); // 遍历子节点 |
| 71 | } |
| 72 | } else if (el.nodeType === Node.TEXT_NODE) { // 文本节点翻译 |
| 73 | transElement(el, 'data'); |
| 74 | } |
| 75 | |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * 获取翻译页面 |
no test coverage detected