From 81b017a1185e2fef656a814cda81978ac7968bed Mon Sep 17 00:00:00 2001 From: joyqi Date: Mon, 16 Dec 2013 14:37:33 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E6=88=90pot=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/Makefile | 28 +++++++++-------- tools/list.php | 81 ++++++++++++++------------------------------------ 2 files changed, 38 insertions(+), 71 deletions(-) diff --git a/tools/Makefile b/tools/Makefile index 05c42c50..2dd80fbc 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -2,8 +2,6 @@ #define root directory DIR=../ -TINYMCE=3_2_2 - #update subversion update: @@ -11,8 +9,8 @@ update: rm -Rf build/ git clone https://github.com/typecho/typecho-replica.git build rm -Rf build/.git - rm -Rf build/.gitignore - rm -Rf build/.gitattributes + rm -f build/.gitignore + rm -f build/.gitattributes for i in `find build/ -name '*.css'`; do echo $$i && java -Xmx32m -jar yuicompressor-2.4.2.jar $$i --charset UTF-8 -o $$i; done; for i in `find build/admin/js/ -name '*.js'`; do echo $$i && java -Xmx32m -jar yuicompressor-2.4.2.jar $$i --charset UTF-8 -o $$i; done; for i in `find build/ -name '*.php'`; do php -l $$i; done; @@ -21,10 +19,10 @@ update: package: @echo 'package' rm -Rf build/tools/ - rm -Rf build/todo.txt - rm -Rf build/changelog.txt - rm -Rf build/.travis.yml - rm -Rf build/README.md + rm -f build/todo.txt + rm -f build/changelog.txt + rm -f build/.travis.yml + rm -f build/README.md rm -Rf build/admin/scss rm -Rf build/admin/img/editor rm -Rf build/admin/img/icons @@ -59,10 +57,10 @@ theme: install: make update rm -Rf build/tools/ - rm -Rf build/todo.txt - rm -Rf build/changelog.txt - rm -Rf build/.travis.yml - rm -Rf build/README.md + rm -f build/todo.txt + rm -f build/changelog.txt + rm -f build/.travis.yml + rm -f build/README.md rm -Rf build/admin/scss rm -Rf build/admin/img/editor rm -Rf build/admin/img/icons @@ -73,6 +71,12 @@ install: make clear +pot: + cd ../ && php tools/list.php ./ > tools/files.txt + cd ../ && xgettext --files-from=tools/files.txt -Lphp --from-code=UTF-8 --keyword=_t --keyword=_e --keyword=_n:1,2 --no-location --copyright-holder=Typecho --package-name=Typecho --package-version=`grep -E "VERSION = '(.*)'" ./var/Typecho/Common.php | cut -d "'" -f 2` --no-wrap --output=tools/messages.pot + rm -f files.txt + + all: make update make package diff --git a/tools/list.php b/tools/list.php index dd8fc251..35f7b71c 100644 --- a/tools/list.php +++ b/tools/list.php @@ -6,68 +6,31 @@ if (!isset($argv[1])) { exit(1); } -//获取一个目录下的文件 -function mgGetFile($inpath, $trim = false,$stamp = NULL) -{ - $file = array(); +/** + * 获取所有文件 + * + * @param string $dir + * @param string $pattern + * @return array + */ +function all_files($dir, $pattern = '*') { + $result = array(); - if(!is_dir($inpath)) - { - return $file; - } + $items = glob($dir . '/' . $pattern, GLOB_BRACE); + foreach ($items as $item) { + if (is_file($item)) { + $result[] = $item; + } + } - $handle=opendir($inpath); - if(NULL != $stamp) - { - $stamp = explode("|",$stamp); - } - - while ($tmp = readdir($handle)) - { - if(file_exists($inpath."/".$tmp) && eregi("^([_@0-9a-zA-Z\x80-\xff\^\.\%-]{0,})[\.]([0-9a-zA-Z]{1,})$",$tmp,$file_name)) - { - if($stamp != NULL && in_array($file_name[2],$stamp)) - { - $file[] = $trim ? $file_name[0] : $file_name[1]; - } - else if($stamp == NULL) - { - $file[] = $trim ? $file_name[0] : $file_name[1]; - } - } - } - closedir($handle); - return $file; -} - -//获取一个目录下的目录 -function mgGetDir($inpath) -{ - $handle=opendir($inpath); - $dir = array(); - while ($tmp = readdir($handle)) - { - if(is_dir($inpath."/".$tmp) && $tmp != ".." && $tmp != "." && 0 !== stripos($tmp,'.')) - { - $dir[] = $tmp; - } - } - closedir($handle); - return $dir; -} - -function listFile($inpath, $stamp) -{ - $files = mgGetFile($inpath, true, $stamp); - $dirs = mgGetDir($inpath); - - if ($dirs) { - foreach ($dirs as $dir) { - $files = array_merge($files, listFile($dir, $stamp)); + $items = glob($dir . '/*', GLOB_ONLYDIR); + foreach ($items as $item) { + if (is_dir($item)) { + $result = array_merge($result, all_files($item, $pattern)); } } - - return $files; + + return $result; } -echo implode("\n", listFile($argv[1], 'php')); +echo implode("\n", all_files($argv[1], '*.php'));