美文网首页
中英国际化

中英国际化

作者: 索隆萨克 | 来源:发表于2018-11-05 18:03 被阅读15次

最近做的项目时不时需要增加一些设备信息,有要求国际化,不停徘徊于Google翻译,英文全大写,中文转Unicode的页面中。所以花了一点时间弄了一个基于Vue的小demo。输入中文和英文和,自动生成国际化命名,点击按钮自动复制,爽死了。
英文命名时设置保存四个字符
效果:


image.png

目录结构:


image.png
代码:
html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0" >
    <title>国际化</title>
    <link rel="stylesheet" href="src/css/index.css">
    <script type="text/javascript" src="src/js/vue.min.js"></script>
    <script src="https://cdn.bootcss.com/clipboard.js/1.7.0/clipboard.js"></script>
</head>
<body>
    <div id="todo" class="todo">
        <div class="header">
            <section>
                <form action="javascript:void(0)">
                    <label for="title">国际化</label>
                    <button class="addBtn" v-on:click="start"></button>
                    <input type="text" name="title" placeholder="english..." required="required" autocomplete="off" v-model="eng" v-on:keypress.enter="start">
                    <input type="text" name="title" placeholder="中文..." required="required" autocomplete="off" v-model="chi" v-on:keypress.enter="start">
                </form>
            </section>
        </div>
        <section>
            <h2>Unicode<span id="Unicode" class="count">{{unicode}}</span>
                <button type="button" id="btn1"  class="btn"  data-clipboard-action="copy" data-clipboard-target="#Unicode">copy</button> 
            </h2>
            
            <h2>English<span id="English" class="count">{{english}}</span>
                <button type="button" id="btn2"  class="btn"  data-clipboard-action="copy" data-clipboard-target="#English">copy</button>  
            </h2>
            <h2>Only Unic<span id="Only" class="count">{{onlyuni}}</span>
                <button type="button" id="btn3"  class="btn"  data-clipboard-action="copy" data-clipboard-target="#Only">copy</button>  
            </h2>
            
        </section>
        <p class="footer">Derek</p>
    </div>
    <script type="text/javascript" src="src/js/index.js"></script>
</body>
</html>

css

* {
    margin: 0;
    padding: 0;
}

body {
    font-size: 16px;
    background: #cdcdcd;
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.header {
    height: 50px;
    background: rgba(47, 47, 47, 0.98);
}

section {
    max-width: 620px;
    margin: 0 auto;
    padding: 0 10px;
}

label {
    float: left;
    width: 100px;
    line-height: 50px;
    color: #ddd;
    font-size: 24px;
    cursor: pointer;
}

.header input {
    float: right;
    width: 37%;
    height: 24px;
    margin-top: 12px;
    text-indent: 10px;
    border-top-left-radius: 5px;
    border-bottom-left-radius: 5px;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.24), 0 1px 6px rgba(0, 0, 0, 0.45) inset;
    border: none;
}

.header button{
    float: right;
    width: 48px;
    height: 25px;
    margin-top: 12px;
    background-color: #07FC27;
    border-top-right-radius: 5px;
    border-bottom-right-radius: 5px;
    outline: none;
    font-weight: bolder;
}

h2 {
    position: relative;
    margin: 26px 0;
}

h2 .count{
    position: absolute;
    top: 2px;
    right: 5px;
    display: inline-block;
    padding: 0 5px;
    height: 20px;
    width: 80%;
    border-radius: 20px;
    background: #e6e6fa;
    line-height: 22px;
    text-align: center;
    color: #666;
    font-size: 14px;
}
.btn{
    position: absolute;
    top: 2px;
    right: 5px;
    display: inline-block;
    padding: 0 5px;
    height: 20px;
    width: 10%;
    border-radius: 20px;
    background: #07FC27;
    line-height: 14px;
    text-align: center;
    color: #666;
    font-size: 14px;
    outline: none;
}

.btn:hover{
    cursor: pointer;
}

ol {
    margin: 28px 0 32px;
}

ol,
ul {
    list-style-type: none;
}

li {
    height: 32px;
    line-height: 32px;
    background: #fff;
    position: relative;
    margin-bottom: 10px;
    padding: 0 48px;
    border-radius: 3px;
    border-left: 5px solid #629a9c;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.07);
}

li input {
    position: absolute;
    top: 6px;
    left: 22px;
    width: 22px;
    height: 22px;
    cursor: pointer;
}

li p {
    line-height: 34px;
}

li a {
    position: absolute;
    top: 4px;
    right: 5px;
    display: inline-block;
    width: 14px;
    height: 12px;
    border-radius: 14px;
    border: 6px double #fff;
    background: #ccc;
    line-height: 12px;
    text-align: center;
    color: #fff;
    font-weight: bold;
    font-size: 14px;
    cursor: pointer;
}

#doneList li {
    border-left: 5px solid #999;
    opacity: 0.5;
}

.footer {
    font-size: 14px;
    text-align: center;
    color: #666;
}

@media only screen and (max-width: 400px){
    .header input{
        width: 52%;
    }
}

js

var todo = new Vue({
    el: "#todo",
    data: {
        chi:'',
        eng:'',
        unicode: 'hello',
        english: 'world',
        onlyuni:"!"
    },
    mounted: function() {
        var clipboard1 = new Clipboard('#btn1');
        var clipboard2 = new Clipboard('#btn2');
        var clipboard3 = new Clipboard('#btn3');
    },
    methods: {
        start: function() {
            if (!this.chi || !this.eng) return;
            this.onlyuni = this.toUnicode(this.chi);
            this.unicode = "COL."+this.toEnglish(this.eng)+"="+this.toUnicode(this.chi);
            this.english = "COL."+this.toEnglish(this.eng)+"="+this.eng;
            this.chi = "";
            this.eng = "";
        },
        toUnicode: function(data) {
            if (data == '') return '请输入汉字';
            var str = '';
            for (var i = 0; i < data.length; i++) {
                str += "\\u" + parseInt(data[i].charCodeAt(0), 10).toString(16);
            }
            return str;
        },
        toEnglish: function(data) {
            var arr = data.split(" ");
            for (var i = 0; i < arr.length; i++) {
                arr[i] = this.toUpper(arr[i]);
            }
            return arr.join("_");
        },
        toUpper:function(str){
            var arr = str.split("");
            if (arr.length>4) {
                arr = arr.slice(0,4);
            }
            for (var i = 0; i < arr.length; i++) {
                arr[i] = arr[i].toUpperCase();
            }
            return arr.join("");
        }
    }
});

相关文章

  • 屌丝浅谈前端国际化

    近来公司规划项目国际化,what?国际化?那么高大上~嗯,浅说也就是中英两语言适配。那么嗯,挺好的,大概一个构思也...

  • SpringBoot项目国际化

    1.背景 最近,客户提了个需求要求网站国际化,提供中英文两种版本,可切换。so,就琢磨起国际化了,还早就知道有国际...

  • 中英国际化

    最近做的项目时不时需要增加一些设备信息,有要求国际化,不停徘徊于Google翻译,英文全大写,中文转Unicode...

  • Grails国际化实例

    Grails实现国际化(中英文切换) 在grails-app/i18n分别配置英文(messages.proper...

  • 国际化中英文

    录屏软件国际化 主界面 录屏 屏幕录制,快捷方便 录制质量选择:流畅、标准、精细 微课类型选择: 全部微课、录屏微...

  • Vue国际化处理 vue-i18n 以及项目自动切换中英文

    0. 直接上 预览链接 Vue国际化处理 vue-i18n 以及项目自动切换中英文 1. 环境搭建 命令...

  • 前端国际化优化方案

    国际化一般都是使用 i18n 这个库,在开发过程中需要对中英文两个文件内容中添加对应中英文文本,业务代码中使用可读...

  • 英语口译翻译要注意哪些问题

    如今,英语在我国生活中很普遍了,但是精通英语并非易事,在当下国际化交流中英语口译应用最为广泛,英语口译公司就当下英...

  • IOS开发之App语言国际化,内部切换中英文等

    今天项目中添加了一个需求,App设置中有个语言切换,需要实现的效果是中英繁切换,针对APP国际化进行操作,使APP...

  • :lang 选择器最佳实践

    在公司做项目的时候遇到一个情况。项目需要做国际化,并且中英文环境下,样式会有不同。所以选择了:lang 选择器 按...

网友评论

      本文标题:中英国际化

      本文链接:https://www.haomeiwen.com/subject/getexqtx.html