简体   繁体   English

使用Google Translate在PHP中进行编码错误

[英]Encoding error in PHP with Google Translate

I have some text which I need to translate into Japanese. 我有一些文字需要翻译成日文。

Translate text, webpage, or document

Google Translate returns the string as: Google翻译将字符串返回为:

翻訳テキスト、 Webページ、またはドキュメント

When I am writing that text to a file (ja.po), it looks like: 当我将该文本写入文件(ja.po)时,它看起来像:

–|–óƒeƒLƒXƒgA Webƒy[ƒWA‚Ü‚½‚̓hƒLƒ…ƒƒ“ƒg

What would be the error? 这是什么错误?

I am using poeditor.exe to view the file. 我正在使用poeditor.exe来查看文件。 I am not using any encoding function at present. 我目前没有使用任何编码功能。

for(/*extracting from the trnslated string array*/)
{
    $pattern = "/msgid \"".preg_quote($id, '/')."\"(\r?\n)msgstr \"\"/";
    $string = str_replace('"', '\"', $string);
    $replacement = "msgid \"$id\"\nmsgstr \"". $string . "\"";
    $res = preg_replace($pattern, $replacement, $con);
    $con = $res;
}
file_put_contents("ja.po", $con);

It looks like the program you are using to read that file isn't understanding the encoding format that you wrote it out as. 看来您用来读取该文件的程序不了解您写成的编码格式。 Are you using UTF8 all the way through? 您是否一直使用UTF8? Maybe try http://www.php.net/manual/en/function.iconv.php to convert it to UTF8 if it is some other encoding. 也许尝试http://www.php.net/manual/en/function.iconv.php将其转换为UTF8(如果使用其他编码)。

How are you getting the string from Google and how are you writing it? 您如何从Google获取字符串以及如何编写字符串? Somewhere along the way it gets converted from UTF8 to latin1 I suppose. 我猜想它会从UTF8转换为latin1。 If you can figure out where it happens, use mb_convert_encoding to fix it. 如果您可以确定发生的位置,请使用mb_convert_encoding进行修复。

BTW, the translated Japanese is pretty bad. 顺便说一句,翻译的日语非常糟糕。 ;) ;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM