(新手求助)請問ubuntu終端機文字模式下 ls --help 顯示的幫助提示可以改中文嘛? [論壇 - Ubuntu基本設定]


正在瀏覽:   1 名遊客


 到底部   前一個主題   下一個主題  [無發表權] 請登錄或者註冊



(新手求助)請問ubuntu終端機文字模式下 ls --help 顯示的幫助提示可以改中文嘛?
會員一級
註冊日期:
8/10 23:17:05
所屬群組:
已註冊使用者
等級: 1
HP : 0 / 0
MP : 0 / 0
EXP: 0
離線
ls --help有些部份可以顯示中文 可以把英文提示全部改成中文提示嘛?
我找了很久 >< 請求幫助!

附件:



png  2017-09-19 05-35-47 的螢幕擷圖.png (261.67 KB)
49788_59c043c32192b.png 1600X900 px

9/19 6:03:15
應用擴展 工具箱
回覆: (新手求助)請問ubuntu終端機文字模式下 ls --help 顯示的幫助提示可以改中文嘛?
會員二級
註冊日期:
2013/8/12 9:20
所屬群組:
已註冊使用者
等級: 7
HP : 0 / 167
MP : 25 / 2132
EXP: 71
離線
這個的話......,就是官方收錄的中文翻譯還沒翻完,所以就這樣囉 :P

9/19 6:43:38
應用擴展 工具箱
回覆: (新手求助)請問ubuntu終端機文字模式下 ls --help 顯示的幫助提示可以改中文嘛?
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 33
HP : 161 / 806
MP : 508 / 13318
EXP: 24
離線
最近的一篇討論回覆「回覆: ubuntun 14.04, psql 無法使用 [#4] [#5] [#6]」,
裡面有紀錄跟這個議題相關的探索,可以一併參考。

以下測試環境「Xubuntu 16.04 amd64 英文界面」

================================================================================

執行


$ cat /etc/default/locale



顯示


# File generated by update-locale
LANG="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"



執行


$ locale



顯示


LANG=en_US.UTF-8
LANGUAGE=en_US
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=en_US.UTF-8
LC_TIME=en_US.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=en_US.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8
LC_ALL=


執行


$ LANGUAGE=zh_TW locale



顯示


LANG=en_US.UTF-8
LANGUAGE=zh_TW
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=en_US.UTF-8
LC_TIME=en_US.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=en_US.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8
LC_ALL=



================================================================================

執行


$ LANGUAGE=zh_TW ls --help



顯示


用法:ls [選項]... [檔案]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all                  do not ignore entries starting with .
  -A, --almost-all           do not list implied . and ..
      --author               with -l, print the author of each file
  -b, --escape               print C-style escapes for nongraphic characters
      --block-size=SIZE      scale sizes by SIZE before printing them; e.g.,
                               '--block-size=M' prints sizes in units of
                               1,048,576 bytes; see SIZE format below
  -B, --ignore-backups       do not list implied entries ending with ~
  -c                         with -lt: sort by, and show, ctime (time of last
                               modification of file status information);
                               with -l: show ctime and sort by name;
                               otherwise: sort by ctime, newest first
  -C                         list entries by columns
      --color[=WHEN]         colorize the output; WHEN can be 'always' (default
                               if omitted), 'auto', or 'never'; more info below
  -d, --directory            list directories themselves, not their contents
  -D, --dired                generate output designed for Emacs' dired mode
  -f                         do not sort, enable -aU, disable -ls --color
  -F, --classify             append indicator (one of */=>@|) to entries
      --file-type            likewise, except do not append '*'
      --format=WORD          across -x, commas -m, horizontal -x, long -l,
                               single-column -1, verbose -l, vertical -C
      --full-time            like -l --time-style=full-iso
  -g                         like -l, but do not list owner
      --group-directories-first
                             group directories before files;
                               can be augmented with a --sort option, but any
                               use of --sort=none (-U) disables grouping
  -G, --no-group             in a long listing, don't print group names
  -h, --human-readable       with -l and/or -s, print human readable sizes
                               (e.g., 1K 234M 2G)
      --si                   likewise, but use powers of 1000 not 1024
  -H, --dereference-command-line
                             follow symbolic links listed on the command line
      --dereference-command-line-symlink-to-dir
                             follow each command line symbolic link
                               that points to a directory
      --hide=PATTERN         do not list implied entries matching shell PATTERN
                               (overridden by -a or -A)
      --indicator-style=WORD  append indicator with style WORD to entry names:
                               none (default), slash (-p),
                               file-type (--file-type), classify (-F)
  -i, --inode                print the index number of each file
  -I, --ignore=PATTERN       do not list implied entries matching shell PATTERN
  -k, --kibibytes            default to 1024-byte blocks for disk usage
  -l                         使用較長格式列出資訊
  -L, --dereference          當顯示符號鏈結的檔案資訊時,顯示符號鏈結所指示
                               的目標而並非符號鏈結本身的資訊
  -m                         所有項目以逗號分隔,並填滿整行行寬
  -n, --numeric-uid-gid      like -l, but list numeric user and group IDs
  -N, --literal              print raw entry names (don't treat e.g. control
                               characters specially)
  -o                         like -l, but do not list group information
  -p, --indicator-style=slash
                             append / indicator to directories
  -q, --hide-control-chars   print ? instead of nongraphic characters
      --show-control-chars   show nongraphic characters as-is (the default,
                               unless program is 'ls' and output is a terminal)
  -Q, --quote-name           enclose entry names in double quotes
      --quoting-style=WORD   use quoting style WORD for entry names:
                               literal, locale, shell, shell-always,
                               shell-escape, shell-escape-always, c, escape
  -r, --reverse              reverse order while sorting
  -R, --recursive            list subdirectories recursively
  -s, --size                 print the allocated size of each file, in blocks
  -S                         sort by file size, largest first
      --sort=WORD            sort by WORD instead of name: none (-U), size (-S),
                               time (-t), version (-v), extension (-X)
      --time=WORD            with -l, show time as WORD instead of default
                               modification time: atime or access or use (-u);
                               ctime or status (-c); also use specified time
                               as sort key if --sort=time (newest first)
      --time-style=STYLE     with -l, show times using style STYLE:
                               full-iso, long-iso, iso, locale, or +FORMAT;
                               FORMAT is interpreted like in 'date'; if FORMAT
                               is FORMAT1<newline>FORMAT2, then FORMAT1 applies
                               to non-recent files and FORMAT2 to recent files;
                               if STYLE is prefixed with 'posix-', STYLE
                               takes effect only outside the POSIX locale
  -t                         sort by modification time, newest first
  -T, --tabsize=COLS         assume tab stops at each COLS instead of 8
  -u                         with -lt: sort by, and show, access time;
                               with -l: show access time and sort by name;
                               otherwise: sort by access time, newest first
  -U                         do not sort; list entries in directory order
  -v                         natural sort of (version) numbers within text
  -w, --width=COLS           set output width to COLS.  0 means no limit
  -x                         list entries by lines instead of by columns
  -X                         sort alphabetically by entry extension
  -Z, --context              print any security context of each file
  -1                         list one file per line.  Avoid '\n' with -q or -b
      --help     顯示此求助說明並離開
      --version  顯示版本資訊並離開

The SIZE argument is an integer and optional unit (example: 10K is 10*1024).
Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).

Using color to distinguish file types is disabled both by default and
with --color=never.  With --color=auto, ls emits color codes only when
standard output is connected to a terminal.  The LS_COLORS environment
variable can change the settings.  Use the dircolors command to set it.

Exit status:
 0  if OK,
 1  if minor problems (e.g., cannot access subdirectory),
 2  if serious trouble (e.g., cannot access command-line argument).

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Full documentation at: <http://www.gnu.org/software/coreutils/ls>
or available locally via: info '(coreutils) ls invocation'



================================================================================

執行


$ whereis ls



顯示


ls: /bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1/ls.1posix.gz



執行


$ dpkg -S /bin/ls



顯示


coreutils: /bin/ls



表示「/bin/ls」這個檔案,是屬於「coreutils」這個套件。


執行


$ apt-file search coreutils.mo | grep zh_TW



顯示


language-pack-zh-hant-base: /usr/share/locale-langpack/zh_TW/LC_MESSAGES/coreutils.mo
policycoreutils: /usr/share/locale/zh_TW.Big5/LC_MESSAGES/policycoreutils.mo
policycoreutils: /usr/share/locale/zh_TW/LC_MESSAGES/policycoreutils.mo



表示「/usr/share/locale-langpack/zh_TW/LC_MESSAGES/coreutils.mo」這個檔案,是屬於「language-pack-zh-hant-base」這個套件

================================================================================

執行


$ grep '使用較長格式列出資訊' /usr/share/locale-langpack/* -R



顯示


Binary file /usr/share/locale-langpack/zh_TW/LC_MESSAGES/coreutils.mo matches



================================================================================

執行下面指令,下載「language-pack-zh-hant-base」這個套件的「Source Package: language-pack-zh-hant-base」。


$ apt-get source language-pack-zh-hant-base



會下載兩個檔案

* language-pack-zh-hant-base_16.04+20160627.dsc
* language-pack-zh-hant-base_16.04+20160627.tar.gz

並且解開到資料夾「language-pack-zh-hant-base-16.04+20160627」


然後執行


$ find language-pack-zh-hant-base-16.04+20160627 -name coreutils.po



顯示


language-pack-zh-hant-base-16.04+20160627/data/zh_TW/LC_MESSAGES/coreutils.po
language-pack-zh-hant-base-16.04+20160627/data/zh_HK/LC_MESSAGES/coreutils.po



執行


$ grep '使用較長格式列出資訊' language-pack-zh-hant-base-16.04+20160627/data/zh_TW/LC_MESSAGES/coreutils.po -n -A 4 -B 10



顯示


4993-
4994-#: src/ls.c:4795
4995-msgid ""
4996-"  -l                         use a long listing format\n"
4997-"  -L, --dereference          when showing file information for a symbolic\n"
4998-"                               link, show information for the file the link\n"
4999-"                               references rather than for the link itself\n"
5000-"  -m                         fill width with a comma separated list of "
5001-"entries\n"
5002-msgstr ""
5003:"  -l                         使用較長格式列出資訊\n"
5004-"  -L, --dereference          當顯示符號鏈結的檔案資訊時,顯示符號鏈結所指示\n"
5005-"                               的目標而並非符號鏈結本身的資訊\n"
5006-"




================================================================================

執行下面指令,產生一個測試資料夾


$ mkdir -p test



切換到「test」這個資料夾


$ cd test



執行下面指令,複製「coreutils.po」來測試


$ cp ../language-pack-zh-hant-base-16.04+20160627/data/zh_TW/LC_MESSAGES/coreutils.po ./



執行


$ ls



顯示


coreutils.po



執行


$ grep 'but do not list owner' coreutils.po -n -A 2 -B 2



顯示


4947-
4948-#: src/ls.c:4760
4949:msgid "  -g                         like -l, but do not list owner\n"
4950-msgstr ""
4951-




請使用您慣用的編輯器,修改「coreutils.po」這個檔案的第「4950」行
或是也可以透過「poedit」來編輯。

原本是


msgstr ""



改成


msgstr "  -g                         類似 -l, 不過不顯示擁有者欄位\n"



然後執行下面指令,產生「coreutils.mo」


$ msgfmt -o coreutils.mo coreutils.po



就會產生一個檔案「coreutils.mo」

執行下面指令確認


$ ls -1



顯示


coreutils.mo
coreutils.po



執行下面指令,將剛剛產生的「coreutils.mo」複製到「/usr/share/locale-langpack/zh_TW/LC_MESSAGES/coreutils.mo」。


$ sudo cp coreutils.mo /usr/share/locale-langpack/zh_TW/LC_MESSAGES/coreutils.mo



執行下面指令,測試「ls --help 」的顯示結果


$ LANGUAGE=zh_TW ls --help



或是執行


$ LANGUAGE=zh_TW ls --help | grep '類似'



會看到


 -g                         類似 -l, 不過不顯示擁有者欄位



或是執行


$ LANGUAGE=zh_TW gettext -e -d coreutils '  -g                         like -l, but do not list owner\n'



顯示


 -g                         類似 -l, 不過不顯示擁有者欄位



或是執行


$ LANGUAGE=zh_TW TEXTDOMAIN=coreutils gettext -e '  -g                         like -l, but do not list owner\n'



顯示


 -g                         類似 -l, 不過不顯示擁有者欄位




================================================================================

若要復原,只要執行下面的指令,重新安裝「language-pack-zh-hant-base」這個套件就行了。


$ sudo apt-get install language-pack-zh-hant-base --reinstall



================================================================================

上面只是顯示原理給您瞭解,您也可以重新編譯「language-pack-zh-hant-base」的「Source Package
然後在透過「sudo dpkg -i」來安裝編譯好的「Debian Binary Package」。


在剛剛執行完「apt-get source language-pack-zh-hant-base」後,

執行下面指令,切換「language-pack-zh-hant-base-16.04+20160627」這個資料夾


$ cd language-pack-zh-hant-base-16.04+20160627/



執行


$ ls -1



顯示


COPYING
data
debian



執行


$ sudo debian/rules binary



會產生一個檔案「language-pack-zh-hant-base_16.04+20160627_all.deb」。

執行


$ ls ../*.deb



顯示


../language-pack-zh-hant-base_16.04+20160627_all.deb



然後執行下面指令,安裝「language-pack-zh-hant-base_16.04+20160627_all.deb」。


$ sudo dpkg -i ../language-pack-zh-hant-base_16.04+20160627_all.deb



================================================================================

## 相關索引

* [索引] 文件編碼
* [索引] 套件操作實務
* [影片教學][TOSSUG] Debian 套件打包工作坊


## 相關討論

* 回覆: 為什麼要這樣翻譯 - 「#4」,「#10
* 討論這篇「邁向永續的臺灣桌面應用自由軟體在地發展」- 「#1

## Wikipedia

* gettext (中文)

## GNU gettext

* manual

$ info gettext


================================================================================

## Package

* gettext
* gettext-doc
* gettext-base

## Manpage

* man msgfmt

================================================================================

執行下面指令,下載「coreutils」這個套件的「Source Package: coreutils」。


$ apt-get source coreutils



coreutils_8.25-2ubuntu3~16.04.debian.tar.xz
coreutils_8.25-2ubuntu3~16.04.dsc
coreutils_8.25.orig.tar.xz

並且解開到「coreutils-8.25」這個資料夾

執行


$ find coreutils-8.25 -name zh_TW.po



顯示


coreutils-8.25/po/zh_TW.po


執行


$ grep '使用較長格式列出資訊' coreutils-8.25/po/zh_TW.po -n -A 4 -B 10



顯示


5395-
5396-#: src/ls.c:4891
5397-msgid ""
5398-"  -l                         use a long listing format\n"
5399-"  -L, --dereference          when showing file information for a symbolic\n"
5400-"                               link, show information for the file the link\n"
5401-"                               references rather than for the link itself\n"
5402-"  -m                         fill width with a comma separated list of "
5403-"entries\n"
5404-msgstr ""
5405:"  -l                         使用較長格式列出資訊\n"
5406-"  -L, --dereference          當顯示符號鏈結的檔案資訊時,顯示符號鏈結所指示\n"
5407-"                               的目標而並非符號鏈結本身的資訊\n"
5408-"  -m                         所有項目以逗號分隔,並填滿整行行寬\n"
5409-




執行


$ grep 'but do not list owner' coreutils-8.25/po/zh_TW.po -n -A 2 -B 2



顯示


5332-
5333-#: src/ls.c:4856
5334:msgid " -g like -l, but do not list owner\n"
5335-msgstr ""
5336-



另外發現有一個地方有翻譯,但發現該處的「msgid」和「msgstr」有點對不上

執行


$ grep '但不列出擁有者' coreutils-8.25/po/zh_TW.po -n -A 5 -B 14



顯示


5358-
5359-#: src/ls.c:4871
5360-#, fuzzy
5361-msgid ""
5362-"  -H, --dereference-command-line\n"
5363-"                             follow symbolic links listed on the command "
5364-"line\n"
5365-"      --dereference-command-line-symlink-to-dir\n"
5366-"                             follow each command line symbolic link\n"
5367-"                               that points to a directory\n"
5368-"      --hide=PATTERN         do not list implied entries matching shell "
5369-"PATTERN\n"
5370-"                               (overridden by -a or -A)\n"
5371-msgstr ""
5372:"  -g                         類似 -l,但不列出擁有者\n"
5373-"  -G, --no-group             不列出任何有關群組的資訊\n"
5374-"  -h, --human-readable       以容易理解的格式印出檔案大小 (例如 1K 234M 2G)\n"
5375-"      --si                   類似 -h,但取 1000 的次方而不是 1024\n"
5376-"  -H, --dereference-command-line    使用指令列中的符號鏈結指示的真正目的地\n"
5377-



執行


$ grep 'but do not list owner' coreutils-8.25/src/ls.c -n -A 1 -B 1



顯示


4855-      fputs (_("\
4856:  -g                         like -l, but do not list owner\n\
4857-"), stdout);



執行


$ grep 'dereference-command-line-symlink-to-dir' coreutils-8.25/src/ls.c -n -A 6 -B 3



顯示


...略...
--
4870-      fputs (_("\
4871-  -H, --dereference-command-line\n\
4872-                             follow symbolic links listed on the command line\n\
4873:      --dereference-command-line-symlink-to-dir\n\
4874-                             follow each command line symbolic link\n\
4875-                               that points to a directory\n\
4876-      --hide=PATTERN         do not list implied entries matching shell PATTERN\
4877-\n\
4878-                               (overridden by -a or -A)\n\
4879-"), stdout);




================================================================================

## main.c


#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <libintl.h>

#define PACKAGE "coreutils"
#define LOCALEDIR "/usr/share/locale"
#define _(msgid) gettext (msgid)


int main (int argc, char *argv[])
{
	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

	printf("LANGUAGE=%s\n", getenv("LANGUAGE"));

	fputs (_("\
  -g                         like -l, but do not list owner\n\
"), stdout);

	exit(EXIT_SUCCESS);
}




執行下面指令編譯


$ gcc -o demo main.c



執行


$ ./demo



顯示


LANGUAGE=en_US
  -g                         like -l, but do not list owner



執行


$ LANGUAGE=zh_TW ./demo



顯示


LANGUAGE=zh_TW
  -g                         類似 -l, 不過不顯示擁有者欄位




$ man 3 gettext
$ man 3 bindtextdomain
$ man 3 textdomain


上面雖然使用「#define LOCALEDIR "/usr/share/locale"」,
關於「/usr/share/locale-langpack」是從那邊設定的,可以參考「#5 回覆: ubuntun 14.04, psql 無法使用」這篇的探索。

這個範例,則是可以對照「#6 回覆: ubuntun 14.04, psql 無法使用」的「測試十一」來看。

================================================================================

以上提供參考

報告完畢



9/19 10:02:35
應用擴展 工具箱


 [無發表權] 請登錄或者註冊


可以查看帖子.
不可發帖.
不可回覆.
不可編輯自己的帖子.
不可刪除自己的帖子.
不可發起投票調查.
不可在投票調查中投票.
不可上傳附件.
不可不經審核直接發帖.