suchen
HeimBackend-EntwicklungPHP-Tutorial php 使用gettext实现国际化有关问题! 用过的进来讨论一下撒~

php 使用gettext实现国际化问题! 用过的进来讨论一下撒~~
我的环境:ubuntu server +xampp 套件

php代码中的输出是使用简体中文来输出的,现在 要将简体中文的输出转换成英文,和繁体中文。
使用gettext 来做。

现象 : 无法转换!
  但是, 如果吧代码中得中文换成英文字符,然后在 .po文件中更新一下,再生成.mo文件后,则能够正常转换!


也就是说 当po文件中的需要转换的字符串为中文的时候 则不能转!

即 中文 --》 其他语言 ,不成功!
  英文 --》 其他语言 ,则能够成功!!


请大家来讨论下这是为什么?!



------解决方案--------------------
下载地址:
http://sourceforge.net/projects/gnuwin32/files/gettext/0.14.4/gettext-0.14.4-src.zip/download

PHP code

第一步:撰写PHP程序
<?php putenv("LANG=zh_CN");
setlocale(LC_ALL, "zh_CN");

bindtextdomain("test", "./locale");
textdomain("test");

echo gettext("Hello!");
echo gettext("World!");
echo gettext("Hello World!");
?>
第二步:
xgettext.exe -d test -L PHP --from-code=utf-8 index.php

第三步:
修改test.po为:

#: ../index.php:8
msgid "Hello!"
msgstr "你好!"

#: ../index.php:9
msgid "World!"
msgstr "世界!"

#: ../index.php:10
msgid "Hello World!"
msgstr "你好,世界!"

第四步:
msgfmt -o zh_CN/test.mo zh_CN/test.po
生成test.mo文件
第五步:
创建locale\zh_CN\LC_MESSAGES目录,将test.mo放入该目录中
第六步:
重启apache,访问index.php即可看到效果
<br><font color="#e78608">------解决方案--------------------</font><br>
编码用utf-8试试 <div class="clear">
                 
              
              
        
            </div>
Stellungnahme
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Apple iPhone 16 Pro as Leica smartphone: Leica subsidiary confirms camera grip with official Leica appApple iPhone 16 Pro as Leica smartphone: Leica subsidiary confirms camera grip with official Leica appJun 13, 2024 pm 08:52 PM

LeicareleasedtheLeicaLuxcameraappfortheAppleiPhoneafewdaysago.However,theappwasnotdevelopedbyLeica,butbyFjorden.ThecompanyhasbeenknownprimarilyforitscameragripsfortheiPhoneandwasacquiredbyLeicainDecember2023.Fo

Remote 3 universal remote control comes with touchscreen, but without subscription or server obligationRemote 3 universal remote control comes with touchscreen, but without subscription or server obligationJun 14, 2024 am 09:13 AM

SincethedemiseofLogitech'spopularHarmonyremotecontrols,themarketforhigh-qualityuniversalremotecontrolshasbeenfragmentedatbest.UnfoldedCircleaimstoavoidthefateoftheHarmonyUltimatebyeliminatinganyserverobligationsorsubs

Light Phone 3 launches with 50% discount, monochrome OLED and minimalist designLight Phone 3 launches with 50% discount, monochrome OLED and minimalist designJun 13, 2024 pm 10:18 PM

WhiletheLightPhone2from2018wasstillequippedwithaneconomicale-inkdisplay,theLightPhone3usesanOLEDdisplaythatcanonlydisplaygrayscale.Thereasonfortheswitchtothe3.92-inchOLEDpanelwithitsresolutionof1,240x1,080isth

Jabra discontinues Elite wireless earbuds lineupJabra discontinues Elite wireless earbuds lineupJun 14, 2024 am 09:39 AM

TheJabraEliteserieshascometoanend,withGNCEOPeterKarlstromerannouncingthediscontinuationofthewirelessearbudswithinthelineupinapressrelease.Petersaysthatthechangingmarketdynamicsandhowchallengingithasbecometogetas

Audio-Technica unveils ATH-S300BT wireless headphones with hear-through noise-cancellation, 90 hours battery life, and multipoint pairingAudio-Technica unveils ATH-S300BT wireless headphones with hear-through noise-cancellation, 90 hours battery life, and multipoint pairingJun 14, 2024 am 09:46 AM

Audio-TechnicahasunveiledtheATH-S300BTwirelessheadphoneswithhear-throughnoise-cancellation,multipointpairing,and90hoursofbatterylife.Thenoise-cancellingfeaturehasthreemodes:off,on,andhear-through,whereambientsoundscanbehea

First complete PCIe 7.0 IP solution presented by Synopsys coming to market in 2025 for HPCs and AI supercomputersFirst complete PCIe 7.0 IP solution presented by Synopsys coming to market in 2025 for HPCs and AI supercomputersJun 14, 2024 am 09:19 AM

Backin2022,whenPCIe7.0wasstartingtotakeshapeasafuturestandard,PCIe5.0wasjusthittingtheservermarketsandtheprospectofseeingPCIe6.0devicesavailableanytimesoon,letalonePCIe7.0ones,wasquitefar-fetched.CurrentlyPCIe5

Hisense unveils new Starlight S1 Pro Laser TV with up to 100-inch foldable screenHisense unveils new Starlight S1 Pro Laser TV with up to 100-inch foldable screenJun 14, 2024 am 10:07 AM

HisensehaslaunchedtheStarlightS1ProLaserTVinChina.TheproductwasteasedinaWeibopostearlierthismonthandwasunveiledatthe2024HisenseTVNewProductLaunchConferenceeventonJune12th.TheStarlightS1Proisa4KlaserTVinfours

HYgreen GOMOW new robot lawn mower arriving soon with discountHYgreen GOMOW new robot lawn mower arriving soon with discountJun 14, 2024 am 10:06 AM

TheHYgreenGOMOWrobotlawnmowerisduetolaunchinGermanysoonandcouldarriveinothercountriesinthefuture.Theproductwillbeshownatspoga+gafa2024inColognefromJune16thto18th,withtheCalifornia-basedcompanylocatedatHall5.1St

See all articles

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

Heiße Werkzeuge

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

SAP NetWeaver Server-Adapter für Eclipse

SAP NetWeaver Server-Adapter für Eclipse

Integrieren Sie Eclipse mit dem SAP NetWeaver-Anwendungsserver.

mPDF

mPDF

mPDF ist eine PHP-Bibliothek, die PDF-Dateien aus UTF-8-codiertem HTML generieren kann. Der ursprüngliche Autor, Ian Back, hat mPDF geschrieben, um PDF-Dateien „on the fly“ von seiner Website auszugeben und verschiedene Sprachen zu verarbeiten. Es ist langsamer und erzeugt bei der Verwendung von Unicode-Schriftarten größere Dateien als Originalskripte wie HTML2FPDF, unterstützt aber CSS-Stile usw. und verfügt über viele Verbesserungen. Unterstützt fast alle Sprachen, einschließlich RTL (Arabisch und Hebräisch) und CJK (Chinesisch, Japanisch und Koreanisch). Unterstützt verschachtelte Elemente auf Blockebene (wie P, DIV),

Herunterladen der Mac-Version des Atom-Editors

Herunterladen der Mac-Version des Atom-Editors

Der beliebteste Open-Source-Editor