avatar
Today is 星期天
2010年09月5日

2008年04月27日

用gettext实现i18n多语言界面

由 晨笛 — 分类目录: Python评论暂缺

想在开启程序界面的时候,中文系统就出现中文,英文系统就出现英文吗?呵呵,gettext就可以实现.

过去非常向往那种风格: 选了语言,就可以用什么语言显示.以前玩anjuta的时候总是有个gettext错误,弄得我每次新建工程的时候第一件事就是关掉gettext,而且搞的好像非常神秘似的,今天才知道就是这个gettext有这种能力.

其实说起来也没什么神秘的,gettext也就是建立一个语言对应文件,必要的时候去文件中查找某国语言,然后以那种形式读出,替代原来的字符罢了.

用Python玩个简单的例子吧!其实C++什么的都有相关程序,只不过C++写起来太麻烦了,而且C++的库在Windows上是一大堆,需要下载好些依赖的dll和exe,Python才两个py文件就可以.

Python的i18n工具的存放位置在Python24\Tools\i18n目录下,一共两个msgfmt.py和pygettext.py两个文件.

现在我们先来制作语言对应文件.

运行pygettext.py会生成一个messages.pot,注意,这不是个ppt模板,是一个po文件模板.拷贝一个,改名为gb.po,其实随便改成什么都好,只要扩展名为po(其实pot也可以),用记事本打开,里面的内容如下:
[code]
# SOME DEscrīptIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR , YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2006-11-04 11:47+中国标准时间\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME \n"
"Language-Team: LANGUAGE \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: ENCODING\n"
"Generated-By: pygettext.py 1.5\n"
[/code]

把”Content-Type: text/plain; charset=CHARSET\n”改成
“Content-Type: text/plain; charset=gb2312\n”

把”Content-Transfer-Encoding: ENCODING\n”改成
“Content-Transfer-Encoding: cp936\n”
当然,这要看自己的情况了.gb2312是文件字符集,如果是utf8,则用utf8代替.
然后在文件后面添加msgid,msgstr对,比如添加完是这样:
[code]
# SOME DEscrīptIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR , YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2006-11-04 09:59+中国标准时间\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME \n"
"Language-Team: LANGUAGE \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=gb2312\n"
"Content-Transfer-Encoding: cp936\n"
"Generated-By: pygettext.py 1.5\n"

msgid "Open"
msgstr "打开"

msgid "Edit"
msgstr "编辑"

msgid "delete"
msgstr "删除"

msgid "Export"
msgstr "导出"
[/code]

注意,第一个出现的msgid,msgstr对是文件头中的内容,不要动,否则会出问题.

好了,退出,运行dos命令:
msgfmt.py gb.po
生成一个gb.mo文件,这就是语言翻译库文件.
写个程序运行下:
[python]
import gettext
cat = gettext.GNUTranslations(open(“gb.mo”))
_ = cat.gettext
print _(“Open”)
print _(“Hello”)
[/python]

输出:
打开
Hello

可以看到,定义过的英文被翻译成了中文,其他的没有定义,也就还是英文输出.

Getting started with XULRunner

由 晨笛 — 分类目录: 技术评论暂缺

This article explores the Mozilla platform by building a basic desktop application using XULRunner. Given that Firefox, Thunderbird, and multiple other applications are written using the platform, it a safe bet that it can be used to build a basic application.
I want to build a simple XUL-based desktop application. If you’re going to build a XUL-based desktop application, you’ll probably need to install XULRunner. Let’s start by installing XULRunner installed and making sure it runs a bare-bones application.

Step 1: Download XULRunner
You can find a download link on the main XULRunner page here on MDC.
The XULRunner download for Windows is a zip file, not a true install. As a developer, I like the idea that XULRunner only needs to be unzipped onto my machine. I am assuming that it doesn’t need to hook into my Windows system and that’s a good thing.
The Mac version of XULRunner is distributed as a standard Mac OS X installer.

Step 2: Install XULRunner
On Windows, unzip the archive someplace reasonable. I unzipped it to a new C:\program files\xulrunner folder. Pretty simple so far. On the Mac, just run the installer, which installs XULRunner as XUL.Framework in the /Library/Frameworks directory.
Time to start a simple, bare bones application shell. Call it a XUL “Hello World” if you want. Google turned up a nice tutorial here. It is definitely worth reading. Using the tutorial, I created a simple bootstrap application. All of what you see below can be found in Ryan’s tutorial and the XULRunner documentation here on MDC.

Step 3: Create the application folder structure
On Windows, I created the root in a new c:\program files\myapp folder, but you can create it wherever you like. Here is the subfolder structure:
/myapp
  /chrome
    /content
      main.xul
    chrome.manifest
  /defaults
    /preferences
      prefs.js
  application.ini
Notice that there are 4 files in the folder structure: application.ini, chrome.manifest, prefs.js, and main.xul.

Step 4: Set up application.ini
The application.ini file acts as the XULRunner entry point for your application. It specifies how your application intends to use the XULRunner platform as well as configure some information that XULRunner uses to run your application. Here is mine:
[App]
Vendor=Finkle
Name=Test App
Version=1.0
BuildID=20060101
Copyright=Copyright (c) 2006 Mark Finkle
ID=xulapp@starkravingfinkle.org

[Gecko]
MinVersion=1.8
MaxVersion=1.8

Note: to run this 2006 sample app with 2007 nightly trunk XULRunner builds, change MaxVersion to 1.9.

Step 5: Set up the chrome manifest
The chrome manifest file is used by XULRunner to define specific URIs which in turn are used to locate application resources. This will become clearer when we see how the “chrome://” URI is used. Application chrome can be in a single or a few JAR files or uncompressed as folders and files. I am using the uncompressed method for now. Here is my manifest:
 content myapp file:content/
Note: Make sure your application name is lowercase and longer than 3 characters

Step 6: Set up preferences
The prefs.js file tells XULRunner the name of the XUL file to use as the main window. Here is mine:
 pref(“toolkit.defaultChromeURI”, “chrome://myapp/content/main.xul”);
XULRunner preferences include:
toolkit.defaultChromeURI
Specifies the default window to open when the application is launched.
toolkit.defaultChromeFeatures
Specifies the features passed to window.open() when the main application window is opened.
toolkit.singletonWindowType
Allows configuring the application to allow only one instance at a time.
This is described in further detail in XULRunner:Specifying Startup Chrome Window.

Step 7: Create some XUL
Finally, we need to create a simple XUL window, which is described in the file main.xul. Nothing fancy here, just the minimum we need to make a window. No menus or anything:
<?xml version=”1.0″?>
<?xml-stylesheet href=”chrome://global/skin/” type=”text/css”?>

<window id=”main” title=”My App” width=”300″ height=”300″
xmlns=”http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul”>
  <caption label=”Hello World”/>
</window>
Note: Make sure there is no extra whitespace at the beginning of the XML/XUL file

Step 8: Run the application
The moment of truth. We need to get XULRunner to launch the bare-bones application. From a Windows command prompt opened to the C:\program files\myapp folder, we should be able to execute this:
 xulrunner.exe application.ini
Of course, xulrunner.exe must be in the PATH. Because of where I unzipped XULRunner, I could also try this if xulrunner.exe is not in the PATH:
 ..\xulrunner\xulrunner.exe application.ini
On the Mac, you can run the application by opening a Terminal window, navigating to the myapp directory, and typing:
 /Library/Frameworks/XUL.framework/xulrunner-bin application.ini
You should now see a window that looks something like this. This particular screenshot is from Windows 2000.

Alternative: Use Firefox3 -app to run XUL apps
In recent Firefox 3 pre-release builds (also known as “Gran Paradiso”, or “Minefield”), you can tell the firefox executable to run a XUL application from the command line, instead of the Firefox browser that normally starts. This is similar to starting a XUL app using XULRunner.

Deploying XULRunner 1.8

由 晨笛 — 分类目录: 技术评论暂缺

XULRunner 1.8 is a stable developer preview release. This means that while the release is immature in some areas such as embedding, application deployment, and OS integration, it can be used by developers that are releasing standalone XUL applications. This document explains how this deployment should be managed.

 

Windows

On Windows, XULRunner does not yet have a built-in installation solution; app developers should use pre-existing solutions for a native Windows installer. The installed files should be arranged in the following directory structure:

installdir/
application.ini
components/
… components which are part of the application
chrome/
… chrome which is part of the application
… additional application files such as icons, etc
myapplicationname.exe (This is the “stub executable”… you should copy and rename this file from xulrunner-stub.exe in your XULRunner installation.)
xulrunner/
… copy xulrunner/ to this directory
 

Mac OS X

On Mac OS X, the XULRunner framework bundle is placed in your application bundle:

MyApp.app/
Contents/
Info.plist
Frameworks/
XUL.framework/
files copied from /Library/Frameworks/XUL.framework/Versions/1.8/… make sure you copy all symlinks correctly (use rsync -rl /Library/Frameworks/XUL.framework …).
Resources
application.ini
app_icon.icns
components/
… components which are part of the application
chrome/
… chrome which is part of the application
… additional application files such as icons, etc
MacOS/
xulrunner (This is the “stub executable”… you should copy this file from /Library/Frameworks/XUL.framework/Versions/1.8/xulrunner.)
Additionally, your Mac app WILL NOT RUN without a valid Info.plist file. Here’s a sample one:

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE plist PUBLIC “-//Apple Computer//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd“>

<plist version=”1.0″>

<dict>

         <key>CFBundleDevelopmentRegion</key>

         <string>English</string>

         <key>CFBundleExecutable</key>

         <string>xulrunner</string>

         <key>CFBundleGetInfoString</key>

         <string>1.0</string>

         <key>CFBundleIconFile</key>

         <string>app_icon.icns</string>

         <key>CFBundleIdentifier</key>

         <string>net.yourcompany.yourapplication</string>

         <key>CFBundleInfoDictionaryVersion</key>

         <string>6.0</string>

         <key>CFBundleName</key>

         <string>applicationName</string>

         <key>CFBundlePackageType</key>

         <string>APPL</string>

         <key>CFBundleShortVersionString</key>

         <string>1.0</string>

         <key>CFBundleSignature</key>

         <string>YOURAPP</string>

         <key>CFBundleURLTypes</key>

         <array>

                   <dict>

                            <key>CFBundleURLIconFile</key>

                            <string>app_icon.icns</string>

                            <key>CFBundleURLName</key>

                            <string>YOURAPP Entity</string>

                            <key>CFBundleURLSchemes</key>

                            <array>

                                     <string>chrome</string>

                            </array>

                   </dict>

         </array>

         <key>CFBundleVersion</key>

         <string>1.0</string>

</dict>

</plist>

Edit this as you need to, but CFBundleExecutable MUST be xulrunner, and CFBundleIconFile and CFBundleURLIconFile should be set to the filename of your application icon (app_icon.icns).

 

Linux

Most Linux applications are distributed as simple .tar.bz2 archives which can be unpacked by the user wherever they wish. The archive should be structured as follows:

appname/
application.ini
components/
… components which are part of the application
chrome/
… chrome which is part of the application
… additional application files such as icons, etc
myapplicationname (This is the “stub executable”… you should copy and rename this file from xulrunner-stub in your XULRunner installation.)
xulrunner/
… copy xulrunner/ to this directory

FreeBSD6.1下图形界面KDE和输入法SCIM安装

由 晨笛 — 分类目录: Unix评论暂缺

# sysinstall

选择[Configure]->[Distributions]->[X.Org],如下图:
点击在新窗口中浏览此图片
接下来会出现一个菜单让你选择所需要安装的X.Org的包,如下图所示,请进入每一个选项里选取ALL.
点击在新窗口中浏览此图片

点击在新窗口中浏览此图片
接着选择Exit回到选择安装来源.您可以选择CD/DVD为安装本源,放入第一张CD即可开始安装.

安装KDE:
leo# sysinstall
选择[Configure]->[Packages]->[kde],选择kde-3.5.1如下图:
点击在新窗口中浏览此图片
选择OK,然后Install会有提示要求您放第二张光盘.这里需要等比较长的时间.安装完就退出.

运行
xorgcfg –textmode
点击在新窗口中浏览此图片
配置xorg
本机上所生成的/etc/X11/xorg.conf文件内容如下
leo# cat /etc/X11/xorg.conf
Section “ServerLayout”
       Identifier     “Layout0″
       Screen      0  ”Screen0″ 0 0
       InputDevice    ”Keyboard0″ “CoreKeyboard”
       InputDevice    ”Mouse0″ “CorePointer”
EndSection

Section “Files”
EndSection

Section “Module”
       Load  ”freetype”
       # Load “xtt”
       Load  ”extmod”
       Load  ”glx”
       Load  ”dri”
       Load  ”dbe”
       Load  ”record”
       Load  ”xtrap”
       Load  ”type1″
       Load  ”speedo”
EndSection

Section “InputDevice”
       Identifier  ”Mouse0″
       Driver      ”mouse”
       Option      ”Protocol” “Auto”
       Option      ”Emulate3Buttons”
       Option      ”Device” “/dev/sysmouse”
EndSection

Section “InputDevice”
       Identifier  ”Keyboard0″
       Driver      ”kbd”
       Option      ”XkbModel” “pc101″
       Option      ”XkbLayout” “us”
EndSection

Section “Monitor”

### Comment all HorizSync and VertSync values to use DDC:
       Identifier   “Monitor0″
### Comment all HorizSync and VertSync values to use DDC:
       HorizSync    31.5 – 57.0
       VertRefresh  50.0 – 90.0
EndSection

Section “Device”
       Identifier  ”Card0″
       Driver      ”vmware”
EndSection

Section “Screen”
       Identifier “Screen0″
       Device     “Card0″
       Monitor    ”Monitor0″
       DefaultDepth     24
       SubSection “Display”
               Viewport   0 0
               Depth     24
               Modes    ”1024×768″ “800×600″
       EndSubSection
EndSection

在 /root 目录下 编辑 .xinitrc 文件:
加入下面行
exec /usr/local/bin/startkde
然后执行
startx
即可进入KDE
点击在新窗口中浏览此图片

接着我们要将KDE 汉化,如果要在X-Window 中看到中文的菜单,必须先装中文字体kcfont(国乔字体)及arphicttf(文鼎字体),以及中文信息档(i18n)
# cd /usr/ports/chinese/kcfonts
# make install clean
# cd /usr/ports/chinese/arphicttf
# make install clean
# cd /usr/ports/chinese/kde3-i18n-zh_CN
# make install clean
# cd /usr/ports/chinese/koffice-i18n-zh_CN
# make install clean
接着编辑/etc/X11/xorg.conf
leo# vi /etc/X11/xorg.conf
在Section “Files”之间加入下面三行,以使X-Window能找到正确的字体路径,如下:
Section “Files”
       FontPath     “/usr/X11R6/lib/X11/fonts/TrueType”
       FontPath     “/usr/X11R6/lib/X11/fonts/local”
       FontPath     “/usr/X11R6/lib/X11/fonts/misc”
EndSection
更改保存后进入KDE。
找到Setting->Desktop Setting Wizard进行设置:
点击在新窗口中浏览此图片

按Next一直到最后即可。
如果您想要有Windows的字体,可以到将Win上面的字体COPY到下面的目录
#cd /usr/X11R6/lib/X11/fonts/TrueType
然后打开“控制中心”->外观和主题->字体,里面设置你所需要的字体和字体大小。我是把windows下面的simsun.ttc和tohoma.ttf拷贝到了FreeBSD上面,然后应用windows的字体,这样感觉比较舒服,毕竟是平时看惯了windows的字体了。看其它字体感觉怪怪的。
-rw-r–r–  1 root  wheel  10507340 May 14 19:07 simsun.ttc
-rw-r–r–  1 root  wheel    379856 May 14 19:07 tahoma.ttf
点击在新窗口中浏览此图片
中文输入法安装:
cd /usr/ports/chinese/scim-tables/
make install

cat >> /etc/csh.cshrc << OK
setenv LANG zh_CN.eucCN
setenv LC_CTYPE zh_CN.eucCN
setenv XMODIFIERS @im=SCIM
setenv GTK_IM_MODULE scim
OK
另外在进入X之前需要执行(在~/.xinitrc中加入)
exec scim -d &
此行一定要放在exec /usr/local/bin/startkde之前
leo# cat /root/.xinitrc
exec scim -d &
exec /usr/local/bin/startkde

重新启动KDE就可以输入中文了。

简要安装FreeBSD 6.2及配置桌面环境

由 晨笛 — 分类目录: Unix评论暂缺

这里的安装过程其实也很简单,在这里我不打算讲解虚拟机 vmware 上的安装(因为和实际的环境相差不大。同时,这个安装假定你的机器为没有任何操作系统的裸机且您只打算在这个机器上安装一个单一的 FreeBSD 系统。(有关多系统共存的安装方式,请自行参阅 handbook 的相关章节)。

下面转入正题:

1、翻阅你的 handbook 手册,查看你的机器是否适合安装 FreeBSD。
2、将 FreeBSD-Install 光盘放入你的机器的光驱中,启动电源,在光盘启动FreeBSD的启动菜单中按 1 进入安装,此时系统会进入 “Country Selection”选择菜单。
我们在其中选择“45 China”
在 “System Console Keymap”中选“USA ISO”(US ISO keymap)。
接下来就进入系统安装主菜单(sysinstall Main Menu),FreeBSD的安装配置全部可以在这里设置,使用上下箭头移动到不同的选项:
Usage
Standard
Express
Custom
Configure
Doc
Keymap
Options
Fixit
Upgrade
Load Config
Index
在这里按下空格或者回车可进入相应的菜单选项。。
这里我选择Custom,自定义安装,进入 Custom 菜单:
“1 Exit” // 退出并返回到上一级菜单状态
“2 Options” //“View/Set various installation options查看/设置安装选项”
“3 Partition” //“Allocate disk space for FreeBSD分配系统分区”
“4 Label” //“Label allocated disk partitions设置系统分区”
“5 Distributions” //“Select distribution(s) to extract选择安装内容”
“6 Media” //“Choose the installation media type选择安装界质”
“7 Commit” //“Perform any pending Partition/Label/Extract actions 所有安装选项设置完毕,提交您的安装过程”

①选择“3 Partition分配系统分区”了:这是FreeBSD的“FDISK Partition Editor”
这里会进入一个磁盘分区创建的界面,对于新手而言,我强烈建议使用 “A” 选项,让系统自动为你创建分区。然后选择 “Q”退出 分配系统分区界面。在退出分配系统分区的时候,系统会提示你是否创建多系统引导(可能是这个意思)的一个提问,并提供了三个选项。
在“Install Boot Manager for drive ad0?”中安装BootMgr:
还有一选项“BootMgr”即“Install the FreeBSD Boot Manager”把FreeBSD做为启动管理器了。
如果想安装到MBR可以选“Standard”即“Install a standard MBR (no boot manager)”(不推荐)
如果已经有启动管理器可以选“None”即“Leave the Master Boot Record untouched”

②建好分区之后回到“Choose Custom Installation Options自定义安装选项菜单”,选“4 Lable”接着设置系统分区:来到“FreeBSD Disklabel Editor”,看到高亮的是刚刚建立的分区,如果看不到,那返回上一步继续设置一般选择A auto DEfaults即可,让FreeBSD自动设置,新手就选自动吧,Q保存。创建完成后,一个可能的磁盘分区信息如下(这是某个前人的磁盘分区情况,我借鉴过来了)。
Part Mount Size Newfs Part
ad0s2a / 512MB UFS2 Y
ad0s2b swap 166MB SWAP
ad0s2d /var 1107MB UFS2+S Y
ad0s2e /tmp 512MB UFS2+S Y
ad0s2f /usr 2698MB UFS2+S Y

③ 选择“5 Distributions”,安装FreeBSD的内容:
选择菜单,有很多选项
Exit、
All、
Reset、
4 Developer、
5 X-Developer、
6 Kern-Developer、
7 X-Kern-Developer、
8 User、
9 X-User、
A Minimal、
B Custom
使用上下箭头移动到不同的选项,按下空格或者回车选择,如果要启动X,建议一定要把Xorg选中并完全安装。在这里,我建议选择“A Minimal”最小化安装,然后返回“Choose Custom Installation Options”。如果选择“B Custom”选项,可以选ALL,回车,会有一个弹出框,选择YES,安装Ports(建议一定要安装)。
然后选择 Exit ,退出,回到上一级菜单。
④ 选6 ,进入安装介质选择,在这里,我们当然选择 CD-ROM 。

⑤ 现在,我们来选择 2 Options, 来看看我们刚才的设定,如果没有问题,我们就要开始进入实际的安装过程了。退出来,返回上级菜单。
⑥ 选“7 Commit”按OK。系统会出现提示“User confirmation Requested”对话框确认是否开始安装过程(这是最后的一次机会),如果担心有什么地方有错误,可以选“No”回头重新设置。如果没有问题,选“yes”开始安装吧。
接下来就是安装过程了。安装完后会提示你是否需要进入配置菜单改变其他设置(Visit the general configuration menu for a chance to set any last options?),选择默认的“No”完成安装过程。
选“X Exit”Exit this menu (returning to previous),回到“sysinstall main Menu ”安装主菜单。
最后,在“sysinstall Main Menu”中选“[X ExitInstall]” -> “Yes”(Are you sure you wish to exit? The system will reboot (be sure to remove any floppies/CDs/DVDs from the drives). 确认退出并重新启动)。

经过上面的步骤,我们已经安装了一个最小化的系统,但这个系统离我们的要求还相距甚远,别着急,我们接着来。
重新启动系统,如果前面安装了“BootMgr”,则重启的时候会有一个启动菜单,在这里,由于我们仅仅只有一个 FreeBSD 系统,系统会显示:
F1 FreeBSD
不管它,一会儿,系统会自动启动。启动后,freeBSD就展现在你眼前了啦,等待一会,就会出现Login提示符,输入root,回车,熟悉的#号又出现在你的面前了(因为安装时没有设置密码)。
下面,我们就开始安装图形界面,本例以 Gnome 为例,KDE 的安装与此相差不大,略去。
在命令行需要入 sysinstall,是不是又到了我们熟悉的菜单了。^_^.
选择 Configure,进入 Configure 配置菜单。
X Exit
Distributions
Packages
Root Password
Fdisk
Label
User Management
Console
Time Zone
Media
Mouse
Networking
Security
Startup
TTYs
Options
HTML Docs
Load KLD

下面,我们开始进行一些 FreeBSD 的基本配置。
①首先,Supper User 的空密码是不安全的,我们选择 Root Passward(更改ROOT密码,一定要改!)
②设定时区(Time Zone):会询问你是否属于UTC时间(格林威治时间),对于绝大部分人来说,当然选NO了,既然不是UTC时间,那系统就会让你自己选择,选择大区域,当然是5亚洲Asia,接下来选择时间区了,9是中国,然后是选1北京时间east China了,回车,接下来系统再次询问,是否属于该时区,选(Yes)。
③鼠标的设定(Mouse) :一般选择“2 Enable”,系统会自动找到鼠标的。
④进入“Networking”(选项有:
X Exit“Exit this menu (returning to previous)”、
Interfaces“Configure additional network interfaces”、
AMD“This machinewants to run the auto-mounter service”、
AMD Flags“Set flags to AMD service (if enabled)”、
Anon FTP“This machine wishes to allow anonymous FTP”、
Gateway“This machine will route packets between interfaces”、
inetd“This machine wants to run the inet daemon”、
Mail“This machine wants to run a Mail Transfer Agent”、
NFS client“This machine will be an NFS client”、
NFS server“This machine will be an NFS server”、
Ntpdate“Select a clock-synchronization server”、
PCNFSD“Run authentication server for clients with PC-NFS.”、
rpcbind“RPC port mapping daemon (formerly portmapper)”、
rpc.statd“NFS status monitoring daemon”、
rpc.lockd“NFS file locking daemon”、
Routed“Select routing daemon (default: routed)”、
Rwhod“This machine wants to run the rwho daemon”、
sshd“This machine wants to run the SSH daemon”、
TCP Extensions“Allow RFC1323 and RFC1644 TCP extensions?”)。
-> Interfaces (网卡设定) -> (开始网卡设定之前,系统会将现有的可能通讯接口列出。通常,你的网卡会是第一个位置,网卡的型号会因为网卡不同而有改变)。
a.请选择该网卡(lnc0 Lance/PCnet (Isolan/Novell NE2100/NE32-VL) ethernet);
b.是否采用IPv6 (选择“No”) ;
c.是否采用DHCP(动态DNS) ,如果你使用 ADSL 拨号上网,这里选择 DHCP Clent ,这也是我的选择。
d.然后分别进入一个 Host 、domain、IPv4 Gateway、Name server、IPv4 Address、Netmask 等要求输入相关信息的界面,由于我们使用的 DHCP ,这里什么也不填。
e.显示“Would you like to bring the lnc0 interface up right now?”时选“Yes”。
选择“X Exit”退出到“FreeBSD Configuration Menu”配置菜单。

下面进入到 Xorg 的安装与配置(root权限配置)
1.安装Xorg
(1)通过FreeBSD光盘安装(推荐)
在 sysinstall MainMenu 主菜单下选择: -> Configure -> Distributions
进入 Distributions 菜单,这里面有如下选项:
X Exit“Exit this menu (returning to previous)”、
All“All system sources, Binaries and X Window System”、
Reset“Reset all of the below”、
base“Binary base distribution (required)”、
kernels“Binary kernel distributions (required)”、
dict“Spelling checker dictionary files”、
doc“Miscellaneous FreeBSD online docs”、
games“Games (non-commercial)”、
info“GNU info files”、
man“System manual pages – recommended”、
catman“Preformatted system manual pages”、
proflibs“Profiled versions of the libraries”、 src“Sources for everything”、
ports“The FreeBSD Ports collection”、
local“Local additions collection”、
X.Org“The X.Org distribution”)
我们选择 X.Org ,进入到 X.org 的菜单选项,在这其中,我们把 Basic、Server和Fonts 中的内容全选,然后 “OK”确认退出。
选择 ports 。(强烈建议安装上这个,FreeBSD 的有很多软件包都是通过 porst 服务器发布的,在以后你对 FreeBSD 熟悉后,你会需要安装很多的软件包,这个时候,你会觉得在这里选择安装了 ports 软件包,真的是一个英明的举动)。
最后 “OK”确认, 从“Distributions”退回“Configuration”过程中会安装刚才选中的软件包。

(2)编译安装
# cd /usr/ports/x11/xorg
# make install clean

(3)从Package安装
# pkg_add -r xorg

安装完成后,我们再 Exit 到 sysinstall -> X Exit Install。
好了,累了,我们 reboot 一下。

现在,我们再次进入系统了吗?

好了,现在,我们开始宽带接入的 ADSL 拨号配置:
(1)编辑 /etc/ppp/ppp.conf
default:
set log Phase tun command
adsl:
set device PPPoE:rl0
set authname 宽带帐号
set authkey 宽带密码
set dial
set login
add default HISADDR
enable dns
(2)拔号 # ppp -ddial adsl
(3)开机自动联网
配置 /etc/rc.conf,增加如下内容:
#Auto dial ADSL at startup
ppp_enable=”YES”
ppp_mode=”ddial”
ppp_nat=”YES”
ppp_profile=”adsl”

下一步,我们配置 xorg.conf 文件,这个文件决定了你的桌面的分辨率、刷新率、鼠标等性能。
跟我来,配置Xorg :

(1)在/root中生成xorg.conf.new
# Xorg -configure
这个过程在你的 root 用户的根目录下生成一个基本的 Xorg 的配置文件 xorg.conf.new

(2)测试配置文件,以确认Xorg能够和系统上的显卡正常工作
# Xorg -config xorg.conf.new
如果能显示黑灰的格子和”X”鼠标指针,说明配置成功,Ctrl+Alt+Backspace键退出测试界面。如果配置不成功也没关系,按照下面的说明对xorg.conf.new进行调整。
(3)调整xorg.conf.new文件并测试:
①设置显示器刷新率,加入到xorg.conf.new的”Monitor”小节中:
Section “Monitor”
Identifier “Monitor0″
VendorName “Monitor Vendor”
ModelName “Monitor Model”
Horizsync 31.5-99.0 #根据自己显示器情况而定
VertRefresh 50.0-90.0 #根据自己显示器情况而定
EndSection

②设置显示器分辨率及色深,修改xorg.conf.new的”Screen”小节。

Section “Screen”
Identifier “Screen0″
Device “Card0″
Monitor “Monitor0″
DefaultDepth 24 #根据自己显示器情况而定,可小到8,下同
SubSection “Display”
Viewport 0 0
Depth 24 #根据自己显示器情况而定
Modes “800×600″ #根据自己显示器情况而定
EndSubSection
EndSection

③鼠标中键滚轮支持
在6.0之前该选项要自己设置,6.1中,如果使用Xorg -configure生成xorg.conf.new,那么该功能不需要自己配置,否则请修改xorg.conf.new中的”InputDevice”小节。

Section “InputDevice”
Identifier “Mouse0″
Driver “mouse”
Option “rotocol” “auto”
Option “Device” “/dev/sysmouse”
Option “ZAxisMapping” “4 5 6 7″ #没有这一行请手动加上
EndSection

配置修改存盘后再进行测试,如没问题将xorg.conf.new更名为xorg.conf后拷到以下目录“/etc/X11/”:
# cp xorg.conf.new /etc/X11/xorg.conf
如仍有问题可查看/var/log/xorg.0.log 然后根据提示修改。
注意:如果是在虚拟机 vmware 5.x 上安装,那么你的系统的配置文件可能是如下内容(这个是经过我反复测试成功后的配置文件

下面进入到了最激动人心的过程—>桌面环境的安装配置(Gnome2.6.12) (root权限配置)

1.Gnome安装
再次输入 sysinstall 进入 sysinstall Main Menu 安装主菜单。
sysinstall -> Configure -> Packages -> 1 CD/DVD -> gnome -> 选择“gnome2-2.6.12”时其它选项自动关联(仅剩“xchat2-2.6.1_1”项也可选上) -> 按Tab键选OK再回车返回“Package Selection”
然后选择 “linux”,把 linux basic 包也装上(以后,有很多的 linux 应用软件需要这个包的支持)。
在“Package Selection”窗口按Tab键选“Install”开始安装软件包。
从“Distributions”退回“Configuration”过程中会安装刚才选中的软件包,此时安装时间较长,最后回到“FreeBSD configuration Menu” -> 最后退出sysinstall。

2.配置 gnome 的启动文件。
vi .xinitrc
在其中的最后一行加入
“exec /usr/local/bin/gnome-session”
(注意,如果你使用KDE,则加入”exec /usr/local/bin/startkde”)

3.startx 即可启动桌面,但此时的Gnome是英文的。

4.中文本地化设置。
(1)在/etc/login.conf中最后,加入以下部分
#
#Chinese Users Accounts.
#
chinese|Chinese Users Accounts:\
:charset=eucCN:\
:lang=zh_CN.eucCN:\
:tc=default:

(2)执行以下命令
#cap_mkdb /etc/login.conf

(3)用vipw修改登入类型,针对相应用用户进行修改,修改格式参照如下内容:
root1$lOOD78Dm$oSG5u21RGrXoC.TTJ3nCs.:0:0:chinese:0:0:Charlie &:/root:/bin/csh
关键是在相应位置加入”chinese”,”chinese”是和第1步的设置对应的。
保存退出。

(4)重新登入后执行startx,进入的Gnome便是全中文的了。
—————————————————————————————-
下面,我们将使用Windows下的Simsun字体进行中文字体美化
在 /usr/X11R6/lib/X11/fonts/下建立一个”TrueType”目录,将Windows下的simsun.ttc改名为simsun.ttf后拷贝到 /usr/X11R6/lib/X11/fonts/TrueType下重建字体缓存 fc-cache -fv
然后在GNOME中设置字体,在字体细节中调整:“平滑”选无,“微调”选轻微,“次象素顺序”选RGB。

最后设置在开机即进入图形登录界面登录 (这里我选择的是 GDM 方式)
修改/etc/rc.conf,加入以下内容
gdm_enable=”YES”
经过以上设置应该就有了一个漂亮的中文桌面系统了。

经过以上设置,我们就可以了吗???还不行,我们还要加入中文输入法,在这里,我选择了 scim 输入法。

在 scim 输入法安装之前,我们还得做一个工作:把我们的安装软件所需要申请 ports 服务的服务器指向最快的那些 ports 服务器,否则,你的安装过程将无法忍受。

修改 /etc/make.conf 文件,在其中的最后部分加入如下语句:

MASTER_SITE_OVERRIDE= \
ftp://ftp.tw.FreeBSD.org/pub/FreeBSD/ports/distfiles/${DIST_SUBDIR} \
ftp://ftp4.tw.FreeBSD.org/pub/FreeBSD/ports/distfiles/${DIST_SUBDIR} \
ftp://ftp10.tw.FreeBSD.org/pub/FreeBSD/ports/distfiles/${DIST_SUBDIR} \
ftp://ftp13.tw.FreeBSD.org/pub/FreeBSD/ports/distfiles/${DIST_SUBDIR} \
ftp://ftp.jp.FreeBSD.org/pub/FreeBSD/ports/distfiles/${DIST_SUBDIR} \
ftp://ftp3.jp.FreeBSD.org/pub/FreeBSD/ports/distfiles/${DIST_SUBDIR} \
ftp://ftp5.jp.FreeBSD.org/pub/FreeBSD/ports/distfiles/${DIST_SUBDIR} \
ftp://ftp.jaist.ac.jp/pub/FreeBSD/ports/distfiles/${DIST_SUBDIR} \
ftp://ftp.freebsdchina.org/pub/FreeBSD/ports/distfiles/${DIST_SUBDIR}

(以上的 ports 服务器地址是我从论坛中搜索来的,感谢前面的大牛无私的奉献)

下面开始我们的 scim 输入法的安装配置 (root权限配置)
(1)SCIM安装
安装拼音输入法
# cd /usr/ports/chinese/scim-pinyin
# make install clean
安装五笔输入法
# /usr/ports/chinese/scim-tables
# make insall clean

(2)scim 输入法的环境变量配置
①查看当前的locale设置:
locale
②查看你使用的shell:
echo $0 或 cat /etc/passwd
③如果使用的Shell是bash或sh:
请编辑 ~/.profile 文件,在其中的最后,输入如下参数:
export LANG=zh_CN.eucCN
export LC_CTYPE=zh_CN.eucCN
export XMODIFIERS=’@im=scim’
export GTK_IM_MODULE=scim

④如果使用的Shell是csh或tcsh:
请编辑 ~/.cshrc 文件,在其中加入如下参数:
setenv LANG zh_CN.eucCN
setenv LC_CTYPE zh_CN.eucCN
setenv XMODIFIERS @im=scim
setenv GTK_IM_MODULE scim

(3)在~/.xinitrc中的 exec /usr/local/bin/gnome-session 行之前加入如下语句:

execl /usr/local/bin/scim -d &

(注意:如果在X下操作,记得重启X。简单一点按Ctrl+Alt+BackSpace
如果您使用了 gdm ,在系统启动时直接进入到图形界面状态下,那么请注意,gdm 并不会读取 .xinitrc 文件的内容,此时请注意修改 ~/.profile 文件,在其中加入如下内容:
export LANG=zh_CN.eucCN
export LC_CTYPE=zh_CN.eucCN
export XMODIFIERS=’@im=scim’
export GTK_IM_MODULE=scim
)。

下面,我们开始安装声卡的驱动
最简单的方式就是修改/boot/defaults/loader.conf文件中的“Sound modules”部分,把相应声卡的驱动Load上即可,但为了修改,我们首先必须知道自己的声卡类型,有难度吗?别急,跟我来。
首先执行:
kldload snd_driver
#这是个 meta 驱动,一次加载了最常见的设备驱动。 这会提高搜索正确驱动的速度。
然后dmesg | grep pcm

pcm0: ; port 0xe000-0xe03f,0xdc00-0xdcff irq 11 at device 31.5 on pci0
pcm0: ;

声卡的状态可以通过 /dev/sndstat 文件来查询:

# cat /dev/sndstat
FreeBSD Audio Driver (newpcm)
Installed devices:
pcm0: ; at io 0xdc00, 0xe000 irq 11 bufsz 16384 kld snd_ich (1p/1r/0v channels duplex default)

说明该声卡的类型为:snd_ich

#vi /boot/defaults/loader.conf
修改:snd_ich_load=”NO” #intel Tch 这一行,
改成:snd_ich_load=”YES” #intel Tch

例如,我的声卡在执行 # cat /dev/sndstat 后,显示为 snd_es173x
则找到 /boot/defaults/loader.conf 文件中的 ##############################################################
### Sound modules ##########################################
##############################################################
小节,在这个小节中,有一个 snd_es173x_load = “NO” ,修改成 snd_es173x_load = “YES”
(注意:如果在声卡驱动的这个小节,没有发现你的声卡类型,也可以手工自己加入一行,内容为
你的声卡类型_load = “YES” )

下面,我们已经基本可以使用了,但这样就满足了吗?不行,我们接着来。
接着我们要在控制台下实现中文化。
进入 /usr/ports/chinese/cce 目录,在其下输入 make install clean 命令进行安装。
安装完成后,在 .cshrc 文件中设置如下内容:
alias vi ‘env LC_CTYPE=en_US.ISO8859-1 vi’
(这个定义是为了我们在使用 vi 时能正确输入和识别中文。)
setenv LANG zh_CN.eucCN
setenv LC_CTYPE zh_CN.eucCN

当需要使用汉字环境的时候,输入 cce 启动汉字环境。退出汉字环境时请输入 exit 。

下面,我们该开始 Gaim 及时通讯工具的安装的安装了。
进入 /usr/ports/net-im/gaim-openq 目录,在其目录下输入 make install clean 进行安装。

有人会说了,Gaim 不能使用了,腾讯已经把登录服务器的协议改了, Gaim 登录不进去了,别担心,我们得感谢 FreeBSD ,他们及时给我们提供了 openq-2006 的补丁插件。

http://www.linuxdiyf.com/viewarticle.php?id=43700

页数: 上一页 1 2 3 4 5 6 7 8 下一页
© 2010 晨笛的博客 All rights reserved - Wallow theme by TwoBeers Crew - Powered by WordPress - 使用愉快!