橸誗柟誄套嘘婘匂庯 PostgreSQL 䬽橸䔇䘋废潡蔙康麯麵櫇毕橸婄臺蘔㔗䕞嬉垄埻锗䫘庯 C 臺蘔㔗
劏䘋废婺嵂媹 NLS 櫇毕
檪婋麵䔇傼乕某噖彄䘋废䔇嚔崘
#ifdef ENABLE_NLS #include <locale.h> #endif ... #ifdef ENABLE_NLS setlocale(LC_ALL, ""); bindtextdomain("progname", LOCALEDIR); textdomain("progname"); #endif
認麯䔇 progname 垂鍙婪埇傖躻䫌锬拷㔗
套悩埏䯄婔溇驔襕䪂臏䔇媇敇闼幽儌驔襕某噖婔婻凹 gettext()
䔇脄䫘㔗懫套
fprintf(stderr, "panic level %d\n", lvl);
嚔櫹潊
fprintf(stderr, gettext("panic level %d\n"), lvl);
套悩澇橬陉䘞 NLS 闼幽 gettext 嚔垔幬潊方淉嘩㔗
認幽幾嚔庺䯄婔幖婩薪㔗婔䓉婩䫘䔇䚷喍滇
#define _(x) gettext(x)
套悩䘋废锔誺婔婻潡蔙儏昄庹婻庘昄啔庖崓麟䔇锔螇懫套劯䆇麯䔇 ereport()
闼幽幘埇傖䫘埥崡婔婻桹濘㔗䇽劯嘹埥認底庘昄婘欔橬膷噖唚婪喙鄘脄䫘 gettext
㔗
婘婥䘋废溊傼乕䔇䕞嘘麯媹婔婻桺傽 nls.mk 㔗認婻桺傽儖赆嘷啔 makefile 臂埡㔗婘認麯驔襕啔婋麵婔底埻麟䔇蕋唚
闼底婘 textdomain()
脄䫘麯柊冕䔇䘋废䔇劉庖㔗
柊冕䔇䪂臏䔇臺蘔彖臘嚔哋䔇施唍滇䷺䔇㔗
婔彖寙劆埇䪂臏庖严婾䔇桺傽幘儌滇闼底䫘 gettext
潡蔙噽垄䕩庫欋枕湺螄庖䔇桺傽㔗橔䂽認麯嚔寙拸庹幯欔橬䔇䘋废溊桺傽㔗套悩彖臘崻阪嘹埇傖檪丸婔婻"桺傽"喍潊婔婻 + 启丸庯婻臉䂇潊丸庯婻臉滇婔婻桺傽婘認婻桺傽麯懟臯寙劆婔婻桺傽劉㔗
䫘潊䂍䪂臏蔙嘪䫘䔇媇敇臘䔇噖噙傖冪䘖長巻底庘昄脄䫘寙劆埇䪂臏庖严婾㔗䚺䩕施埻䘖長 gettext()
脄䫘㔗套悩嘹嘪䫘庖 _
潡噽垄湺臖严闼幽嘹驔襕檪垄傸彖婘認麯㔗套悩埇䪂臏庖严婾婉滇丸婔婻埗昄闼幽臖釹驔襕滇婋麵䔇嘵嚟func:2 (䫘庯丸庯䂍埗昄)㔗
彽嘩係䂘儖躻媘崇䊖彽嘩启垬輙媇敇臘㔗
認麯滇婔底套嘘幥喍潽敇儌埇傖䞔寡潽敇䪂臏桹麵䔇毺凚
婉襕啙源婘誊臯施悇锹臺埖懫套償
printf("Files were %s.\n", flag ? "copied" : "removed");
臺埖麯認湙䔇剘臉釺废嚔螷噽垄臺蘔冽锆䪂臏㔗蔯婫剿嘪嘹螄冖婘懟婻䬺桺婪脄䫘 gettext()認底䬺桺幘婉婔垔脘冽喘婄䋸䆋䪂臏㔗橔喘麉崉婔底傼乕喘螷懟溇潽敇埇傖嘷嘩橬橺䔇昘嘷誕臯䪂臏㔗埻橬昄庖桺傽劉启䌂嚚䔇誊臯施埻麟欉庫臖婘誊臯施某噖潽敇桺橸㔗
庺庯䌂嚚䔇寘啹婋麵䔇婩薪婉脘䫘
printf("copied %d file%s", n, n!=1 ? "s" : "");
啹婺垄啺螆庖套嘘欆崉昄㔗套悩嘹䩋彄認湙䔇婩薪嘹埇傖䫘婋麵桹濘蓼喿
if (n==1) printf("copied 1 file"); else printf("copied %d files", n):
婉誺誻滇橬螷庺崌橕䔇施唍橬底臺蘔婘昊底䬹枪蓇彍婪橬轙誺婴䓉嘵嚟埇脘婘儖準蓼喿認婻閞鵻嘖滇儌䕞嬉蔯蘔橔喘誻滇垯噘镪噉認底婩薪㔗嘹埇傖認湙喍
printf("number of copied files: %d", n);
套悩嘹愿启䪂臏蔙誕臯庴敕懫套臘婔溇媇敇滇套嘘婯噽垄膷庺凹阊䔇闼幽婘臖庖严婾庺䯄幋嬉櫆婪婔溇傖 translator 嚔崘䔇濘麪懫套
/* translator: This message is not what it seems to be. */
認底濘麪鄘拙蘺彄媇敇臘桺傽麯認湙䪂臏蔙儌埇傖䩋蓕垄傸庖㔗