📄 00000001.htm
字号:
<BR>If the master font that you set for a widget doesn't contain a glyph for <BR> a particular Unicode character that you want to display, Tk attempts to <BR> locate a font that does. Where possible, Tk attempts to locate a font <BR>that matches as many characteristics of the widget's master font as <BR>possible (for example, weight, slant, etc.). Once Tk finds a suitable <BR>font, it displays the character in that font. In other words, the widget <BR> uses the master font for all characters it is capable of displaying, <BR>and alternative fonts only as needed. <BR> <BR>In some cases, Tk is unable to identify a suitable font, in which case <BR>the widget cannot display the characters. (Instead, the widget <BR>displays a system-dependent fallback character such as "?") The <BR>process of identifying suitable fonts is complex, and Tk's algorithms <BR>don't always find a font even if one is actually installed on the <BR>system. Therefore, for best results, you should try to select as a <BR>widget's master font one that is capable of handling the characters <BR>you expect to display. For example, "Times" is likely to be a poor <BR>choice if you know that you need to display Japanese or Arabic <BR>characters in a widget. <BR> <BR>If you work with text in a variety of character sets, you may need to <BR>search out fonts to represent them. Markus Kuhn has developed a free <BR>6x13 font that supports essentially all the Unicode characters that <BR>can be displayed in a 6x13 glyph. This does not include Japanese, <BR>Chinese, and other Asian languages, but it does cover many others. The <BR>font is available at <A HREF="http://www.cl.cam.ac.uk/~mgk25/ucs-fonts.html.">http://www.cl.cam.ac.uk/~mgk25/ucs-fonts.html.</A> <BR>His site also contains many useful links to other sources of fonts and <BR>font information. <BR> <BR>Message Catalogs <BR>The new msgcat package provides a set of functions for managing <BR>multilingual user interfaces. It allows you to define strings in a <BR>message catalog, which is independent from your application or package <BR>and which you can edit or localize without modifying the application <BR>source code. The msgcat package is optional, but Ajuba Solutions <BR>recommends using it for all multilingual applications and packages. <BR> <BR>The basic principle of the msgcat package is that you create a set of <BR>message files, one for each supported language, containing localized <BR>versions of all the strings your application or package can display. <BR>Then in your application or package, instead of using a string directly, <BR> you call the ::msgcat::mc command to return a localized version of <BR>the string you want. <BR> <BR>This document provides only a brief introduction to message catalogs. <BR>The msgcat package provides additional features such as namespace <BR>support and "best match" handling of sublocales. See the msgcat.n <BR>reference page for more information. <BR> <BR>Using Message Catalogs <BR>Using message catalogs from within your application or package <BR>requires the following steps: <BR> <BR>Optionally set the locale using the ::msgcat::mclocale command. If you <BR>don't call mclocale, the locale defaults to the value of the env(LANG) <BR>environment variable at the time the msgcat package is loaded. If <BR>env(LANG) isn't defined, then the locale defaults to "C". <BR>Call ::msgcat::mcload to load the appropriate message files. The <BR>mcload command requires as an argument a directory containing your <BR>message files. <BR>Anywhere in your script that you would typically specify a string to <BR>display, use the ::msgcat::mc command instead. The mc command takes as <BR>an argument a source string and returns the translation of that string <BR>in the current locale. <BR>The following code fragment demonstrates how you could use the msgcat <BR>package in a script: <BR> <BR># Use the default locale as specified by env(LANG). <BR># You could explicitly set the locale with a command such as <BR># ::msgcat::mclocale "en_UK" <BR> <BR># Load the messages files. In this example, they are stored <BR># in a subdirectory named "msgs" which is in the same directory <BR># as this script. <BR> <BR>∶<I>:msgcat::mcload [file join [file dirname [info script]] msgs] </I><BR> <BR># Display a welcome message <BR> <BR>puts [::msgcat::mc "Welcome to Tcl!"] <BR>In this example, instead of directly displaying the message "Welcome <BR>to Tcl!", the application calls mc to retrieve a localized version of <BR>the string. The string returned by mc depends on the current locale. For <BR> example, in the "es" locale mc could return the Spanish-language <BR>greeting "隆Bienvenido a Tcl!" <BR> <BR>If a message file doesn't exist for the current locale, mc executes <BR>the procedure ::msgcat::mcunknown. The default behavior of mcunknown <BR>is to return the original string ("Welcome to Tcl!" in this case), but <BR>you can redefine it to perform any action you want. <BR> <BR>Creating Localized Message Files <BR>To use the msgcat package, you need to prepare a set of message files <BR>for your package or application, all contained within the same <BR>directory. The name of each message file is a locale specifier <BR>followed by the extension ".msg" (for example, es.msg for a Spanish <BR>message file or en_UK.msg for a UK English message file). <BR> <BR>Each message file contains a series of calls to ::msgcat::mcset to set <BR>the translation strings for that language. The format of the mcset <BR>command is: <BR> <BR>∶<I>:msgcat::mcset locale src-string ?translation-string? </I><BR>The mcset command defines a locale-specific translation for the given <BR>src-string. If no translation-string argument is present, then the value <BR> of src-string is also used as the locale-specific translation string. <BR> <BR>So, if American English is the "source language" for your application, <BR>an en_UK.msg file might contain commands such as: <BR> <BR>∶<I>:msgcat::mcset en_UK "Welcome to Tcl!" </I><BR>∶<I>:msgcat::mcset en_UK "Select a color:" "Select a colour:" </I><BR>Note that no translation string is provided for the first line, so the <BR>resulting "translation" for the en_UK locale is the same as the American <BR> source string, "Welcome to Tcl!" If you omitted this entry in the <BR>message file, then calling mc with the source string "Welcome to Tcl!" <BR>in the en_UK locale would result in mcunknown being called. Although the <BR> default behavior of mcunknown would produce the desired results <BR>(returning "Welcome to Tcl!"), you could run into problems if you <BR>override the behavior of mcunknown. Therefore, it is always safest to <BR>include a mcset mapping for every source string in your application, <BR>even if a particular locale doesn't require a "translation" for that <BR>string. <BR> <BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -