0

40 以上の言語への翻訳が必要なプロジェクトに取り組んでいます。

私はほとんどのものをすべて整理しましたが、これは本当に私を悩ませています. これを見て、何が必要かを確認してください。

<script type="text/javascript">
/* Purpose: Converts all non-latin based characters to their ASCII entity value
 * Usage: [String].encode()
 * Arguments: none
 * Returns: String
 */
String.prototype.encode = function() {
        return this.replace(/([^\x01-\x7E])/g, function(s) { return         "&#"+s.charCodeAt(0)+";"; });
};

/**
 * Converts all ASCII entity value characters into their unicode equivelant
 * @return (String)
 */
String.prototype.decode = function() {
        Number.prototype.toHex = function(pad) {
            var s = this.toString(16).toUpperCase();
            var v = "";
            if(typeof pad == "number") {
                    while(v.length + s.length < pad) {
                            v += "0";
                    }
            }
            return v + s;
    };
    return this.replace(/(&#([^;]*);)/g, function(s) { return unescape("%u"+        Number(RegExp.$2).toHex(4)); });
};

function translate() {
document.getElementById("txtOutput").value =         document.getElementById("txtInput").value.encode();
}
</script>

<div class="admin_block">

<h1>Translator</h1>
<p>Sometimes you need to add non latin Characters to the templates, php code and more. This tool will help you convert your text</p>
<h2>Type or paste non latin text in here</h2>
<form name="input" onmousemove="translate();">
    <textarea style="width: 900px" id="txtInput" onkeyup="translate();" onchange="translate();" onmouseup="translate();" onmousemove="translate();"></textarea>
</form>

<h2>Copy and paste this safe code below</h2>
<form onmousemove="translate();">
    <textarea style="width: 900px" id="txtOutput"></textarea><br />
    <button id="btnSelect" onclick="translate();document.getElementById('txtOutput').select(); return false;">Translate and select</button>
</form>

</div>

ロシア語のテキスト、タイ語などを取得して、素晴らしい JS コンバーターにポップします。ASCII 値が出力されます。これらの値は、PHP 配列、HTML テンプレートなどで使用できるようになり、すべて問題ありません。

PHP 言語配列を新しい言語に変換するための PHP 翻訳クラスの新しいメソッドを作成しています - 問題はここにあります。この JS が正常に動作していることを PHP に実行させるにはどうすればよいですか? htmlentities、iconv などを試しました。次のような翻訳されたテキストを見たいです。

&#1057;&#1086;&#1083;&#1086;&#1084;&#1086;&#1085;&#1086;&#1074;&#1099; &#1054;&#1089;&#1090;&#1088;&#1086;&#1074;&#1072;

Соломоновы Острова

4

1 に答える 1