├── p_td_lable-control
├── 翻譯tpl中的英文.txt
├── 以TXT檔的內容翻譯tpl模板檔案.txt
├── 手動要替換的文字.txt
├── 03.php
├── api_TextTranslate.php
├── 02.php
├── 01_p.php
├── t_nav_nav-tabs.php
├── translate_tw.txt
├── p_td_lable-control.php
├── translate_en.txt
└── zh-TW
│ └── wg24themeoptionpanel.php
├── H9使用GoogleTranslateAPI來做自動化檔案翻譯工具.txt
├── .gitignore
├── _api
├── google
│ ├── 來源位置.txt
│ └── GoogleTranslate.php
└── api_TextTranslate
│ ├── translate_tw.txt
│ ├── api_TextTranslate.php
│ └── translate_en.txt
├── 翻譯後注意事項.txt
├── 自機測試網址.txt
├── README
├── 0304.jpg
├── 0305.jpg
├── 運行抓圖.jpg
├── css
│ ├── dot.gif
│ ├── arrow_ltr.png
│ ├── logo_left.png
│ ├── s_collapseall.png
│ ├── ajax_clock_small.gif
│ ├── show-hint.css
│ ├── lint.css
│ ├── printview.css
│ └── codemirror.css
└── t_translation_googleapi.sql
├── google翻譯API申請網址.txt
├── .vscode
└── tasks.json
├── _inc
├── inc_password_admin.php
├── mysql.inc.php
└── toolsfunction.php
├── 01_test_googlefree.php
├── 01_test_post_googleapi.php
├── config-dist.php
├── _sql
└── t_translation_googleapi.sql
├── 02_tw_del_01a.php
├── README.html
├── index12.php
├── index13.php
├── index14_EN_to_vi.php
├── index5.php
├── index6.php
├── en-gb_com_zh-TW.php
├── index7.php
├── README.md
├── index8.php
├── index9.php
└── index10.php
/p_td_lable-control/翻譯tpl中的英文.txt:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/H9使用GoogleTranslateAPI來做自動化檔案翻譯工具.txt:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/p_td_lable-control/以TXT檔的內容翻譯tpl模板檔案.txt:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | config.php
2 | 01zh-TW/
3 | 01en-gb/
4 | *.rar
--------------------------------------------------------------------------------
/_api/google/來源位置.txt:
--------------------------------------------------------------------------------
1 | https://github.com/statickidz/php-google-translate-free
--------------------------------------------------------------------------------
/翻譯後注意事項.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/suffixbig/PHP-GoogleTranslate/HEAD/翻譯後注意事項.txt
--------------------------------------------------------------------------------
/自機測試網址.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/suffixbig/PHP-GoogleTranslate/HEAD/自機測試網址.txt
--------------------------------------------------------------------------------
/README/0304.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/suffixbig/PHP-GoogleTranslate/HEAD/README/0304.jpg
--------------------------------------------------------------------------------
/README/0305.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/suffixbig/PHP-GoogleTranslate/HEAD/README/0305.jpg
--------------------------------------------------------------------------------
/README/運行抓圖.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/suffixbig/PHP-GoogleTranslate/HEAD/README/運行抓圖.jpg
--------------------------------------------------------------------------------
/README/css/dot.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/suffixbig/PHP-GoogleTranslate/HEAD/README/css/dot.gif
--------------------------------------------------------------------------------
/google翻譯API申請網址.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/suffixbig/PHP-GoogleTranslate/HEAD/google翻譯API申請網址.txt
--------------------------------------------------------------------------------
/README/css/arrow_ltr.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/suffixbig/PHP-GoogleTranslate/HEAD/README/css/arrow_ltr.png
--------------------------------------------------------------------------------
/README/css/logo_left.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/suffixbig/PHP-GoogleTranslate/HEAD/README/css/logo_left.png
--------------------------------------------------------------------------------
/README/css/s_collapseall.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/suffixbig/PHP-GoogleTranslate/HEAD/README/css/s_collapseall.png
--------------------------------------------------------------------------------
/README/css/ajax_clock_small.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/suffixbig/PHP-GoogleTranslate/HEAD/README/css/ajax_clock_small.gif
--------------------------------------------------------------------------------
/p_td_lable-control/手動要替換的文字.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/suffixbig/PHP-GoogleTranslate/HEAD/p_td_lable-control/手動要替換的文字.txt
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.1.0",
3 | "command": "explorer",
4 | "windows": {
5 | "command": "explorer.exe"
6 | },
7 | "args": [
8 | "http://t.test.com/${relativeFile}"
9 | ],
10 | "problemMatchers": []
11 | }
--------------------------------------------------------------------------------
/_inc/inc_password_admin.php:
--------------------------------------------------------------------------------
1 | translate($source, $target, $text);//翻譯 參數1=原文語言代號 參數2=目標語言代號 參數3=輸入文字
16 |
17 | echo $result;
18 |
--------------------------------------------------------------------------------
/README/css/show-hint.css:
--------------------------------------------------------------------------------
1 | .CodeMirror-hints {
2 | position: absolute;
3 | z-index: 10;
4 | overflow: hidden;
5 | list-style: none;
6 |
7 | margin: 0;
8 | padding: 2px;
9 |
10 | -webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
11 | -moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
12 | box-shadow: 2px 3px 5px rgba(0,0,0,.2);
13 | border-radius: 3px;
14 | border: 1px solid silver;
15 |
16 | background: white;
17 | font-size: 90%;
18 | font-family: monospace;
19 |
20 | max-height: 20em;
21 | overflow-y: auto;
22 | }
23 |
24 | .CodeMirror-hint {
25 | margin: 0;
26 | padding: 0 4px;
27 | border-radius: 2px;
28 | max-width: 19em;
29 | overflow: hidden;
30 | white-space: pre;
31 | color: black;
32 | cursor: pointer;
33 | }
34 |
35 | li.CodeMirror-hint-active {
36 | background: #08f;
37 | color: white;
38 | }
39 |
--------------------------------------------------------------------------------
/_api/api_TextTranslate/translate_tw.txt:
--------------------------------------------------------------------------------
1 | 產品盒中最後一個產品顯示為新圖標的數量
2 | 您可以顯示或隱藏主頁3的迷你產品滑塊
3 | 你可以選擇4種類型的店頭風格
4 | 類別模塊產品顯示或隱藏
5 | 首頁中免費退款內容
6 | 首頁中免費退款內容
7 | 主頁來自博客的新聞
8 | 主頁新聞從博客內容
9 | 主頁底部褒獎滑塊
10 | 主頁底部推薦滑塊內容
11 | 你可以選擇3種類型的主頁
12 | 類別頁面側欄
13 | 類別左邊欄橫幅
14 | 類別左側欄橫幅內容
15 | 產品頁面3種類型的佈局
16 | 標題容器Bg顏色
17 | 菜單BG顏色
18 | 菜單框陰影顏色
19 | 菜單邊框顏色
20 | 菜單懸停bg顏色
21 | 原色1
22 | 原色2
23 | 原色3
24 | 原色4
25 | Secendary顏色1
26 | 頁腳Bg顏色
27 | 頁腳標題顏色
28 | 頁腳鍊接顏色
29 | 頁腳鍊接懸停顏色
30 | 頁腳底部bg顏色
31 | 頁腳支持文本顏色
32 | 背景圖像
33 | 選擇一個模式編號
34 | 背景附件
35 | Baackground重複
36 | Backgorund位置
37 | 首頁大滑塊
38 | 首頁大滑塊內容
39 | 首頁大滑塊底部促銷橫幅
40 | 首頁大滑塊底部促銷橫幅內容
41 | 家庭兒童時裝(0-5歲)的旗幟
42 | 家庭兒童時裝(0 - 5年)橫幅內容
43 | 家庭兒童時裝(6-12歲)橫幅
44 | 首頁兒童時裝(6-12歲)內容
45 | 家庭玩具和書籍(0-12 Years)橫幅內容
46 | 家庭玩具和書籍(0-12 Years)橫幅內容
47 | 家特別優惠橫幅
48 | 家特別優惠橫幅內容
49 | 首頁與迷你橫幅大滑塊
50 | 首頁大滑塊底部迷你橫幅內容
51 | 選擇字體來源
52 | 正文字體到系統
53 | 身體字體谷歌
54 | 字體大小
55 | 選擇字體來源
56 | 標題字體到系統
57 | 標題字體谷歌
58 | 文本轉換
59 | 產品標題字體大小
60 | 頁眉字體大小
61 | 左/右邊欄塊標題字體大小
62 | 頁腳標題字體大小
63 | 標題自定義橫幅1
64 | 標題自定義橫幅1
65 | 標題自定義橫幅2
66 | 標題自定義橫幅2
67 | 聯繫信息頁面
68 | Linkedin網址
69 | Maestro網址
70 | 美國運通網址
71 | 產品盒的新文本
72 | 銷售文本為產品箱子
73 | 對比框的銷售文本
74 | Twitter的腳本文本
75 | 頁腳讓我們的文字
76 | 頂級品牌名稱
77 | 最新類別選項卡所有文本
78 | 特色產品標題主頁
79 | 最新產品標題主頁
80 | Best Best Sales產品標題的最佳銷售文本
81 | 家庭迷你專用產品標題的特殊文本
82 | 最高的產品標題
83 | 類別側邊欄標題
84 | 頁腳付款接受文本
--------------------------------------------------------------------------------
/01_test_post_googleapi.php:
--------------------------------------------------------------------------------
1 |
15 |
16 |
17 |
18 |
19 | GOOGLE 一次翻多行測試
20 |
21 |
22 |
23 | GOOGLE 一次翻多行測試
24 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/_api/api_TextTranslate/api_TextTranslate.php:
--------------------------------------------------------------------------------
1 | tw=$tw;
31 | $this->en=$en;
32 | //print_r($en);
33 | }
34 | }
35 |
36 | //取出繁體翻譯
37 | public function get_tw($text)
38 | {
39 | $text=trim($text);
40 | for ($i = 0; $i < count($this->en); $i++) {
41 | $text2 = $this->en[$i];
42 | if ($text == $text2) {
43 | return $this->tw[$i];
44 | }
45 | }
46 |
47 | }
48 | public static function translate($source, $target, $text)
49 | {
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/config-dist.php:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/README/t_translation_googleapi.sql:
--------------------------------------------------------------------------------
1 | -- phpMyAdmin SQL Dump
2 | -- version 4.4.15.7
3 | -- http://www.phpmyadmin.net
4 | --
5 | -- 主機: localhost:3306
6 | -- 產生時間: 2017-12-16 08:50:48
7 | -- 伺服器版本: 5.7.14
8 | -- PHP 版本: 7.0.10
9 |
10 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
11 | SET time_zone = "+00:00";
12 |
13 | --
14 | -- 資料庫: `t_translation_googleapi`
15 | --
16 |
17 | -- --------------------------------------------------------
18 |
19 | --
20 | -- 資料表結構 `oc_t`
21 | --
22 |
23 | CREATE TABLE IF NOT EXISTS `oc_t` (
24 | `t_id` int(10) unsigned NOT NULL COMMENT '主鍵',
25 | `project_name` varchar(30) DEFAULT NULL COMMENT '專案名',
26 | `version` varchar(10) DEFAULT NULL COMMENT '版本號',
27 | `dirname` varchar(100) NOT NULL COMMENT '路徑名稱',
28 | `basename` varchar(30) NOT NULL COMMENT '檔案名稱',
29 | `var` varchar(200) DEFAULT NULL COMMENT '變數名',
30 | `sourcelanguage` varchar(5) NOT NULL COMMENT '來源語言',
31 | `sourcetext` text COMMENT '來源內容',
32 | `targetlanguage` varchar(5) NOT NULL COMMENT '目標語言',
33 | `targettext` text COMMENT '目標內容',
34 | `priority` int(2) unsigned NOT NULL DEFAULT '20' COMMENT '優先度數字越小越大為1的話不可複寫',
35 | `add_date` date NOT NULL COMMENT '資料建立日期'
36 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='翻譯資料表';
37 |
38 | --
39 | -- 已匯出資料表的索引
40 | --
41 |
42 | --
43 | -- 資料表索引 `oc_t`
44 | --
45 | ALTER TABLE `oc_t`
46 | ADD PRIMARY KEY (`t_id`);
47 |
48 | --
49 | -- 在匯出的資料表使用 AUTO_INCREMENT
50 | --
51 |
52 | --
53 | -- 使用資料表 AUTO_INCREMENT `oc_t`
54 | --
55 | ALTER TABLE `oc_t`
56 | MODIFY `t_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主鍵';
--------------------------------------------------------------------------------
/p_td_lable-control/03.php:
--------------------------------------------------------------------------------
1 | ".PHP_EOL;
13 | $file1="wg24themeoptionpanel.tpl";//來源檔案
14 |
15 |
16 | //==========================================================================
17 | //==========================================================================
18 | $file_text=file_get_contents($file1);//開啟檔案
19 |
20 | //===========================================================
21 | require_once('api_TextTranslate.php');//載入自寫文字翻譯
22 | $Translate=new TextTranslate();
23 |
24 | $T[1]=array();
25 | $T[2]=array();
26 |
27 | //翻譯字的英文排成陣列
28 | for($i=0;$ien);$i++){
29 | $v=$Translate->en[$i];
30 | $v=str_replace("(","\(",$v);
31 | $v=str_replace(")","\)",$v);
32 | $T[1][]="@".$v."@";//不能大小寫不管-會改到其他
33 | $T[2][]="";//空格取代為沒有
34 | }
35 |
36 | //print_r($T);exit;
37 | //===========================================================
38 | //修改tpl 檔
39 |
40 | $text=preg_replace($T[1],$T[2], $file_text);//字串替換
41 |
42 | $filename=str_replace(".tpl","_tw.tpl",$file1);//儲存檔名
43 | auto_mkdir($filename);//查路徑目錄在不在,不在就建立目錄
44 |
45 | //抓取之後存檔
46 | if (!$handle = fopen($filename, 'w')) {echo "error open log file";}
47 | if (fwrite($handle, $text) === FALSE) {echo "error write LOG File";}
48 | fclose($handle);//關檔
49 | echo "內容已丟到暫存檔".$filename.$br;
50 |
--------------------------------------------------------------------------------
/p_td_lable-control/api_TextTranslate.php:
--------------------------------------------------------------------------------
1 | tw[]=trim($v);
35 | }
36 | }
37 | for($i=0;$ien[]=trim($v);
41 | }
42 | }
43 | }
44 | }
45 |
46 | //取出繁體翻譯
47 | public function get_tw($text)
48 | {
49 | $text=trim($text);
50 | for ($i = 0; $i < count($this->en); $i++) {
51 | $text2 = $this->en[$i];
52 | if ($text == $text2) {
53 | return $this->tw[$i];
54 | }
55 | }
56 |
57 | }
58 | public static function translate($source, $target, $text)
59 | {
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/p_td_lable-control/02.php:
--------------------------------------------------------------------------------
1 | ".PHP_EOL;
13 | $file2="wg24themeoptionpanel.php";//來源檔案目標檔案
14 |
15 |
16 |
17 | /*說明
18 | //空格取代為沒有-變數名稱中不要有空格()號\號
19 | function t_($text)
20 | //讓空格變整齊以變數長度決定空格數目 參數1變數,參數2最大長度
21 | function tt_($v,$s=53)
22 | */
23 | //===========================================================
24 | require_once('api_TextTranslate.php');//載入自寫文字翻譯
25 | $Translate=new TextTranslate();
26 | //===========================================================
27 | //搞出英文翻譯版
28 | $text="";//起始
29 | $td=$Translate->en;
30 | for($i=0;$iget_tw($v).'\';';//翻譯的文字
54 | $text.="\n";
55 | }
56 |
57 | $filename="./zh-TW/".$file2;
58 | auto_mkdir($filename);//查路徑目錄在不在,不在就建立目錄
59 |
60 |
61 | //抓取之後存檔
62 | if (!$handle = fopen($filename, 'w')) {echo "error open log file";}
63 | if (fwrite($handle, $text) === FALSE) {echo "error write LOG File";}
64 | fclose($handle);//關檔
65 | echo "內容已丟到暫存檔".$filename.$br;
66 |
--------------------------------------------------------------------------------
/_sql/t_translation_googleapi.sql:
--------------------------------------------------------------------------------
1 | -- phpMyAdmin SQL Dump
2 | -- version 4.8.3
3 | -- https://www.phpmyadmin.net/
4 | --
5 | -- 主機: localhost:3306
6 | -- 產生時間: 2019 年 01 月 07 日 19:39
7 | -- 伺服器版本: 5.7.23
8 | -- PHP 版本: 7.2.10
9 |
10 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
11 | SET AUTOCOMMIT = 0;
12 | START TRANSACTION;
13 | SET time_zone = "+00:00";
14 |
15 |
16 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
17 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
18 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
19 | /*!40101 SET NAMES utf8mb4 */;
20 |
21 | --
22 | -- 資料庫: `t_translation_googleapi`
23 | --
24 |
25 | -- --------------------------------------------------------
26 |
27 | --
28 | -- 資料表結構 `oc_t`
29 | --
30 |
31 | CREATE TABLE `oc_t` (
32 | `t_id` int(10) UNSIGNED NOT NULL COMMENT '主鍵',
33 | `project_name` varchar(30) DEFAULT NULL COMMENT '專案名',
34 | `version` varchar(10) DEFAULT NULL COMMENT '版本號',
35 | `dirname` varchar(100) NOT NULL COMMENT '路徑名稱',
36 | `basename` varchar(30) NOT NULL COMMENT '檔案名稱',
37 | `var` varchar(500) DEFAULT NULL COMMENT '變數名',
38 | `sourcelanguage` varchar(5) NOT NULL COMMENT '來源語言',
39 | `sourcetext` text COMMENT '來源內容',
40 | `targetlanguage` varchar(5) NOT NULL COMMENT '目標語言',
41 | `targettext` text COMMENT '目標內容',
42 | `priority` int(2) UNSIGNED NOT NULL DEFAULT '20' COMMENT '優先度數字越小越大為1的話不可複寫',
43 | `add_date` date NOT NULL COMMENT '資料建立日期'
44 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='翻譯資料表';
45 |
46 | --
47 | -- 已匯出資料表的索引
48 | --
49 |
50 | --
51 | -- 資料表索引 `oc_t`
52 | --
53 | ALTER TABLE `oc_t`
54 | ADD PRIMARY KEY (`t_id`);
55 |
56 | --
57 | -- 在匯出的資料表使用 AUTO_INCREMENT
58 | --
59 |
60 | --
61 | -- 使用資料表 AUTO_INCREMENT `oc_t`
62 | --
63 | ALTER TABLE `oc_t`
64 | MODIFY `t_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主鍵';
65 | COMMIT;
66 |
67 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
68 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
69 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
70 |
--------------------------------------------------------------------------------
/_api/api_TextTranslate/translate_en.txt:
--------------------------------------------------------------------------------
1 | How much last produt show for as new icon in product box
2 | You can show or hide mini product slider for home page 3
3 | You can Choose 4 type header style for your shop
4 | Category module product show or hide
5 | Home middle free Money Back content
6 | Home middle free Money Back content
7 | Home News From Blogs
8 | Home News From Blogs content
9 | Home bottom Testimonials Slider
10 | Home bottom Testimonials Slider content
11 | You can choose 3 type home page
12 | Category Page Sidebar
13 | Category left sidebar banner
14 | Category left sidebar banner content
15 | Product page 3 types layout
16 | Header container Bg color
17 | Menu BG color
18 | Menu box shadow color
19 | Menu border color
20 | Menu hover bg color
21 | Primary Color 1
22 | Primary color 2
23 | Primary color 3
24 | Primary color 4
25 | Secendary Color 1
26 | Footer Bg color
27 | Footer Headers color
28 | Footer links color
29 | Footer links hover color
30 | Footer bottom bg color
31 | Footer powered by text color
32 | Background-images
33 | Choose a pattern number
34 | Baackground Attachment
35 | Baackground Repeat
36 | Backgorund Position
37 | Home big slider
38 | Home big slider content
39 | Home big slider bottom promo banner
40 | Home big slider bottom promo banner content
41 | Home Child Fashion (0-5 Years) banner
42 | Home Child Fashion (0-5 Years) Banner Content
43 | Home Kids Fashion (6-12 Years) Banner
44 | Home Kids Fashion (6-12 Years) content
45 | Home Toys & Books (0-12 Years) banner content
46 | Home Toys & Books (0-12 Years) banner content
47 | Home Special Offers banners
48 | Home Special Offers banners content
49 | Home big slider with mini banner
50 | Home big slider bottom mini banner content
51 | Select font source
52 | Body Font to system
53 | Body Font to google
54 | Font size
55 | Select font source
56 | Heading Font to system
57 | Heading Font to google
58 | Text transform
59 | Product headers Font size
60 | Page headers Font size
61 | Left/Right sidebar block headers Font size
62 | Footer headers Font size
63 | Header custom banner 1
64 | Header custom banner 1
65 | Header custom banner 2
66 | Header custom banner 2
67 | Contact information page
68 | Linkedin url
69 | Maestro url
70 | American Express url
71 | New text for produt box
72 | Sale text for produt box
73 | Sale text for compare box
74 | Twitter text for footer
75 | Footer fllow us text
76 | Top Brands Name
77 | Latest category tab all text
78 | Featured Products title home page
79 | Latest Products title home page
80 | Best Sales text for mini Best Sales product title
81 | Special text for home mini Special product title
82 | Top rate product title
83 | Category sidebar title
84 | footer payment accept text
--------------------------------------------------------------------------------
/02_tw_del_01a.php:
--------------------------------------------------------------------------------
1 | read()) {
12 | if ($file != "." && $file != "..") {
13 | get_allfiles($path . "/" . $file, $files); //呼叫自己
14 | }
15 | }
16 | $dp->close();
17 | }
18 | if (is_file($path)) {
19 | $files[] = $path; //只把檔案加進去
20 | }
21 | }
22 |
23 | function get_filenamesbydir($dir)
24 | {
25 | $files = array();
26 | get_allfiles($dir, $files);
27 | return $files;
28 | }
29 |
30 | /** 刪除所有空目錄
31 | * @param String $path 目錄路徑
32 | */
33 | function rm_empty_dir($path)
34 | {
35 | if (is_dir($path) && ($handle = opendir($path)) !== false) {
36 | while (($file = readdir($handle)) !== false) { //遍歷文件夾
37 | if ($file != '.' && $file != '..') {
38 | $curfile = $path . '/' . $file; //當前目錄
39 | if (is_dir($curfile)) { //目錄
40 | rm_empty_dir($curfile); //如果是目錄則繼續遍歷
41 | if (count(scandir($curfile)) == 2) { //目錄為空,=2是因為.和..存在
42 | rmdir($curfile); //刪除空目錄
43 | }
44 | }
45 | }
46 | }
47 | closedir($handle);
48 | }
49 | }
50 | /*********************************************************************************************/
51 | $thisDir = "."; //config.inc.php檔的相對路徑
52 | $_file = basename(__FILE__); //自行取得本程式名稱
53 | $br = "
\n";
54 |
55 | $sourceLanguage = 'en-gb'; //來源語言
56 | $targetLanguage = 'zh-TW'; //目標語言
57 |
58 | $dir = dirname(__FILE__) . "\\01"; //要開啟的路徑
59 | $dir1 = $dir . "a"; //來源目錄 放有英文檔案
60 | $dir2 = $dir . $targetLanguage; //放有 翻譯過的中文檔案
61 |
62 | /*********************************************************************************************/
63 |
64 | $filenamesA = get_filenamesbydir($dir1); //獲取目錄下所有文件,包括子目錄
65 | $filenamesB = get_filenamesbydir($dir2); //獲取目錄下所有文件,包括子目錄
66 | //打印所有文件名,包括路徑
67 |
68 | echo "開始在" . $dir1 . "目錄下刪除已有翻譯檔存在的檔案" . $br;
69 | $z = array('y1' => 0, 'y2' => 0);
70 |
71 | //請注意來源目錄的檔名之中不要有zh-TW這樣的字
72 | foreach ($filenamesB as $value) {
73 | //這裡不會有目錄名只有檔案名
74 | $value2 = str_replace($dir2, $dir1, $value); //要找的檔名
75 | $value2 = str_replace('/', '\\', $value2); //要找的檔名
76 | $value2 = str_replace($targetLanguage, $sourceLanguage, $value2); //要找的檔名
77 | echo "尋找檔案" . $value2;
78 | echo " |結果:";
79 | if (is_file($value2)) {
80 | echo "找到檔案並刪除檔案" . $br;
81 | unlink($value2); //刪除檔案
82 | $z['y1']++;
83 | } else {
84 | echo "沒找到檔案" . $br;
85 | $z['y2']++;
86 | }
87 | }
88 |
89 | echo "統計" . $dir1 . "目錄下有檔案" . count($filenamesA) . "個,和" . $dir2 . "目錄下相同檔案" . $z['y1'] . "個,以刪除檔案" . $z['y1'] . "個";
90 | echo $br;
91 | echo "刪除所有空目錄" . $br;
92 | rm_empty_dir($dir1); //刪除所有空目錄
93 |
--------------------------------------------------------------------------------
/p_td_lable-control/01_p.php:
--------------------------------------------------------------------------------
1 | ".PHP_EOL;
8 | $file1="wg24themeoptionpanel.tpl";//來源檔案
9 | $file2="wg24themeoptionpanel.php";//來源檔案目標檔案
10 |
11 |
12 | //取得所有P標籤裡面的字,並儲存至二維陣列-此法適用"號與'號皆可
13 | function html_ul($text)
14 | {
15 | preg_match_all('@@i', $text, $src);
16 | print_r($src);exit;
17 | if(count($src[1])>0)
18 | {
19 | return $src[1];//只要裡面的字
20 | }else{
21 | return false;
22 | }
23 | }
24 | function html_li($text)
25 | {
26 | preg_match_all('@(.*)@i', $text, $src);
27 | //print_r($src);exit;
28 | if(count($src[1])>0)
29 | {
30 | $src2=array();
31 | //有翻譯過的不要
32 | foreach($src[1] as $v){
33 | if(!preg_match("@<\?php@",$v))
34 | $src2[]=$v;
35 | }
36 | return $src2;//只要裡面的字
37 | }else{
38 | return false;
39 | }
40 | }
41 | //取得所有P標籤裡面的字,並儲存至二維陣列-此法適用"號與'號皆可
42 | function html_p($text)
43 | {
44 | preg_match_all("@(.*)
@i", $text, $src);
45 | //print_r($src);exit;
46 | if(count($src[1])>0)
47 | {
48 | return $src[1];//只要裡面的字
49 | }else{
50 | return false;
51 | }
52 | }
53 |
54 | function html_b($text)
55 | {
56 | preg_match_all("@(.*)@i", $text, $src);
57 | if(count($src[1])>0)
58 | {
59 | $src2=array();
60 | //有翻譯過的不要
61 | foreach($src[1] as $v){
62 | if(!preg_match("@<\?php@",$v))
63 | $src2[]=$v;
64 | }
65 | return $src2;//只要裡面的字
66 | }else{
67 | return false;
68 | }
69 | }
70 | //取得所有td標籤裡面的字,並儲存至二維陣列-此法適用"號與'號皆可
71 | function html_td($text)
72 | {
73 | preg_match_all("@(.*) | @i", $text, $src);
74 | //print_r($src);exit;
75 | if(count($src[1])>0)
76 | {
77 | $src2=array();
78 | //有翻譯過的不要
79 | foreach($src[1] as $v){
80 | if(!preg_match("@<\?php@",$v))
81 | $src2[]=$v;
82 | }
83 | return $src2;//只要裡面的字
84 | }else{
85 | return false;
86 | }
87 | }
88 |
89 | //==========================================================================
90 | //==========================================================================
91 | $file_text=file_get_contents($file1);//開啟檔案
92 |
93 | $td=html_p($file_text);//取出p標籤的字
94 | //print_r($p);
95 |
96 | //要翻譯的字
97 | $text="";//起始
98 | for($i=0;$i".$br;
106 |
107 |
108 | $b=html_b($file_text);//取出ul標籤的字
109 | //print_r($p);
110 |
111 | //要翻譯的字
112 | $text="";//起始
113 | for($i=0;$i".PHP_EOL;
8 | $file1="wg24themeoptionpanel.tpl";//來源檔案
9 | $file2="wg24themeoptionpanel.php";//來源檔案目標檔案
10 |
11 |
12 | //取得所有P標籤裡面的字,並儲存至二維陣列-此法適用"號與'號皆可
13 | function html_ul($text)
14 | {
15 | preg_match_all('@@i', $text, $src);
16 | print_r($src);exit;
17 | if(count($src[1])>0)
18 | {
19 | return $src[1];//只要裡面的字
20 | }else{
21 | return false;
22 | }
23 | }
24 | function html_li($text)
25 | {
26 | preg_match_all('@(.*)@i', $text, $src);
27 | //print_r($src);exit;
28 | if(count($src[1])>0)
29 | {
30 | $src2=array();
31 | //有翻譯過的不要
32 | foreach($src[1] as $v){
33 | if(!preg_match("@<\?php@",$v))
34 | $src2[]=$v;
35 | }
36 | return $src2;//只要裡面的字
37 | }else{
38 | return false;
39 | }
40 | }
41 | //取得所有P標籤裡面的字,並儲存至二維陣列-此法適用"號與'號皆可
42 | function html_p($text)
43 | {
44 | preg_match_all("@(.*)
@i", $text, $src);
45 | //print_r($src);exit;
46 | if(count($src[1])>0)
47 | {
48 | return $src[1];//只要裡面的字
49 | }else{
50 | return false;
51 | }
52 | }
53 |
54 | function html_b($text)
55 | {
56 | preg_match_all("@(.*)@i", $text, $src);
57 | if(count($src[1])>0)
58 | {
59 | $src2=array();
60 | //有翻譯過的不要
61 | foreach($src[1] as $v){
62 | if(!preg_match("@<\?php@",$v))
63 | $src2[]=$v;
64 | }
65 | return $src2;//只要裡面的字
66 | }else{
67 | return false;
68 | }
69 | }
70 | //取得所有td標籤裡面的字,並儲存至二維陣列-此法適用"號與'號皆可
71 | function html_td($text)
72 | {
73 | preg_match_all("@(.*) | @i", $text, $src);
74 | //print_r($src);exit;
75 | if(count($src[1])>0)
76 | {
77 | $src2=array();
78 | //有翻譯過的不要
79 | foreach($src[1] as $v){
80 | if(!preg_match("@<\?php@",$v))
81 | $src2[]=$v;
82 | }
83 | return $src2;//只要裡面的字
84 | }else{
85 | return false;
86 | }
87 | }
88 | //空格取代為底線
89 | function t_($text)
90 | {
91 | $text2=trim($text);
92 | $text2=str_replace(' ', '',$text2);
93 | $text2=str_replace('/', '',$text2);
94 | return $text2;
95 | }
96 |
97 | //讓空格變整齊以變數長度決定空格數目
98 | function tt_($v)
99 | {
100 | $text=" ";
101 | $s=53;//預設最常空格多少個;
102 | $s2=strlen(t_($v));//以去除後的字數做計算
103 | //print_r($s2);echo "\n";
104 | $td=$s-($s2+6);
105 |
106 | for($i=0;$i<$td;$i++){
107 | $text.=" ";
108 | }
109 | return $text;
110 | }
111 | //==========================================================================
112 | //==========================================================================
113 | $file_text=file_get_contents($file1);//開啟檔案
114 |
115 | $td=html_li($file_text);//取出ul標籤的字
116 | //print_r($p);
117 |
118 | //要翻譯的字
119 | $text="";//起始
120 | for($i=0;$i".$br;
128 |
129 |
130 | $b=html_b($file_text);//取出ul標籤的字
131 | //print_r($p);
132 |
133 | //要翻譯的字
134 | $text="";//起始
135 | for($i=0;$iquery("SET NAMES 'utf8'"); //以下資料用utf8碼與資料庫連線 必須有此行
13 | //$mysqli->query("set time_zone = '+8:00'"); //時區指定
14 | if (mysqli_connect_errno($mysqli)) {
15 | echo "連接 MySQL 失敗: " . mysqli_connect_error();
16 | }
17 | return $mysqli;
18 | }
19 |
20 | //關資料庫
21 | function cmysql($link) {
22 | //$mysqli->close();
23 | mysqli_close($link);
24 | }
25 |
26 | //以IN查資料 給陣列變為要入SQL的字-----這段不一樣注意注意
27 | function idgroup($array=array()) {
28 | if (empty($array))
29 | return "IN(0)"; //沒資料不查
30 |
31 | if (is_array($array)) {
32 | $IDGroup = " IN (";
33 | for ($ii = 0; $ii < count($array); $ii++) {
34 | if (!$ii)
35 | $IDGroup = $IDGroup . "'" . $array[$ii] . "'";
36 | else
37 | $IDGroup .= ",'" . $array[$ii] . "'";
38 | }
39 | $IDGroup .= ")";
40 | return $IDGroup;
41 | }else {
42 | return "IN(0)";
43 | }
44 | }
45 |
46 | //不連結資料庫--以數字建立二維陣列
47 | function srow_sql($sql, $linkID = "") {
48 | if ($linkID)
49 | $result = mysqli_query($linkID,$sql)or die("error 單行查詢錯誤: " . $sql); //帶入查詢語法;
50 | else
51 | $result = mysqli_query($sql)or die("error - 1 : " . $sql); //帶入查詢語法
52 | //查詢結果抓出一筆存入array[]陣列
53 | while ($row = mysqli_fetch_row($result)) {
54 | $array[] = $row;
55 | }
56 | $result->close(); //釋放記憶體
57 | return $array;
58 | }
59 |
60 | //不連結資料庫-以欄名建立二維陣列
61 | function assoc_sql($sql, $link) {
62 | $result = mysqli_query($link, $sql)or die("error 單行查詢錯誤: " . $sql); //帶入查詢語法;
63 | //查詢結果抓出一筆存入array[]陣列
64 | while ($row = mysqli_fetch_assoc($result)) {
65 | $array[] = $row;
66 | }
67 | $result->close(); //釋放記憶體
68 | return $array;
69 | }
70 |
71 | //不連結資料庫-以攔名建立一維陣列(單行)
72 | function assoc_sql1p($sql, $linkID = "") {
73 | if ($linkID)
74 | $str = mysqli_query($linkID,$sql)or die("error 單行查詢錯誤: " . $sql); //帶入查詢語法;
75 | else
76 | $str = mysqli_query($sql)or die("error 單行查詢錯誤: " . $sql); //帶入查詢語法;
77 | $row = mysqli_fetch_assoc($str); //抄下符合名稱那一排的資料
78 | return $row; //結果參數存回主程式 若找無資料會返回""
79 | }
80 |
81 | //不連結資料庫-以數字建立一維陣列(單行)
82 | function row_sql($sql, $linkID = "") {
83 | if ($linkID)
84 | $str = mysqli_query($linkID,$sql)or die("error 單行查詢錯誤: " . $sql); //帶入查詢語法;
85 | else
86 | $str = mysqli_query($sql)or die("error 單行查詢錯誤: " . $sql); //帶入查詢語法;
87 | $row = mysqli_fetch_row($str); //抄下符合名稱那一排的資料
88 | return $row; //結果參數存回主程式 若找無資料會返回""
89 | }
90 |
91 | //不連結資料庫-只取一個答案
92 | function row_sql1p($sql, $s = 0, $linkID = "") {
93 | if ($linkID)
94 | $str = mysqli_query($linkID,$sql)or die("error 單行查詢錯誤: " . $sql); //帶入查詢語法;
95 | else
96 | $str = mysqli_query($sql)or die("error 單行查詢錯誤: " . $sql); //帶入查詢語法;
97 | $row = mysqli_fetch_row($str); //抄下符合名稱那一排的資料
98 | return $row[$s]; //結果參數存回主程式 若找無資料會返回""
99 | }
100 |
101 | //修改資料
102 | function mysql_up($sql, $linkID) {
103 | $str = mysqli_query($linkID,$sql)or die("error -1: " . $sql); //帶入查詢語法;
104 | return $str;
105 | }
106 |
107 | //新增資料 //成功會是1 失敗會返回空
108 | function mysql_insert($sql, $linkID) {
109 | $str = mysqli_query($linkID,$sql); //帶入查詢語法;
110 | return $str; //成功會是1 失敗會返回空
111 | }
112 |
113 | //新增資料 //成功會是1 失敗會返回錯誤訊息
114 | function mysql_insert_i($sql, $linkID) {
115 | $str = mysqli_query($linkID,$sql); //帶入查詢語法;
116 | if(empty($str)){
117 | $str =mysqli_error($linkID);//錯誤訊息
118 | }
119 | return $str;
120 | }
--------------------------------------------------------------------------------
/p_td_lable-control/translate_tw.txt:
--------------------------------------------------------------------------------
1 | 產品盒中最後一個產品顯示為新圖標的數量
2 | 您可以顯示或隱藏主頁3的迷你產品輪播
3 | 你可以選擇4種類型的店頭風格
4 | 類別模塊產品顯示或隱藏
5 | 首頁中免費退款內容
6 | 主頁來自博客的新聞
7 | 主頁新聞從博客內容
8 | 主頁底部褒獎輪播
9 | 主頁底部推薦輪播內容
10 | 你可以選擇3種類型的主頁
11 | 類別目錄側欄
12 | 類別左側廣告內容
13 | 類別左側廣告
14 | 產品頁面3種類型的佈局
15 | 標題容器Bg顏色
16 | 選單BG顏色
17 | 選單框陰影顏色
18 | 選單邊框顏色
19 | 選單懸停bg顏色
20 | 原色1
21 | 原色2
22 | 原色3
23 | 原色4
24 | Secendary顏色1
25 | 頁尾Bg顏色
26 | 頁尾標題顏色
27 | 頁尾鍊接顏色
28 | 頁尾鍊接懸停顏色
29 | 頁尾底部bg顏色
30 | 頁尾支持文字顏色
31 | 背景圖像
32 | 選擇一個模式編號
33 | 背景 附件
34 | 背景 重複
35 | 背景 位置
36 | 首頁大輪播
37 | 首頁大輪播內容
38 | 首頁大輪播底部促銷橫幅內容
39 | 首頁大輪播底部促銷橫幅
40 | 家庭兒童時裝(0-5歲)的標題
41 | 家庭兒童時裝(0-5歲)橫幅內容
42 | 家庭兒童時裝(6-12歲)橫幅
43 | 首頁兒童時裝(6-12歲)內容
44 | 家庭玩具和書籍(0-12 歲)橫幅內容
45 | 家庭玩具和書籍(0-12 歲)橫幅內容
46 | 家特別優惠橫幅內容
47 | 家特別優惠橫幅
48 | 首頁與迷你橫幅大輪播
49 | 首頁大輪播底部迷你橫幅內容
50 | 選擇字體來源
51 | 正文字體到系統
52 | 身體字體谷歌
53 | 字體大小
54 | 選擇字體來源
55 | 標題字體到系統
56 | 標題字體谷歌
57 | 文字轉換
58 | 產品標題字體大小
59 | 頁眉字體大小
60 | 左/右邊欄塊標題字體大小
61 | 頁尾標題字體大小
62 | 標題自定義橫幅1
63 | 標題自定義橫幅1
64 | 標題自定義橫幅2
65 | 標題自定義橫幅2
66 | 聯繫信息頁面
67 | Linkedin 網址
68 | Maestro 網址
69 | 美國運通 網址
70 | 產品盒的新文字
71 | 銷售文字為產品箱子
72 | 對比框的銷售文字
73 | Twitter 的腳本文字
74 | 頁尾 聯繫我們 的文字
75 | 廠商品牌名稱
76 | 最新類別選項卡所有文字
77 | 推薦產品 標題主頁
78 | 最新產品 標題主頁
79 | 暢銷商品 標題文字
80 | 特價商品 標題文字
81 | 最高的產品標題
82 | 類別側邊欄標題
83 | 頁尾付款接受文字
84 |
85 | 您可以顯示新圖標的新項目限制
86 | 您可以顯示或隱藏顯示滾動到頂部按鈕
87 | 您可以顯示或隱藏店舖的標題樣式
88 | 您可以顯示或隱藏顯示滾動到頂部按鈕
89 | 您可以顯示或隱藏類別模塊產品
90 | 首頁中免費退款內容
91 | 如果您想要顯示或隱藏來自博客的新聞
92 | 自家博客下的自定義文字
93 | 如果你想顯示或隱藏家庭底部推薦輪播
94 | 家中的自定義文字推薦輪播內容
95 | 您可以選擇主頁1 ..... 3
96 | 您可以顯示或隱藏類別目錄子類別
97 | 如果你想改變目錄頁面的默認視圖風格
98 | 您可以顯示側邊欄或沒有側邊欄
99 | 您可以顯示類別左側邊欄橫幅
100 | 請將您的類別左側欄橫幅內容
101 | 你可以選擇3型產品頁面
102 | 您可以在產品上顯示或隱藏 自定義標籤頁
103 | 自定義html標籤標題
104 | 自定義Html在產品頁面上顯示
105 | 您可以加載配色方案
106 | 默認顏色:#FFFFFF。如果你想改變這種顏色
107 | 默認顏色:#666666。如果你想改變這種顏色
108 | 默認顏色:#666666。如果你想改變這種顏色
109 | 默認顏色:#000000。如果你想改變這種顏色
110 | 默認顏色:#FFFFFF。如果你想改變這種顏色
111 | 默認顏色:#595959。如果你想改變這種顏色
112 | 默認顏色:#dcdcdc。如果你想改變這種顏色
113 | 默認顏色:#FFFFFF。如果你想改變這種顏色
114 | 默認顏色:#FFFFFF。如果你想改變這種顏色
115 | 默認顏色:#eee。如果你想改變這種顏色
116 | 默認顏色:#E7E7E7。如果你想改變這種顏色
117 | 默認顏色:#000000。如果你想改變這種顏色
118 | 默認顏色:#333333。如果你想改變這種顏色
119 | 默認顏色:#FBFBFB。如果你想改變這種顏色
120 | 默認顏色:#FCEFF1。如果你想改變這種顏色
121 | 默認顏色:#333333。如果你想改變這種顏色
122 | 默認顏色:#333333。如果你想改變這種顏色
123 | 默認顏色:#6fc191。如果你想改變這種顏色
124 | 默認顏色:#f37d8a。如果你想改變這種顏色
125 | 默認顏色:#77d0e4。如果你想改變這種顏色
126 | 默認顏色:#e5b856。如果你想改變這種顏色
127 | 默認顏色:#000000。如果你想改變這種顏色
128 | 默認顏色:rgba(51,51,51,0.98)。如果你想改變這種顏色
129 | 默認顏色:#FFFFFF。如果你想改變這種顏色
130 | 默認顏色:#8e8e8e。如果你想改變這種顏色
131 | 默認顏色:#fff。如果你想改變這種顏色
132 | 默認顏色:#rgba(44,44,44,0.98)。如果你想改變這種顏色
133 | 默認顏色:#8e8e8e。如果你想改變這種顏色
134 | 如果你想顯示或隱藏主體背景圖像
135 | 首先上傳到目錄/視圖/主題/ catalog/view/theme/babystore/image/theme_patterns/
136 | 請把你的主頁輪播內容
137 | 如果你想顯示或隱藏首頁大輪播底部促銷橫幅
138 | 如果您想要顯示或隱藏童裝(0-5歲)橫幅
139 | 請將您的主頁輪播底部的功能內容
140 | 如果你想顯示或隱藏家庭兒童時裝(6-12歲)橫幅
141 | 請把你的家庭童裝時裝6-12年的內容
142 | 如果你想顯示或隱藏家庭兒童時裝(0-12歲)的標題
143 | 請把你的家庭時尚(0-12歲)的標題
144 | 如果你想顯示或隱藏家庭特別優惠橫幅
145 | 請把你的家庭特別優惠橫幅內容
146 | 如果你想用迷你橫幅顯示或隱藏首頁大輪播
147 | 請放置您的主頁橫幅內容
148 | 如果你想選擇字體源系統/谷歌。
149 | 您可以更改主體字體樣式..
150 | 您可以更改主體字體樣式。
151 | 您可以更改標題字體樣式..
152 | 您可以更改標題字體樣式。
153 | 請把你的消息框自定義塊內容
154 | 您可以顯示或隱藏主頁消息框自定義塊
155 | 把你的臉書頁面網址放在這個 區塊 裡。
156 | 你的Twitter用戶名。
157 | 推文計數
158 | 你的 Facebook 網址
159 | 你的 Twitter 網址
160 | 你的 Google 網址
161 | 你的 Rss 網址
162 | 你的 Skype 網址
163 | 你的 PayPal 網址
164 | 你的 visaelectron 網址
165 | 你的 Discover 網址
166 | 你的 Visa 網址
167 | 你的 萬事達 網址
168 | 你的 Maestro 網址
169 | 你的 美國運通 網址
170 | 新圖標的文字
171 | 自定義html標籤標題設計在產品頁面上顯示
172 | 自定義html標籤標題設計在比較頁面上顯示
173 | 頁尾讓我們的文字
174 | 查看最新產品文字主頁中間部分
175 | 最新類別選項卡所有文字
176 | 特色產品標題主頁底部迷你產品
177 | 最新產品標題主頁底部迷你產品
178 | Best Sales產品標題的最佳銷售文字
179 | 特殊產品標題的特殊文字
180 | 最高的產品標題
181 | 類別側邊欄標題
182 | 頁尾接受付款文字
183 | 您可以在此框中添加Google分析代碼/其他跟踪代碼
184 | 在您的主題中添加自定義CSS展示
185 | 在您的主題中添加自定義jss顯示
186 | 主頁輪播
187 | 首頁與迷你橫幅大輪播
188 | 身體字體
189 | 標題字體
190 | 類別目錄
191 |
192 | 頁尾
193 | 主頁輪播
194 | 首頁與迷你輪播
195 | 全局內容字體
196 | 商店聯繫信息
197 | 商店聯繫信息頁面內容
198 | 主題文字翻譯器
199 | 佈局
200 | 首頁
201 | 類別目錄
202 | 產品頁面
203 | 加載顏色皮膚
204 | 主要
205 | 主選單
206 | 全局配色
207 | 主頁1
208 | 主頁2
209 | 主頁3
210 | 正文字體
211 | 標題字體
212 | Twitter Feed框
213 | 聯繫信息
214 | 社群圖示
215 | 技術支援訊息
216 | 付款圖示
217 |
218 | 開啟
219 | 關閉
--------------------------------------------------------------------------------
/README.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 檔案版本
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | | 檔案名稱 |
14 | 作用 |
15 | 作用目錄 |
16 | 重要度 |
17 |
18 |
19 | | 01_test_googlefree.php |
20 | 測試 GOOGLE 翻譯 API 寫法的第一支程式 |
21 | |
22 | |
23 |
24 |
25 | | 01_test_post_googleapi.php |
26 | 測試 GOOGLE 翻譯 API 寫法POST |
27 | |
28 | |
29 |
30 |
31 | | 02_tw_del_01a.php |
32 | 來源目錄要刪除現有翻譯過的中文檔案
33 | 以01a目錄和01zh-TW這2個目錄做比對 |
34 | |
35 | |
36 |
37 |
38 | | en-gb_com_zh-TW.php |
39 |
40 | 如果我有一份翻譯好的英文原版和中文版,比對2個目錄下的檔案,然後將翻譯對照表寫入資料庫,優先權設為1,以後翻譯會先以這分為準 |
41 | 比對01en-gb和01zh-TW這2個目錄 |
42 | 重要 |
43 |
44 |
45 | | index13.php |
46 | AUTO translation file googleapi
47 | 功能把01a目錄下的檔案全翻譯完
48 | 2017/12/5 會先比對資料庫,已有資料的就不會呼叫GOOGLEAPI去查
49 | 2017/12/6 多做沒翻完的提醒
50 | 2017/12/8 目標目錄不用自己建立了程式會自己建立-不論幾層 |
51 | 把01a目錄下的檔案自動翻譯完複製到01b目錄下 |
52 | 重要 |
53 |
54 |
55 | | |
56 | 以下為舊版 |
57 | |
58 | |
59 |
60 |
61 | | index5.php |
62 | |
69 | |
70 | |
71 |
72 |
73 | | index6.php |
74 | |
75 | |
76 | |
77 |
78 |
79 | | index7.php |
80 | |
81 | |
82 | |
83 |
84 |
85 | | index8.php |
86 | |
87 | |
88 | |
89 |
90 |
91 | | index9.php |
92 |
93 | 2017/12/5 完工會用資料庫比對查
94 | |
95 | |
96 | |
97 |
98 |
99 | | index10.php |
100 | 資料庫的翻譯也有優先權-以數字小的為優先 |
101 | |
102 | |
103 |
104 |
105 | | index11.php |
106 |
107 | 2017/12/6 多做沒翻完的提醒
108 | |
109 | |
110 | |
111 |
112 |
113 | | index12.php |
114 | 2017/12/8 目標目錄不用自己建立了程式會自己建立-不論幾層 |
115 | |
116 | |
117 |
118 |
119 | | index13.php |
120 | 修正小錯 |
121 | |
122 | |
123 |
124 |
125 | | index14_EN_to_vi.php |
126 | 翻譯中文為越南語 |
127 | |
128 | |
129 |
130 |
131 | | |
132 | |
133 | |
134 | |
135 |
136 |
137 | | /p_td_lable-control |
138 | 以TXT檔的內容翻譯tpl模板檔案.txt |
139 | |
140 | |
141 |
142 |
143 | | |
144 |
145 | 01.以wg24themeoptionpanel.tpl 生出翻譯
146 | 02.以TEXT翻譯檔為基礎 產生2個翻譯檔
147 | 03.以TEXT翻譯檔為基礎 修改目標檔案
148 | |
149 | |
150 | |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
--------------------------------------------------------------------------------
/p_td_lable-control/p_td_lable-control.php:
--------------------------------------------------------------------------------
1 | ".PHP_EOL;
8 | $file1="wg24themeoptionpanel.tpl";//來源檔案
9 | $file2="wg24themeoptionpanel.php";//來源檔案目標檔案
10 |
11 |
12 | //取得所有P標籤裡面的字,並儲存至二維陣列-此法適用"號與'號皆可
13 | function html_p($text)
14 | {
15 | preg_match_all("@(.*)<\/p>@i", $text, $src);
16 | //print_r($src);exit;
17 | if(count($src[1])>0)
18 | {
19 | return $src[1];//只要裡面的字
20 | }else{
21 | return false;
22 | }
23 | }
24 | //取得所有td標籤裡面的字,並儲存至二維陣列-此法適用"號與'號皆可
25 | function html_td($text)
26 | {
27 | preg_match_all("@
(.*)<\/td>@i", $text, $src);
28 | //print_r($src);exit;
29 | if(count($src[1])>0)
30 | {
31 | $src2=array();
32 | //有翻譯過的不要
33 | foreach($src[1] as $v){
34 | if(!preg_match("@<\?php@",$v))
35 | $src2[]=$v;
36 | }
37 | return $src2;//只要裡面的字
38 | }else{
39 | return false;
40 | }
41 | }
42 | //空格取代為底線
43 | function t_($text)
44 | {
45 | $text2=trim($text);
46 | $text2=str_replace(' ', '',$text2);
47 | $text2=str_replace('/', '',$text2);
48 | return $text2;
49 | }
50 |
51 | //讓空格變整齊以變數長度決定空格數目
52 | function tt_($v)
53 | {
54 | $text=" ";
55 | $s=53;//預設最常空格多少個;
56 | $s2=strlen(t_($v));//以去除後的字數做計算
57 | //print_r($s2);echo "\n";
58 | $td=$s-($s2+6);
59 |
60 | for($i=0;$i<$td;$i++){
61 | $text.=" ";
62 | }
63 | return $text;
64 | }
65 | //==========================================================================
66 | //==========================================================================
67 | $file_text=file_get_contents($file1);//開啟檔案
68 |
69 | $p=html_p($file_text);//取出P標籤的字
70 | $td=html_td($file_text);//取出td標籤的字
71 |
72 | //print_r($p);exit;
73 |
74 | //===========================================================
75 | //搞出英文翻譯版
76 | $text="";//起始
77 | for($i=0;$iget_tw($v).'\';';//翻譯的文字
110 | $text.="\n";
111 | }
112 |
113 | $filename="./zh-TW/".$file2;
114 | auto_mkdir($filename);//查路徑目錄在不在,不在就建立目錄
115 |
116 |
117 | //抓取之後存檔
118 | if (!$handle = fopen($filename, 'w')) {echo "error open log file";}
119 | if (fwrite($handle, $text) === FALSE) {echo "error write LOG File";}
120 | fclose($handle);//關檔
121 | echo "內容已丟到暫存檔".$filename.$br;
122 |
123 | //===========================================================
124 | //修改tpl 檔
125 | //以英文翻譯檔的內容為準
126 |
127 | $text=$file_text;//起始
128 | $s=0;
129 | $ok=0;
130 | for($i=0;$i'.$v3.' | ';
135 | //尋找
136 | if(preg_match("@".$v."@i",$text)){
137 | $text=preg_replace("@".$v."@i",''.$Translate->get_tw($v2).' | ',$text);//每一行字翻譯
138 | $ok++;
139 | }else{
140 | echo "沒找到的字".$v.$br;
141 | }
142 | $s++;
143 | }
144 |
145 | echo "tpl檔需翻譯字串".$s."完成".$ok."筆".$br;
146 |
147 | $filename=str_replace(".tpl","_tw.tpl",$file1);//來源檔案改檔名;
148 | auto_mkdir($filename);//查路徑目錄在不在,不在就建立目錄
149 |
150 |
151 | //抓取之後存檔
152 | if (!$handle = fopen($filename, 'w')) {echo "error open log file";}
153 | if (fwrite($handle, $text) === FALSE) {echo "error write LOG File";}
154 | fclose($handle);//關檔
155 | echo "內容已丟到暫存檔".$filename.$br;
156 |
--------------------------------------------------------------------------------
/index12.php:
--------------------------------------------------------------------------------
1 | \n";
21 |
22 | /*********************************************************************************************/
23 | /*
24 | 翻譯超簡單使用
25 | 如果你有申請過該API-網址直打就會有返回值
26 | //$url='https://translation.googleapis.com/language/translate/v2?key=[請自己去申請KEY]&q=fuck&q=language&target=zh-TW';
27 | 申請KEY的位置
28 | 請通過訪問https://console.developers.google.com/apis/api/translate.googleapis來啟用它 這個 AIP名字叫 Google Cloud Translation API
29 | KEY不能用別人的
30 | */
31 |
32 | $url = 'https://translation.googleapis.com/language/translate/v2?key=' . googleApiKEY;
33 | define('googleapi_url', $url);
34 | /*********************************************************************************************/
35 | $sourcelanguage = 'en-gb'; //來源語言
36 | $targetlanguage = 'zh-TW'; //目標語言
37 |
38 | $dir = dirname(__FILE__) . "\\01"; //要開啟的路徑
39 | $dir1 = $dir . "a"; //來源目錄 放有英文檔案
40 | $dir2 = $dir . "b"; //放有 翻譯過的中文檔案
41 |
42 | /*********************************************************************************************/
43 |
44 | $filenamesA = get_filenamesbydir($dir1); //獲取目錄下所有文件,包括子目錄
45 | $filenamesB = get_filenamesbydir($dir2); //獲取目錄下所有文件,包括子目錄
46 | /*********************************************************************************************/
47 | /* ********************************************************************************************* */
48 | $CT_CONFIG['db_name'] = 't_translation_googleapi'; //要開啟的資料庫
49 | $CT_CONFIG['db_sheet'] = DB_PREFIX . 't'; //子資料表
50 |
51 | $CT_CONFIG['project_name'] = 'opencart'; //專案名稱
52 | $CT_CONFIG['version'] = '2.3.0.2'; //版本號一律4碼
53 |
54 | $linkID = omysql($CT_CONFIG['db_name']); //開資料庫================================================
55 | $CT_CONFIG['linkID'] = $linkID;
56 |
57 | $z = array('y1' => 0, 'y2' => 0);
58 | //打印所有文件名,包括路徑
59 | foreach ($filenamesA as $value) {
60 | $ss = 0;
61 | //這裡不會有目錄名
62 | echo "來源" . $value; //開啟檔案
63 | $sms = '';
64 | $f = array();
65 | //這裡不會有目錄名只有檔案名
66 | $value2 = str_replace($dir1, $dir2, $value); //要找的檔名
67 | $value2 = str_replace('/', '\\', $value2); //要找的檔名
68 | $value2 = str_replace($sourcelanguage, $targetlanguage, $value2); //要找的檔名
69 | $sms .= "目標檔案可寫入檢查";
70 | $sms .= " |結果:";
71 | if (is_file($value2)) {
72 | $sms .= "找到檔案" . $br;
73 | $f['target'] = $value2; //目標檔名
74 | $f['dirname'] = substr(dirname($value2), strlen($dir2) + 1); //路徑要去掉相同部分
75 | $f['basename'] = basename($value2); //檔名
76 | //print_r($f);
77 |
78 | $ap = get_translated_word_test($value); //開檔案
79 | $ap['f'] = $f; //檔案相關資訊
80 |
81 | $ap = ai_translated($ap, $sourcelanguage, $targetlanguage, $CT_CONFIG, $sms); //AI翻譯
82 |
83 | //有錯就不做下一步了
84 | if ($ap['error']) {
85 | $sms = $ap['sms'];
86 | } else {
87 | //沒錯才做下一步了
88 | $apend = $ap['ai_result'];
89 | $sms = $ap['sms'];
90 |
91 | //組出檔案內容
92 | $context = '';
93 | $context1p = '';
94 | for ($i = 0; $i < count($apend['a']); $i++) {
95 | $context1p = $apend['a'][$i]; //這沒有換行的
96 | if (trim($apend['c'][$i])) {
97 | //有翻譯才有
98 | $context1p .= " = '" . addslashesB($apend['c'][$i]) . "';"; //由於都用'包覆所以原本有'的要處理
99 | }
100 | if ($context1p == '\n') {
101 | //如果該行是空白只有1個\n
102 | } else {
103 | $context .= $context1p . "\n"; //換行都用\n
104 | }
105 |
106 | }
107 | //有內容才寫檔案
108 | if (trim($context)) {
109 | $sms .= " 寫入檔案";
110 | file_put_contents($value2, $context); //寫入檔案
111 | }
112 | }
113 |
114 | echo $sms . $br;
115 | //exit; //測試做1次就停止
116 | $z['y1']++; //處理檔案次數
117 | } else {
118 | echo "沒找到檔案" . $br;
119 | $z['y2']++;
120 | }
121 | }
122 | cmysql($linkID); //關資料庫==============================================================
123 | echo "
" . $br;
124 | echo "處理" . $z['y1'] . "個檔案" . $br;
125 |
--------------------------------------------------------------------------------
/_api/google/GoogleTranslate.php:
--------------------------------------------------------------------------------
1 |
11 | * @copyright 2016 Adrián Barrio Andrés
12 | * @license https://opensource.org/licenses/GPL-3.0 GNU General Public License 3.0
13 | * @version 2.0
14 | * @link https://statickidz.com/
15 | */
16 |
17 | /**
18 | * Main class GoogleTranslate
19 | *
20 | * @package GoogleTranslate
21 | *
22 | */
23 | class GoogleTranslate
24 | {
25 |
26 | /**
27 | * Retrieves the translation of a text
28 | *
29 | * @param string $source
30 | * Original language of the text on notation xx. For example: es, en, it, fr...
31 | * @param string $target
32 | * Language to which you want to translate the text in format xx. For example: es, en, it, fr...
33 | * @param string $text
34 | * Text that you want to translate
35 | *
36 | * @return string a simple string with the translation of the text in the target language
37 | */
38 | public static function translate($source, $target, $text)
39 | {
40 | // Request translation
41 | $response = self::requestTranslation($source, $target, $text);
42 |
43 | // Get translation text
44 | // $response = self::getStringBetween("onmouseout=\"this.style.backgroundColor='#fff'\">", "", strval($response));
45 |
46 | // Clean translation
47 | $translation = self::getSentencesFromJSON($response);
48 |
49 | return $translation;
50 | }
51 |
52 | /**
53 | * Internal function to make the request to the translator service
54 | *
55 | * @internal
56 | *
57 | * @param string $source
58 | * Original language taken from the 'translate' function
59 | * @param string $target
60 | * Target language taken from the ' translate' function
61 | * @param string $text
62 | * Text to translate taken from the 'translate' function
63 | *
64 | * @return object[] The response of the translation service in JSON format
65 | */
66 | protected static function requestTranslation($source, $target, $text)
67 | {
68 |
69 | // Google translate URL
70 | $url = "https://translate.google.com/translate_a/single?client=at&dt=t&dt=ld&dt=qca&dt=rm&dt=bd&dj=1&hl=es-ES&ie=UTF-8&oe=UTF-8&inputm=2&otf=2&iid=1dd3b944-fa62-4b55-b330-74909a99969e";
71 | $url = "https://translate.google.com.tw/translate_a/single?client=at&dt=t&dt=ld&dt=qca&dt=rm&dt=bd&dj=1&hl=es-ES&ie=UTF-8&oe=UTF-8&inputm=2&otf=2&iid=1dd3b944-fa62-4b55-b330-74909a99969e";
72 |
73 | $fields = array(
74 | 'sl' => urlencode($source),
75 | 'tl' => urlencode($target),
76 | 'q' => urlencode($text)
77 | );
78 |
79 | if(strlen($fields['q'])>=5000)
80 | throw new \Exception("Maximum number of characters exceeded: 5000");
81 |
82 | // URL-ify the data for the POST
83 | $fields_string = "";
84 | foreach ($fields as $key => $value) {
85 | $fields_string .= $key . '=' . $value . '&';
86 | }
87 |
88 | rtrim($fields_string, '&');
89 |
90 | // Open connection
91 | $ch = curl_init();
92 |
93 | // Set the url, number of POST vars, POST data
94 | curl_setopt($ch, CURLOPT_URL, $url);
95 | curl_setopt($ch, CURLOPT_POST, count($fields));
96 | curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
97 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
98 | curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
99 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
100 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
101 | //curl_setopt($ch, CURLOPT_USERAGENT, 'AndroidTranslate/5.3.0.RC02.130475354-53000263 5.1 phone TRANSLATE_OPM5_TEST_1');
102 | curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko');//IE11
103 | // Execute post
104 | $result = curl_exec($ch);
105 |
106 | // Close connection
107 | curl_close($ch);
108 |
109 | return $result;
110 | }
111 |
112 | /**
113 | * Dump of the JSON's response in an array
114 | *
115 | * @param string $json
116 | * The JSON object returned by the request function
117 | *
118 | * @return string A single string with the translation
119 | */
120 | protected static function getSentencesFromJSON($json)
121 | {
122 | $sentencesArray = json_decode($json, true);
123 | $sentences = "";
124 |
125 | foreach ($sentencesArray["sentences"] as $s) {
126 | $sentences .= isset($s["trans"]) ? $s["trans"] : '';
127 | }
128 |
129 | return $sentences;
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/index13.php:
--------------------------------------------------------------------------------
1 | \n";
23 |
24 | /*********************************************************************************************/
25 | /*
26 | 翻譯超簡單使用
27 | 如果你有申請過該API-網址直打就會有返回值
28 | //$url='https://translation.googleapis.com/language/translate/v2?key=[請自己去申請KEY]&q=fuck&q=language&target=zh-TW';
29 | 申請KEY的位置
30 | 請通過訪問https://console.developers.google.com/apis/api/translate.googleapis來啟用它 這個 AIP名字叫 Google Cloud Translation API
31 | KEY不能用別人的
32 | */
33 |
34 | $url = 'https://translation.googleapis.com/language/translate/v2?key=' . googleApiKEY;
35 | define('googleapi_url', $url);
36 | /*********************************************************************************************/
37 | $sourcelanguage = 'en-gb'; //來源語言
38 | $targetlanguage = 'zh-TW'; //目標語言
39 |
40 | $dir = dirname(__FILE__) . "\\01"; //要開啟的路徑
41 | $dir1 = $dir . "a"; //來源目錄 放有英文檔案
42 | $dir2 = $dir . "b"; //放有 翻譯過的中文檔案
43 |
44 | /*********************************************************************************************/
45 |
46 | $filenamesA = get_filenamesbydir($dir1); //獲取目錄下所有文件,包括子目錄
47 | $filenamesB = get_filenamesbydir($dir2); //獲取目錄下所有文件,包括子目錄
48 | /*********************************************************************************************/
49 | /* ********************************************************************************************* */
50 | $CT_CONFIG['db_name'] = 't_translation_googleapi'; //要開啟的資料庫
51 | $CT_CONFIG['db_sheet'] = DB_PREFIX . 't'; //子資料表
52 |
53 | $CT_CONFIG['project_name'] = 'opencart'; //專案名稱
54 | $CT_CONFIG['version'] = '2.3.0.2'; //版本號一律4碼
55 |
56 | $linkID = omysql($CT_CONFIG['db_name']); //開資料庫================================================
57 | $CT_CONFIG['linkID'] = $linkID;
58 |
59 | $z = array('y1' => 0, 'y2' => 0);
60 | //打印所有文件名,包括路徑
61 | foreach ($filenamesA as $value) {
62 | $ss = 0;
63 | //這裡不會有目錄名
64 | echo "來源" . $value; //開啟檔案
65 | $sms = '';
66 | $f = array();
67 | //這裡不會有目錄名只有檔案名
68 | $value2 = str_replace($dir1, $dir2, $value); //要找的檔名
69 | $value2 = str_replace('/', '\\', $value2); //要找的檔名
70 | $value2 = str_replace($sourcelanguage, $targetlanguage, $value2); //要找的檔名
71 |
72 | $sms .= " |結果:";
73 |
74 | $f['target'] = $value2; //目標檔名
75 | $f['dirname'] = substr(dirname($value2), strlen($dir2) + 1); //路徑要去掉相同部分
76 | $f['basename'] = basename($value2); //檔名
77 | //print_r($f);
78 |
79 | $ap = get_translated_word_test($value); //開檔案
80 | $ap['f'] = $f; //檔案相關資訊
81 |
82 | $ap = ai_translated($ap, $sourcelanguage, $targetlanguage, $CT_CONFIG, $sms); //AI翻譯
83 |
84 | //有錯就不做下一步了
85 | if ($ap['error']) {
86 | $sms = $ap['sms'];
87 | } else {
88 | //沒錯才做下一步了
89 | $apend = $ap['ai_result'];
90 | $sms = $ap['sms'];
91 |
92 | //組出檔案內容
93 | $context = '';
94 | $context1p = '';
95 | for ($i = 0; $i < count($apend['a']); $i++) {
96 | $context1p = $apend['a'][$i]; //這沒有換行的
97 | if (trim($apend['c'][$i])) {
98 | //有翻譯才有
99 | $context1p .= " = '" . addslashesB($apend['c'][$i]) . "';"; //由於都用'包覆所以原本有'的要處理
100 | }
101 | if ($context1p == '\n') {
102 | //如果該行是空白只有1個\n
103 | } else {
104 | $context .= $context1p . "\n"; //換行都用\n
105 | }
106 |
107 | }
108 | //有內容才寫檔案
109 | if (trim($context)) {
110 | $sms .= $br;
111 | if (is_file($value2)) {
112 | $sms .= "目標檔案存在" ;
113 | }else{
114 | $sms .= "目標檔案不存在,已自動建立" ;
115 | auto_mkdir($value2);//給檔案路徑自動建立目錄1層1層建立
116 | }
117 | file_put_contents($value2, $context); //寫入檔案
118 | $sms .= " 已寫入檔案";
119 | }
120 | }
121 |
122 | echo $sms . $br;
123 | //exit; //測試做1次就停止
124 | $z['y1']++; //處理檔案次數
125 | }
126 | cmysql($linkID); //關資料庫==============================================================
127 | echo "
" . $br;
128 | echo "處理" . $z['y1'] . "個檔案" . $br;
129 |
--------------------------------------------------------------------------------
/index14_EN_to_vi.php:
--------------------------------------------------------------------------------
1 | \n";
23 |
24 | /*********************************************************************************************/
25 | /*
26 | 翻譯超簡單使用
27 | 如果你有申請過該API-網址直打就會有返回值
28 | //$url='https://translation.googleapis.com/language/translate/v2?key=[請自己去申請KEY]&q=fuck&q=language&target=zh-TW';
29 | 申請KEY的位置
30 | 請通過訪問https://console.developers.google.com/apis/api/translate.googleapis來啟用它 這個 AIP名字叫 Google Cloud Translation API
31 | KEY不能用別人的
32 | */
33 |
34 | $url = 'https://translation.googleapis.com/language/translate/v2?key=' . googleApiKEY;
35 | define('googleapi_url', $url);
36 | /*********************************************************************************************/
37 | $sourcelanguage = 'en-gb'; //來源語言
38 | $targetlanguage = 'vi'; //目標語言
39 |
40 | $dir = dirname(__FILE__) . "\\01"; //要開啟的路徑
41 | $dir1 = $dir . "a"; //來源目錄 放有英文檔案
42 | $dir2 = $dir . "b"; //放有 翻譯過的中文檔案
43 |
44 | /*********************************************************************************************/
45 |
46 | $filenamesA = get_filenamesbydir($dir1); //獲取目錄下所有文件,包括子目錄
47 | $filenamesB = get_filenamesbydir($dir2); //獲取目錄下所有文件,包括子目錄
48 | /*********************************************************************************************/
49 | /* ********************************************************************************************* */
50 | $CT_CONFIG['db_name'] = 't_translation_googleapi'; //要開啟的資料庫
51 | $CT_CONFIG['db_sheet'] = DB_PREFIX . 't'; //子資料表
52 |
53 | $CT_CONFIG['project_name'] = 'opencart'; //專案名稱
54 | $CT_CONFIG['version'] = '2.3.0.2'; //版本號一律4碼
55 |
56 | $linkID = omysql($CT_CONFIG['db_name']); //開資料庫================================================
57 | $CT_CONFIG['linkID'] = $linkID;
58 |
59 | $z = array('y1' => 0, 'y2' => 0);
60 | //打印所有文件名,包括路徑
61 | foreach ($filenamesA as $value) {
62 | $ss = 0;
63 | //這裡不會有目錄名
64 | echo "來源" . $value; //開啟檔案
65 | $sms = '';
66 | $f = array();
67 | //這裡不會有目錄名只有檔案名
68 | $value2 = str_replace($dir1, $dir2, $value); //要找的檔名
69 | $value2 = str_replace('/', '\\', $value2); //要找的檔名
70 | $value2 = str_replace($sourcelanguage, $targetlanguage, $value2); //要找的檔名
71 |
72 | $sms .= " |結果:";
73 |
74 | $f['target'] = $value2; //目標檔名
75 | $f['dirname'] = substr(dirname($value2), strlen($dir2) + 1); //路徑要去掉相同部分
76 | $f['basename'] = basename($value2); //檔名
77 | //print_r($f);
78 |
79 | $ap = get_translated_word_test($value); //開檔案
80 | $ap['f'] = $f; //檔案相關資訊
81 |
82 | $ap = ai_translated($ap, $sourcelanguage, $targetlanguage, $CT_CONFIG, $sms); //AI翻譯
83 |
84 | //有錯就不做下一步了
85 | if ($ap['error']) {
86 | $sms = $ap['sms'];
87 | } else {
88 | //沒錯才做下一步了
89 | $apend = $ap['ai_result'];
90 | $sms = $ap['sms'];
91 |
92 | //組出檔案內容
93 | $context = '';
94 | $context1p = '';
95 | for ($i = 0; $i < count($apend['a']); $i++) {
96 | $context1p = $apend['a'][$i]; //這沒有換行的
97 | if (trim($apend['c'][$i])) {
98 | //有翻譯才有
99 | $context1p .= " = '" . addslashesB($apend['c'][$i]) . "';"; //由於都用'包覆所以原本有'的要處理
100 | }
101 | if ($context1p == '\n') {
102 | //如果該行是空白只有1個\n
103 | } else {
104 | $context .= $context1p . "\n"; //換行都用\n
105 | }
106 |
107 | }
108 | //有內容才寫檔案
109 | if (trim($context)) {
110 | $sms .= $br;
111 | if (is_file($value2)) {
112 | $sms .= "目標檔案存在" ;
113 | }else{
114 | $sms .= "目標檔案不存在,已自動建立" ;
115 | auto_mkdir($value2);//給檔案路徑自動建立目錄1層1層建立
116 | }
117 | file_put_contents($value2, $context); //寫入檔案
118 | $sms .= " 已寫入檔案";
119 | }
120 | }
121 |
122 | echo $sms . $br;
123 | //exit; //測試做1次就停止
124 | $z['y1']++; //處理檔案次數
125 | }
126 | cmysql($linkID); //關資料庫==============================================================
127 | echo "
" . $br;
128 | echo "處理" . $z['y1'] . "個檔案" . $br;
129 |
--------------------------------------------------------------------------------
/index5.php:
--------------------------------------------------------------------------------
1 | read()) {
60 | if ($file != "." && $file != "..") {
61 | get_allfiles($path . "/" . $file, $files);//呼叫自己
62 | }
63 | }
64 | $dp->close();
65 | }
66 | if (is_file($path)) {
67 | $files[] = $path;//只把檔案加進去
68 | }
69 | }
70 |
71 | function get_filenamesbydir($dir)
72 | {
73 | $files = array();
74 | get_allfiles($dir, $files);
75 | return $files;
76 | }
77 |
78 | //翻譯後的取代工作
79 | function translated_and_replaced($str){
80 | if(empty($str))
81 | return '';
82 | $str=str_replace('%','%',$str);
83 | $str=str_replace('?','?',$str);
84 | $str=str_replace('&','&',$str);
85 | return $str;
86 | }
87 | //去除換行字元
88 | function no_r_n($str){
89 | $str=str_replace(PHP_EOL, '', $str);
90 | return $str;
91 | }
92 | //整篇文章要翻譯的字
93 | function get_translated_word_test($file)
94 | {
95 | $files = array();
96 | $file = fopen($file, "r");
97 | //輸出文本中所有的行,直到文件結束為止。
98 | $key = "=";
99 | while (!feof($file)) {
100 | $strs = fgets($file);
101 | //找出字原位置
102 | $leng = strlen($strs);
103 | $place = 0;
104 | for ($i = 0; $i < $leng; $i++) {
105 | $word[$i] = substr($strs, $i, 1);
106 | if ($word[$i] == $key) {
107 | $place = $i;
108 | break;
109 | }
110 | }
111 | if ($place) {
112 | //該行不空白的話
113 | $a=no_r_n(trim(substr($strs, 0, $place)));//換行字元要拿掉
114 | $b=trim(substr($strs, $place + 3));//要翻譯的字
115 | $t = array('a' => $a, 'b' => substr($b,0,-2));
116 | } else {
117 | //沒有=就用原本的字 有可能是 $strs, 'b' => '');
119 | }
120 | $files[] = $t;
121 | }
122 | $a=array();
123 | $b=array();
124 | fclose($file);
125 | for ($i = 0; $i $a,'b'=>$b);
130 | return $files2;
131 | }
132 | /*********************************************************************************************/
133 | $thisDir = "."; //config.inc.php檔的相對路徑
134 | $_file = basename(__FILE__); //自行取得本程式名稱
135 |
136 | $dir = dirname(__FILE__) . "\\01a"; //要開啟的路徑
137 | $targetLanguage = 'zh-TW'; //目標語言
138 |
139 | /*
140 | 翻譯超簡單使用
141 | 如果你有申請過該API-網址直打就會有返回值
142 | //$url='https://translation.googleapis.com/language/translate/v2?key=[請自己去申請KEY]&q=fuck&q=language&target=zh-TW';
143 | 申請KEY的位置
144 | 請通過訪問https://console.developers.google.com/apis/api/translate.googleapis來啟用它 這個 AIP名字叫 Google Cloud Translation API
145 | KEY不能用別人的
146 | */
147 |
148 | $url = 'https://translation.googleapis.com/language/translate/v2?key='.googleApiKEY;
149 | /*********************************************************************************************/
150 |
151 | $filenames = get_filenamesbydir($dir); //獲取目錄下所有文件,包括子目錄
152 |
153 | //打印所有文件名,包括路徑
154 | foreach ($filenames as $value) {
155 | //這裡不會有目錄名
156 | //echo $value . "
";//開啟檔案
157 | $q=array();
158 | $text_array=array();
159 | $iurlq="&target=".$targetLanguage;
160 | $ap = get_translated_word_test($value); //開檔案
161 | //一次送多組
162 | for ($i = 0; $i < count($ap['b']); $i++) {
163 | $iurlq.="&q=".urlencode($ap['b'][$i]);//要翻譯的字要編碼
164 | }
165 | $iurl=$url.$iurlq;
166 | $response = curl_get($iurl);
167 | $data = json_decode($response,true); //接收;
168 | //print_r($iurl);
169 | //print_r($data);
170 |
171 | if(isset($data['error'])){
172 | echo "翻譯失敗";
173 | print_r($data['error']);
174 | exit;
175 | }else{
176 | //翻譯成功
177 | echo "翻譯成功";
178 | //把翻譯內容處理一遍
179 | for ($i = 0; $i < count($data['data']['translations']); $i++) {
180 | $text_array[]=translated_and_replaced($data['data']['translations'][$i]['translatedText']);//翻譯後的取代工作
181 | }
182 | //print_r($text_array);
183 | }
184 | $apend=$ap;
185 | $apend['c']=$text_array;
186 | print_r($apend);
187 | exit;//測試做1次就停止
188 | }
189 |
--------------------------------------------------------------------------------
/index6.php:
--------------------------------------------------------------------------------
1 | read()) {
60 | if ($file != "." && $file != "..") {
61 | get_allfiles($path . "/" . $file, $files); //呼叫自己
62 | }
63 | }
64 | $dp->close();
65 | }
66 | if (is_file($path)) {
67 | $files[] = $path; //只把檔案加進去
68 | }
69 | }
70 |
71 | function get_filenamesbydir($dir)
72 | {
73 | $files = array();
74 | get_allfiles($dir, $files);
75 | return $files;
76 | }
77 |
78 | //翻譯後的取代工作
79 | function translated_and_replaced($str)
80 | {
81 | if (empty($str)) {
82 | return '';
83 | }
84 |
85 | $str = str_replace('%', '%', $str);
86 | $str = str_replace('?', '?', $str);
87 | $str = str_replace('&', '&', $str);
88 | return $str;
89 | }
90 | //去除換行字元
91 | function no_r_n($str)
92 | {
93 | $str = str_replace(PHP_EOL, '', $str);
94 | return $str;
95 | }
96 | //整篇文章要翻譯的字
97 | function get_translated_word_test($file)
98 | {
99 | $files = array();
100 | $file = fopen($file, "r");
101 | //輸出文本中所有的行,直到文件結束為止。
102 | $key = "=";
103 | while (!feof($file)) {
104 | $strs = fgets($file);
105 | //找出字原位置
106 | $leng = strlen($strs);
107 | $place = 0;
108 | for ($i = 0; $i < $leng; $i++) {
109 | $word[$i] = substr($strs, $i, 1);
110 | if ($word[$i] == $key) {
111 | $place = $i;
112 | break;
113 | }
114 | }
115 | if ($place) {
116 | //該行不空白的話
117 | $a = no_r_n(trim(substr($strs, 0, $place))); //換行字元要拿掉
118 | $b = trim(substr($strs, $place + 3)); //要翻譯的字
119 | $t = array('a' => $a, 'b' => substr($b, 0, -2));
120 | } else {
121 | //沒有=就用原本的字 有可能是 $strs, 'b' => '');
123 | }
124 | $files[] = $t;
125 | }
126 | $a = array();
127 | $b = array();
128 | fclose($file);
129 | for ($i = 0; $i < count($files); $i++) {
130 | $a[] = $files[$i]['a'];
131 | $b[] = $files[$i]['b'];
132 | }
133 | $files2 = array('a' => $a, 'b' => $b);
134 | return $files2;
135 | }
136 | /*********************************************************************************************/
137 | /*
138 | 翻譯超簡單使用
139 | 如果你有申請過該API-網址直打就會有返回值
140 | //$url='https://translation.googleapis.com/language/translate/v2?key=[請自己去申請KEY]&q=fuck&q=language&target=zh-TW';
141 | 申請KEY的位置
142 | 請通過訪問https://console.developers.google.com/apis/api/translate.googleapis來啟用它 這個 AIP名字叫 Google Cloud Translation API
143 | KEY不能用別人的
144 | */
145 |
146 | $url = 'https://translation.googleapis.com/language/translate/v2?key='.googleApiKEY;
147 |
148 | /*********************************************************************************************/
149 | $thisDir = "."; //config.inc.php檔的相對路徑
150 | $_file = basename(__FILE__); //自行取得本程式名稱
151 | $br = "
\n";
152 |
153 | $sourceLanguage = 'en-gb'; //來源語言
154 | $targetLanguage = 'zh-TW'; //目標語言
155 |
156 | $dir = dirname(__FILE__) . "\\01"; //要開啟的路徑
157 | $dir1 = $dir . "a"; //來源目錄 放有英文檔案
158 | $dir2 = $dir . "b"; //放有 翻譯過的中文檔案
159 |
160 | /*********************************************************************************************/
161 |
162 | $filenamesA = get_filenamesbydir($dir1); //獲取目錄下所有文件,包括子目錄
163 | $filenamesB = get_filenamesbydir($dir2); //獲取目錄下所有文件,包括子目錄
164 | /*********************************************************************************************/
165 | $z = array('y1' => 0, 'y2' => 0);
166 | //打印所有文件名,包括路徑
167 | foreach ($filenamesA as $value) {
168 | //這裡不會有目錄名
169 | //echo $value . "
";//開啟檔案
170 | $q = array();
171 | $text_array = array();
172 | $iurlq = "&target=" . $targetLanguage;
173 |
174 | $f = array();
175 | //這裡不會有目錄名只有檔案名
176 | $value2 = str_replace($dir1, $dir2, $value); //要找的檔名
177 | $value2 = str_replace('/', '\\', $value2); //要找的檔名
178 | $value2 = str_replace($sourceLanguage, $targetLanguage, $value2); //要找的檔名
179 | echo "目標檔案可寫入檢查" . $value2;
180 | echo " |結果:";
181 | if (is_file($value2)) {
182 | echo "找到檔案" . $br;
183 | $f['target'] = $value2; //目標檔名
184 | $f['dirname'] = substr(dirname($value2), strlen($dir2) + 1); //路徑要去掉相同部分
185 | $f['basename'] = basename($value2); //檔名
186 | //print_r($f);
187 |
188 | $ap = get_translated_word_test($value); //開檔案
189 | //一次送多組
190 | for ($i = 0; $i < count($ap['b']); $i++) {
191 | $iurlq .= "&q=" . urlencode($ap['b'][$i]); //要翻譯的字要編碼
192 | }
193 | $iurl = $url . $iurlq;
194 | $response = curl_get($iurl);
195 | $data = json_decode($response, true); //接收;
196 | //print_r($iurl);
197 | //print_r($data);
198 |
199 | if (isset($data['error'])) {
200 | echo "翻譯失敗";
201 | print_r($data['error']);
202 | exit;
203 | } else {
204 | //翻譯成功
205 | echo "翻譯成功";
206 | //把翻譯內容處理一遍
207 | for ($i = 0; $i < count($data['data']['translations']); $i++) {
208 | $text_array[] = translated_and_replaced($data['data']['translations'][$i]['translatedText']); //翻譯後的取代工作
209 | }
210 | //print_r($text_array);
211 | }
212 | $apend = $ap;
213 | $apend['c'] = $text_array;
214 | $apend['f']=$f;//檔案相關資訊
215 | print_r($apend);
216 | exit; //測試做1次就停止
217 |
218 | //file_put_contents ();//寫入檔案
219 | $z['y1']++;
220 | } else {
221 | echo "沒找到檔案" . $br;
222 | $z['y2']++;
223 | }
224 | }
225 |
--------------------------------------------------------------------------------
/en-gb_com_zh-TW.php:
--------------------------------------------------------------------------------
1 | \n";
19 |
20 | /*********************************************************************************************/
21 | /*
22 | 以翻譯過的字做比對
23 | */
24 | /*********************************************************************************************/
25 | $sourcelanguage = 'en-gb'; //來源語言
26 | $targetlanguage = 'zh-TW'; //目標語言
27 |
28 | $dir = dirname(__FILE__) . "\\01"; //要開啟的路徑
29 | $dir1 = $dir . $sourcelanguage; //來源目錄 放有英文檔案
30 | $dir2 = $dir . $targetlanguage; //放有 翻譯過的中文檔案
31 |
32 | /*********************************************************************************************/
33 |
34 | $filenamesA = get_filenamesbydir($dir1); //獲取目錄下所有文件,包括子目錄
35 | $filenamesB = get_filenamesbydir($dir2); //獲取目錄下所有文件,包括子目錄
36 | /*********************************************************************************************/
37 | /* ********************************************************************************************* */
38 | $CT_CONFIG['db_name'] = 't_translation_googleapi'; //要開啟的資料庫
39 | $CT_CONFIG['db_sheet'] = DB_PREFIX . 't'; //子資料表
40 |
41 | $CT_CONFIG['project_name'] = 'opencart'; //專案名稱
42 | $CT_CONFIG['version'] = '2.3.0.2'; //版本號一律4碼
43 |
44 | //查是否有資料 4 項資料要完全相同
45 | function select_oc_t($dirname, $basename, $var, $targetlanguage, $linkID)
46 | {
47 | $sql = "SELECT * FROM `oc_t` WHERE `dirname` = '$dirname' AND `basename` ='$basename' AND `var` = '$var' AND `targetlanguage` = '$targetlanguage'";
48 | $a = assoc_sql1p($sql, $linkID);
49 | return $a;
50 | }
51 |
52 | echo "比對目錄1:" . $dir1 . "有檔案" . count($filenamesA) . "個" . $br;
53 | echo "比對目錄2:" . $dir2 . "有檔案" . count($filenamesB) . "個" . $br;
54 | echo "
" . $br;
55 | $linkID = omysql($CT_CONFIG['db_name']); //開資料庫================================================
56 | $CT_CONFIG['linkID'] = $linkID;
57 |
58 | $z = array('y1' => 0, 'y2' => 0);
59 | $ss = 0;
60 |
61 | //打印所有文件名,包括路徑
62 | foreach ($filenamesA as $value) {
63 | $sss = 0;
64 | //這裡不會有目錄名
65 | //echo "來源" . $value; //開啟檔案
66 | $sms = '';
67 | $f = array();
68 | //這裡不會有目錄名只有檔案名
69 | $value2 = str_replace($dir1, $dir2, $value); //要找的檔名
70 | $value2 = str_replace('/', '\\', $value2); //要找的檔名
71 | $value2 = str_replace($sourcelanguage, $targetlanguage, $value2); //要找的檔名
72 | if (is_file($value2)) {
73 |
74 | //開啟2個檔案
75 | $f['target'] = $value2; //目標檔名
76 | $f['dirname'] = substr(dirname($value2), strlen($dir2) + 1); //路徑要去掉相同部分
77 | $f['basename'] = basename($value2); //檔名
78 | //print_r($f);
79 | $sms .= $f['basename'] . "英文與中文兩個檔案都在,開始比對翻譯:";
80 | $t[$sourcelanguage] = get_translated_word_test($value); //開檔案
81 | $t[$targetlanguage] = get_translated_word_test($value2); //開檔案
82 | $t[$sourcelanguage]['f'] = $f; //檔案相關資訊
83 | //print_r($t);exit;
84 |
85 | $db_name = $CT_CONFIG['db_name'] . '.' . $CT_CONFIG['db_sheet']; //資料表名稱
86 | $linkID = $CT_CONFIG['linkID'];
87 | $project_name = $CT_CONFIG['project_name']; //專案名稱
88 | $version = $CT_CONFIG['project_name']; //版本號
89 | $priority = 1; //優先度
90 |
91 | $tt = $t[$targetlanguage]['b'];
92 | $nono = 0;
93 | $sms .= $br;
94 | //print_r($t);exit;
95 |
96 | //跑一遍只對有值的內容入資料庫
97 | for ($i = 0; $i < count($tt); $i++) {
98 | //這很重要非空值才跑
99 | if (!empty(trim($tt[$i]))) {
100 | //print_r($tt[$i]);
101 | //echo $i,"|",$br;
102 | $io = '';
103 |
104 | $var2 = trim($t[$targetlanguage]['a'][$i]); //比對一定要去除空格
105 |
106 | //該行是註解就不翻譯
107 | if (substr($var2, 0, 2) == '//') {
108 | $sms .= "裡面有註解不翻譯";
109 | } else {
110 | if (isset($t[$sourcelanguage]['a'][$i])) {
111 | $var1 = trim($t[$sourcelanguage]['a'][$i]);//比對一定要去除空格
112 | }else {
113 | $var1 = '';
114 | }
115 |
116 | //目標和來源行數不一致
117 | if ($var1 == $var2) {
118 | $io = $i; //資料會在同1行
119 | } else {
120 | //目標和來源行數不一致
121 | $sms .= "第" . $i . "行來源和目標不一致";
122 | //跑圈回去找-這裡是跑原來語言的圈回
123 | for ($ii = 0; $ii < count($t[$sourcelanguage]['a']); $ii++) {
124 |
125 | $var3 = trim($t[$sourcelanguage]['a'][$ii]); //比對一定要去除空格
126 | if ($var2 == $var3) {
127 | $io = $ii;
128 | $sms .= "重新尋找,在" . $io . "行找到相同資料" . $br;
129 | }
130 | }
131 | }
132 |
133 | if (!empty($io)) {
134 | $dirname = addslashes($t[$sourcelanguage]['f']['dirname']);
135 | $basename = addslashes($t[$sourcelanguage]['f']['basename']);
136 | $var = substr($var2, 4, strlen($var2) - 6); //變數名//以目標版為準
137 |
138 | $sourcetext = addslashes($t[$sourcelanguage]['b'][$io]);
139 | $targettext = addslashes($tt[$i]); //目標語言; 有些不處理 入不了資料庫
140 | //有翻譯檔內容還是原文的情況,這種不要入資料庫
141 | if ($tt[$i] != $t[$sourcelanguage]['b'][$io]) {
142 |
143 | //先查資料是否已建立
144 | $yno = select_oc_t($dirname, $basename, $var, $targetlanguage, $linkID);
145 | if (count($yno) > 0) {
146 | $nono++;
147 | } else {
148 | //新增資料紀錄
149 | $sql = "INSERT INTO $db_name (`t_id`, `project_name`, `version`, `dirname`, `basename`, `var` ,`sourcelanguage`, `sourcetext`, `targetlanguage`, `targettext`, `priority`, `add_date`) VALUES (NULL, '$project_name', '$version','$dirname','$basename','$var','$sourcelanguage','$sourcetext','$targetlanguage','$targettext','$priority', NOW());";
150 | $ok = mysql_insert_i($sql, $linkID);
151 | $oki = ($ok == 1) ? "成功" : "失敗!";
152 | //$sms.="新增資料:".$oki;
153 | $sss++;
154 | if ($ok != 1) {
155 | $sms .= "新增資料錯誤訊息:" . $ok;
156 | }
157 | }
158 | }
159 |
160 | } else {
161 | $sms .= "重新尋找,最終無找到相同資料" . $br;
162 | }
163 |
164 | }
165 |
166 | }
167 | }
168 |
169 | $sms .= "資料庫已有:" . $nono . "筆資料,";
170 | $sms .= "本檔新增資料:" . $sss . "筆" . $br;
171 | } else {
172 | $sms .= "沒有2個檔案都在" . $br;
173 | }
174 | echo $sms . $br;
175 | //exit; //測試做1次就停止
176 | $z['y1']++; //處理檔案次數
177 | $ss = $ss + $sss;
178 | }
179 | cmysql($linkID); //關資料庫==============================================================
180 | echo "
" . $br;
181 | echo "處理" . $z['y1'] . "個檔案" . $br;
182 | echo "一共翻譯" . $ss . "筆記錄" . $br;
183 |
--------------------------------------------------------------------------------
/p_td_lable-control/translate_en.txt:
--------------------------------------------------------------------------------
1 | How much last produt show for as new icon in product box
2 | You can show or hide mini product slider for home page 3
3 | You can Choose 4 type header style for your shop
4 | Category module product show or hide
5 | Home middle free Money Back content
6 | Home News From Blogs
7 | Home News From Blogs content
8 | Home bottom Testimonials Slider
9 | Home bottom Testimonials Slider content
10 | You can choose 3 type home page
11 | Category Page Sidebar
12 | Category left sidebar banner content
13 | Category left sidebar banner
14 | Product page 3 types layout
15 | Header container Bg color
16 | Menu BG color
17 | Menu box shadow color
18 | Menu border color
19 | Menu hover bg color
20 | Primary Color 1
21 | Primary color 2
22 | Primary color 3
23 | Primary color 4
24 | Secendary Color 1
25 | Footer Bg color
26 | Footer Headers color
27 | Footer links color
28 | Footer links hover color
29 | Footer bottom bg color
30 | Footer powered by text color
31 | Background-images
32 | Choose a pattern number
33 | Baackground Attachment
34 | Baackground Repeat
35 | Backgorund Position
36 | Home big slider content
37 | Home big slider
38 | Home big slider bottom promo banner content
39 | Home big slider bottom promo banner
40 | Home Child Fashion (0-5 Years) banner
41 | Home Child Fashion (0-5 Years) Banner Content
42 | Home Kids Fashion (6-12 Years) Banner
43 | Home Kids Fashion (6-12 Years) content
44 | Home Toys & Books (0-12 Years) banner content
45 | Home Toys & Books (0-12 Years) banner content
46 | Home Special Offers banners content
47 | Home Special Offers banners
48 | Home big slider with mini banner
49 | Home big slider bottom mini banner content
50 | Select font source
51 | Body Font to system
52 | Body Font to google
53 | Font size
54 | Select font source
55 | Heading Font to system
56 | Heading Font to google
57 | Text transform
58 | Product headers Font size
59 | Page headers Font size
60 | Left/Right sidebar block headers Font size
61 | Footer headers Font size
62 | Header custom banner 1
63 | Header custom banner 1
64 | Header custom banner 2
65 | Header custom banner 2
66 | Contact information page
67 | Linkedin url
68 | Maestro url
69 | American Express url
70 | New text for produt box
71 | Sale text for produt box
72 | Sale text for compare box
73 | Twitter text for footer
74 | Footer fllow us text
75 | Top Brands Name
76 | Latest category tab all text
77 | Featured Products title home page
78 | Latest Products title home page
79 | Best Sales text for mini Best Sales product title
80 | Special text for home mini Special product title
81 | Top rate product title
82 | Category sidebar title
83 | footer payment accept text
84 |
85 | you can show new item limit for new icon
86 | You can show or hide show scroll to top button
87 | You can show or hide header style for your shop
88 | You can show or hide show scroll to top button
89 | You can show or hide Category module product
90 | Home middle free Money Back content
91 | If you want to show or hide News From Blogs
92 | Custom text under home News From Blogs
93 | If you want to show or hide Home bottom Testimonials Slider
94 | Custom text under home Testimonials Slider content
95 | You can select home page 1.....3
96 | You can show or hide category page subcategory
97 | if you want to changr catalog page default view style
98 | You can show sidebar or without sidebar
99 | You can show Category left sidebar banner
100 | Please put your Category left sidebar banner content
101 | You can choose 3 type product page
102 | You can show or hide custom tab page on product
103 | custom html tab title design to show on product page
104 | custom Html design to show on product page
105 | You can load color scheme
106 | Default color:#FFFFFF . if you want to change this color
107 | Default color:#666666 . if you want to change this color
108 | Default color:#666666 . if you want to change this color
109 | Default color:#000000 . if you want to change this color
110 | Default color:#FFFFFF . if you want to change this color
111 | Default color:#595959 . if you want to change this color
112 | Default color:#dcdcdc. if you want to change this color
113 | Default color:#FFFFFF . if you want to change this color
114 | Default color:#FFFFFF . if you want to change this color
115 | Default color:#eee. if you want to change this color
116 | Default color:#E7E7E7 . if you want to change this color
117 | Default color:#000000 . if you want to change this color
118 | Default color:#333333 . if you want to change this color
119 | Default color:#FBFBFB . if you want to change this color
120 | Default color:#FCEFF1 . if you want to change this color
121 | Default color:#333333. if you want to change this color
122 | Default color:#333333 . if you want to change this color
123 | Default color:#6fc191 . if you want to change this color
124 | Default color:#f37d8a . if you want to change this color
125 | Default color:#77d0e4. if you want to change this color
126 | Default color:#e5b856. if you want to change this color
127 | Default color:#000000. if you want to change this color
128 | Default color:rgba(51, 51, 51, 0.98). if you want to change this color
129 | Default color:#FFFFFF . if you want to change this color
130 | Default color:#8e8e8e. if you want to change this color
131 | Default color:#fff. if you want to change this color
132 | Default color:#rgba(44, 44, 44, 0.98). if you want to change this color
133 | Default color:#8e8e8e. if you want to change this color
134 | If you want to show or hide main body background imags
135 | First upload your pattern catalog/view/theme/babystore/image/theme_patterns/
136 | Please put your home slider content
137 | If you want to show or hide Home big slider bottom promo banner
138 | If you want to show or hide Child Fashion (0-5 Years) banner
139 | Please put your home slider bottom features content
140 | If you want to show or hide Home Kids Fashion (6-12 Years) Banner
141 | Please put your Home Kids Fashion 6-12 Years content
142 | If you want to show or hide Home Kids Fashion (0-12 Years) banner
143 | Please put your Home Kids Fashion (0-12 Years) banner
144 | If you want to show or hide Home Special Offers banners
145 | Please put your Home Special Offers banners content
146 | If you want to show or hide Home big slider with mini banner
147 | Please put your home banner content
148 | If you want to Select font source system/google.
149 | You can change body font style..
150 | You can change body font style.
151 | You can change heading font style..
152 | You can change heading font style.
153 | Please put your message box custom block content
154 | You can show or hide Home message box custom block
155 | Put your facebook page url on this box.
156 | Put your Twitter username.
157 | Tweets counts
158 | Put your Facebook Url
159 | Put your Twitter Url
160 | Put your Google Url
161 | Put your Rss Url
162 | Put your Skype Url
163 | Put your paypal url
164 | Put your visaelectron url
165 | Put your Discover url
166 | Put your Visa url
167 | Put your mastercard url
168 | Put your Maestro url
169 | Put your American Express url
170 | New text for new icon
171 | custom html tab title design to show on product page
172 | custom html tab title design to show on compare page
173 | Footer fllow us text
174 | Check out latest products text home page middle section
175 | Latest category tab all text
176 | Featured Products title home page bottom mini products
177 | Latest Products title home page bottom mini products
178 | Best Sales text for Best Sales product title
179 | Special text for Special product title
180 | Top rate product title
181 | Category sidebar title
182 | footer payment accept text
183 | You can add Google analytics code/another tracking code in this box
184 | Add custom css show in your theme
185 | Add custom jss show in your theme
186 | Home slider
187 | Home big slider with mini banner
188 | Body Font
189 | Headers font
190 | Category Page
191 |
192 | FOOTER
193 | Home slider
194 | Home big slider with mini banner
195 | Body Font
196 | Contact information
197 | Contact information page cpntent
198 | Theme text translator
199 | Layout
200 | Home Page
201 | Category Page
202 | Product page
203 | Load color skin
204 | Main
205 | Main Menu
206 | Global Color
207 | Home page 1
208 | Home page 2
209 | Home page 3
210 | Body font
211 | Headers font
212 | Twitter Feed box.
213 | Contact Information
214 | Social Icons
215 | Powered by
216 | Payment Icon
217 |
218 | Enable
219 | Disable
--------------------------------------------------------------------------------
/README/css/codemirror.css:
--------------------------------------------------------------------------------
1 | /* BASICS */
2 |
3 | .CodeMirror {
4 | /* Set height, width, borders, and global font properties here */
5 | font-family: monospace;
6 | height: 300px;
7 | color: black;
8 | }
9 |
10 | /* PADDING */
11 |
12 | .CodeMirror-lines {
13 | padding: 4px 0; /* Vertical padding around content */
14 | }
15 | .CodeMirror pre {
16 | padding: 0 4px; /* Horizontal padding of content */
17 | }
18 |
19 | .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
20 | background-color: white; /* The little square between H and V scrollbars */
21 | }
22 |
23 | /* GUTTER */
24 |
25 | .CodeMirror-gutters {
26 | border-right: 1px solid #ddd;
27 | background-color: #f7f7f7;
28 | white-space: nowrap;
29 | }
30 | .CodeMirror-linenumbers {}
31 | .CodeMirror-linenumber {
32 | padding: 0 3px 0 5px;
33 | min-width: 20px;
34 | text-align: right;
35 | color: #999;
36 | white-space: nowrap;
37 | }
38 |
39 | .CodeMirror-guttermarker { color: black; }
40 | .CodeMirror-guttermarker-subtle { color: #999; }
41 |
42 | /* CURSOR */
43 |
44 | .CodeMirror div.CodeMirror-cursor {
45 | border-left: 1px solid black;
46 | }
47 | /* Shown when moving in bi-directional text */
48 | .CodeMirror div.CodeMirror-secondarycursor {
49 | border-left: 1px solid silver;
50 | }
51 | .CodeMirror.cm-fat-cursor div.CodeMirror-cursor {
52 | width: auto;
53 | border: 0;
54 | background: #7e7;
55 | }
56 | .CodeMirror.cm-fat-cursor div.CodeMirror-cursors {
57 | z-index: 1;
58 | }
59 |
60 | .cm-animate-fat-cursor {
61 | width: auto;
62 | border: 0;
63 | -webkit-animation: blink 1.06s steps(1) infinite;
64 | -moz-animation: blink 1.06s steps(1) infinite;
65 | animation: blink 1.06s steps(1) infinite;
66 | }
67 | @-moz-keyframes blink {
68 | 0% { background: #7e7; }
69 | 50% { background: none; }
70 | 100% { background: #7e7; }
71 | }
72 | @-webkit-keyframes blink {
73 | 0% { background: #7e7; }
74 | 50% { background: none; }
75 | 100% { background: #7e7; }
76 | }
77 | @keyframes blink {
78 | 0% { background: #7e7; }
79 | 50% { background: none; }
80 | 100% { background: #7e7; }
81 | }
82 |
83 | /* Can style cursor different in overwrite (non-insert) mode */
84 | div.CodeMirror-overwrite div.CodeMirror-cursor {}
85 |
86 | .cm-tab { display: inline-block; text-decoration: inherit; }
87 |
88 | .CodeMirror-ruler {
89 | border-left: 1px solid #ccc;
90 | position: absolute;
91 | }
92 |
93 | /* DEFAULT THEME */
94 |
95 | .cm-s-default .cm-header {color: blue;}
96 | .cm-s-default .cm-quote {color: #090;}
97 | .cm-negative {color: #d44;}
98 | .cm-positive {color: #292;}
99 | .cm-header, .cm-strong {font-weight: bold;}
100 | .cm-em {font-style: italic;}
101 | .cm-link {text-decoration: underline;}
102 | .cm-strikethrough {text-decoration: line-through;}
103 |
104 | .cm-s-default .cm-keyword {color: #708;}
105 | .cm-s-default .cm-atom {color: #219;}
106 | .cm-s-default .cm-number {color: #164;}
107 | .cm-s-default .cm-def {color: #00f;}
108 | .cm-s-default .cm-variable,
109 | .cm-s-default .cm-punctuation,
110 | .cm-s-default .cm-property,
111 | .cm-s-default .cm-operator {}
112 | .cm-s-default .cm-variable-2 {color: #05a;}
113 | .cm-s-default .cm-variable-3 {color: #085;}
114 | .cm-s-default .cm-comment {color: #a50;}
115 | .cm-s-default .cm-string {color: #a11;}
116 | .cm-s-default .cm-string-2 {color: #f50;}
117 | .cm-s-default .cm-meta {color: #555;}
118 | .cm-s-default .cm-qualifier {color: #555;}
119 | .cm-s-default .cm-builtin {color: #30a;}
120 | .cm-s-default .cm-bracket {color: #997;}
121 | .cm-s-default .cm-tag {color: #170;}
122 | .cm-s-default .cm-attribute {color: #00c;}
123 | .cm-s-default .cm-hr {color: #999;}
124 | .cm-s-default .cm-link {color: #00c;}
125 |
126 | .cm-s-default .cm-error {color: #f00;}
127 | .cm-invalidchar {color: #f00;}
128 |
129 | .CodeMirror-composing { border-bottom: 2px solid; }
130 |
131 | /* Default styles for common addons */
132 |
133 | div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
134 | div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
135 | .CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); }
136 | .CodeMirror-activeline-background {background: #e8f2ff;}
137 |
138 | /* STOP */
139 |
140 | /* The rest of this file contains styles related to the mechanics of
141 | the editor. You probably shouldn't touch them. */
142 |
143 | .CodeMirror {
144 | position: relative;
145 | overflow: hidden;
146 | background: white;
147 | }
148 |
149 | .CodeMirror-scroll {
150 | overflow: scroll !important; /* Things will break if this is overridden */
151 | /* 30px is the magic margin used to hide the element's real scrollbars */
152 | /* See overflow: hidden in .CodeMirror */
153 | margin-bottom: -30px; margin-right: -30px;
154 | padding-bottom: 30px;
155 | height: 100%;
156 | outline: none; /* Prevent dragging from highlighting the element */
157 | position: relative;
158 | }
159 | .CodeMirror-sizer {
160 | position: relative;
161 | border-right: 30px solid transparent;
162 | }
163 |
164 | /* The fake, visible scrollbars. Used to force redraw during scrolling
165 | before actuall scrolling happens, thus preventing shaking and
166 | flickering artifacts. */
167 | .CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
168 | position: absolute;
169 | z-index: 6;
170 | display: none;
171 | }
172 | .CodeMirror-vscrollbar {
173 | right: 0; top: 0;
174 | overflow-x: hidden;
175 | overflow-y: scroll;
176 | }
177 | .CodeMirror-hscrollbar {
178 | bottom: 0; left: 0;
179 | overflow-y: hidden;
180 | overflow-x: scroll;
181 | }
182 | .CodeMirror-scrollbar-filler {
183 | right: 0; bottom: 0;
184 | }
185 | .CodeMirror-gutter-filler {
186 | left: 0; bottom: 0;
187 | }
188 |
189 | .CodeMirror-gutters {
190 | position: absolute; left: 0; top: 0;
191 | z-index: 3;
192 | }
193 | .CodeMirror-gutter {
194 | white-space: normal;
195 | height: 100%;
196 | display: inline-block;
197 | margin-bottom: -30px;
198 | /* Hack to make IE7 behave */
199 | *zoom:1;
200 | *display:inline;
201 | }
202 | .CodeMirror-gutter-wrapper {
203 | position: absolute;
204 | z-index: 4;
205 | height: 100%;
206 | }
207 | .CodeMirror-gutter-elt {
208 | position: absolute;
209 | cursor: default;
210 | z-index: 4;
211 | }
212 | .CodeMirror-gutter-wrapper {
213 | -webkit-user-select: none;
214 | -moz-user-select: none;
215 | user-select: none;
216 | }
217 |
218 | .CodeMirror-lines {
219 | cursor: text;
220 | min-height: 1px; /* prevents collapsing before first draw */
221 | }
222 | .CodeMirror pre {
223 | /* Reset some styles that the rest of the page might have set */
224 | -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
225 | border-width: 0;
226 | background: transparent;
227 | font-family: inherit;
228 | font-size: inherit;
229 | margin: 0;
230 | white-space: pre;
231 | word-wrap: normal;
232 | line-height: inherit;
233 | color: inherit;
234 | z-index: 2;
235 | position: relative;
236 | overflow: visible;
237 | -webkit-tap-highlight-color: transparent;
238 | }
239 | .CodeMirror-wrap pre {
240 | word-wrap: break-word;
241 | white-space: pre-wrap;
242 | word-break: normal;
243 | }
244 |
245 | .CodeMirror-linebackground {
246 | position: absolute;
247 | left: 0; right: 0; top: 0; bottom: 0;
248 | z-index: 0;
249 | }
250 |
251 | .CodeMirror-linewidget {
252 | position: relative;
253 | z-index: 2;
254 | overflow: auto;
255 | }
256 |
257 | .CodeMirror-widget {}
258 |
259 | .CodeMirror-code {
260 | outline: none;
261 | }
262 |
263 | /* Force content-box sizing for the elements where we expect it */
264 | .CodeMirror-scroll,
265 | .CodeMirror-sizer,
266 | .CodeMirror-gutter,
267 | .CodeMirror-gutters,
268 | .CodeMirror-linenumber {
269 | -moz-box-sizing: content-box;
270 | box-sizing: content-box;
271 | }
272 |
273 | .CodeMirror-measure {
274 | position: absolute;
275 | width: 100%;
276 | height: 0;
277 | overflow: hidden;
278 | visibility: hidden;
279 | }
280 | .CodeMirror-measure pre { position: static; }
281 |
282 | .CodeMirror div.CodeMirror-cursor {
283 | position: absolute;
284 | border-right: none;
285 | width: 0;
286 | }
287 |
288 | div.CodeMirror-cursors {
289 | visibility: hidden;
290 | position: relative;
291 | z-index: 3;
292 | }
293 | .CodeMirror-focused div.CodeMirror-cursors {
294 | visibility: visible;
295 | }
296 |
297 | .CodeMirror-selected { background: #d9d9d9; }
298 | .CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
299 | .CodeMirror-crosshair { cursor: crosshair; }
300 | .CodeMirror ::selection { background: #d7d4f0; }
301 | .CodeMirror ::-moz-selection { background: #d7d4f0; }
302 |
303 | .cm-searching {
304 | background: #ffa;
305 | background: rgba(255, 255, 0, .4);
306 | }
307 |
308 | /* IE7 hack to prevent it from returning funny offsetTops on the spans */
309 | .CodeMirror span { *vertical-align: text-bottom; }
310 |
311 | /* Used to force a border model for a node */
312 | .cm-force-border { padding-right: .1px; }
313 |
314 | @media print {
315 | /* Hide the cursor when printing */
316 | .CodeMirror div.CodeMirror-cursors {
317 | visibility: hidden;
318 | }
319 | }
320 |
321 | /* See issue #2901 */
322 | .cm-tab-wrap-hack:after { content: ''; }
323 |
324 | /* Help users use markselection to safely style text background */
325 | span.CodeMirror-selectedtext { background: none; }
326 |
--------------------------------------------------------------------------------
/index7.php:
--------------------------------------------------------------------------------
1 | \n";
19 | //送出訊息
20 | //支援SSH的抓檔
21 | function curl_get($url)
22 | {
23 | $ch = @curl_init();
24 | curl_setopt($ch, CURLOPT_URL, $url);
25 | $head[] = "Connection: keep-alive";
26 | $head[] = "Keep-Alive: 300";
27 | $head[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
28 | $head[] = "Accept-Language: en-us,en;q=0.5";
29 | curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36');
30 | curl_setopt($ch, CURLOPT_ENCODING, '');
31 | curl_setopt($ch, CURLOPT_HTTPHEADER, $head);
32 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
33 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
34 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
35 | curl_setopt($ch, CURLOPT_TIMEOUT, 60);
36 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
37 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
38 | $page = curl_exec($ch);
39 | curl_close($ch);
40 | return $page;
41 | }
42 | //送出訊息
43 | function curl_post($url, $post)
44 | {
45 | $ch = curl_init();
46 | curl_setopt($ch, CURLOPT_URL, $url);
47 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
48 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //是否抓取跳轉後的頁面 //一定要開否則會錯
49 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //支援HTTPS
50 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //支援HTTPS
51 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 8); //等代秒數
52 | curl_setopt($ch, CURLOPT_HEADER, false); //不取得返回头信息
53 | curl_setopt($ch, CURLOPT_POST, 1); // 啟用POST
54 | $arrayPOST = http_build_query($post); //送出資料
55 | curl_setopt($ch, CURLOPT_POSTFIELDS, $arrayPOST); //送出資料
56 | curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); //抓圖要設2進制1
57 | $file_contents = curl_exec($ch);
58 | curl_close($ch);
59 | return $file_contents;
60 | }
61 |
62 | //獲取目錄下所有文件,包括子目錄
63 | function get_allfiles($path, &$files)
64 | {
65 | if (is_dir($path)) {
66 | $dp = dir($path);
67 | while ($file = $dp->read()) {
68 | if ($file != "." && $file != "..") {
69 | get_allfiles($path . "/" . $file, $files); //呼叫自己
70 | }
71 | }
72 | $dp->close();
73 | }
74 | if (is_file($path)) {
75 | $files[] = $path; //只把檔案加進去
76 | }
77 | }
78 |
79 | function get_filenamesbydir($dir)
80 | {
81 | $files = array();
82 | get_allfiles($dir, $files);
83 | return $files;
84 | }
85 |
86 | //翻譯後的取代工作
87 | function translated_and_replaced($str)
88 | {
89 | if (empty($str)) {
90 | return '';
91 | }
92 |
93 | $str = str_replace('%', '%', $str);
94 | $str = str_replace('?', '?', $str);
95 | $str = str_replace('&', '&', $str);
96 | $str = str_replace('!', '!', $str);
97 | return $str;
98 | }
99 | //去除換行字元
100 | function no_r_n($str)
101 | {
102 | $str = str_replace(array("\r\n", "\r", "\n"), "", $str);
103 | return $str;
104 | }
105 | //整篇文章要翻譯的字
106 | function get_translated_word_test($file)
107 | {
108 | $files = array();
109 | $file = fopen($file, "r");
110 | //輸出文本中所有的行,直到文件結束為止。
111 | $key = "=";
112 | while (!feof($file)) {
113 | $strs = fgets($file);
114 | //找出字原位置
115 | $leng = strlen($strs);
116 | $place = 0;
117 | for ($i = 0; $i < $leng; $i++) {
118 | $word[$i] = substr($strs, $i, 1);
119 | if ($word[$i] == $key) {
120 | $place = $i;
121 | break;
122 | }
123 | }
124 | if ($place) {
125 | //該行不空白的話
126 | $a = no_r_n(substr($strs, 0, $place)); //換行字元要拿掉
127 | $b = trim(substr($strs, $place + 3)); //要翻譯的字
128 | $t = array('a' => $a, 'b' => substr($b, 0, -2));
129 | } else {
130 | //沒有=就用原本的字 有可能是 no_r_n($strs), 'b' => ''); //換行字元要拿掉
132 | }
133 | $files[] = $t;
134 | }
135 | $a = array();
136 | $b = array();
137 | fclose($file);
138 | for ($i = 0; $i < count($files); $i++) {
139 | $a[] = $files[$i]['a'];
140 | $b[] = $files[$i]['b'];
141 | }
142 | $files2 = array('a' => $a, 'b' => $b);
143 | return $files2;
144 | }
145 |
146 | //單引號處理
147 | function addslashesB($str)
148 | {
149 | $str = str_replace("\'", "'", $str);
150 | $str = str_replace("'", "\'", $str);
151 | return $str;
152 | }
153 |
154 | //新增資料
155 | function add_mysql($apend,$sourceLanguage,$targetLanguage,$CT_CONFIG)
156 | {
157 | $ss=0;
158 | $db_name = $CT_CONFIG['db_name'] . '.' . $CT_CONFIG['db_sheet']; //資料表名稱
159 | $linkID = $CT_CONFIG['linkID'];
160 | for ($i = 0; $i < count($apend['b']); $i++) {
161 | if ($apend['b'][$i]) {
162 | $dirname = addslashes($apend['f']['dirname']);
163 | $basename = $apend['f']['basename'];
164 | $sourcelanguage = $sourceLanguage; //來源語言
165 | $sourcetext = $apend['b'][$i];
166 | $targetanguage = $targetLanguage; //目標語言;
167 | $targettext = $apend['c'][$i];
168 |
169 | //新增資料紀錄
170 | $sql = "INSERT INTO $db_name (`t_id`, `project_name`, `version`, `dirname`, `basename`, `sourcelanguage`, `sourcetext`, `targetanguage`, `targettext`, `priority`, `add_date`) VALUES (NULL, 'opencart', '2.3.0.2','$dirname','$basename','$sourcelanguage','$sourcetext','$targetanguage','$targettext','20', NOW());";
171 | $ok = mysql_insert_i($sql, $linkID);
172 | $oki = ($ok == 1) ? "成功" : "失敗!";
173 | //$sms.="新增資料:".$oki;
174 | $ss++;
175 | if ($ok != 1) {
176 | $sms .= "新增資料錯誤訊息:" . $ok;
177 | }
178 | }
179 | }
180 | return $ss;
181 | }
182 | /*********************************************************************************************/
183 | /*
184 | 翻譯超簡單使用
185 | 如果你有申請過該API-網址直打就會有返回值
186 | //$url='https://translation.googleapis.com/language/translate/v2?key=[請自己去申請KEY]&q=fuck&q=language&target=zh-TW';
187 | 申請KEY的位置
188 | 請通過訪問https://console.developers.google.com/apis/api/translate.googleapis來啟用它 這個 AIP名字叫 Google Cloud Translation API
189 | KEY不能用別人的
190 | */
191 |
192 | $url = 'https://translation.googleapis.com/language/translate/v2?key='.googleApiKEY;
193 | /*********************************************************************************************/
194 | $sourceLanguage = 'en-gb'; //來源語言
195 | $targetLanguage = 'zh-TW'; //目標語言
196 |
197 | $dir = dirname(__FILE__) . "\\01"; //要開啟的路徑
198 | $dir1 = $dir . "a"; //來源目錄 放有英文檔案
199 | $dir2 = $dir . "b"; //放有 翻譯過的中文檔案
200 |
201 | /*********************************************************************************************/
202 |
203 | $filenamesA = get_filenamesbydir($dir1); //獲取目錄下所有文件,包括子目錄
204 | $filenamesB = get_filenamesbydir($dir2); //獲取目錄下所有文件,包括子目錄
205 | /*********************************************************************************************/
206 | /* ********************************************************************************************* */
207 | $CT_CONFIG['db_name'] = 't_translation_googleapi'; //要開啟的資料庫
208 | $CT_CONFIG['db_sheet'] = DB_PREFIX . 't'; //子資料表
209 | $linkID = omysql($CT_CONFIG['db_name']); //開資料庫================================================
210 | $CT_CONFIG['linkID']=$linkID;
211 |
212 | $z = array('y1' => 0, 'y2' => 0);
213 | //打印所有文件名,包括路徑
214 | foreach ($filenamesA as $value) {
215 | $ss = 0;
216 | //這裡不會有目錄名
217 | //echo $value . "
";//開啟檔案
218 | $q = array();
219 | $text_array = array();
220 | $iurlq = "&target=" . $targetLanguage;
221 | $sms = '';
222 | $f = array();
223 | //這裡不會有目錄名只有檔案名
224 | $value2 = str_replace($dir1, $dir2, $value); //要找的檔名
225 | $value2 = str_replace('/', '\\', $value2); //要找的檔名
226 | $value2 = str_replace($sourceLanguage, $targetLanguage, $value2); //要找的檔名
227 | $sms .= "目標檔案可寫入檢查" . $value2;
228 | $sms .= " |結果:";
229 | if (is_file($value2)) {
230 | $sms .= "找到檔案" . $br;
231 | $f['target'] = $value2; //目標檔名
232 | $f['dirname'] = substr(dirname($value2), strlen($dir2) + 1); //路徑要去掉相同部分
233 | $f['basename'] = basename($value2); //檔名
234 | //print_r($f);
235 |
236 | $ap = get_translated_word_test($value); //開檔案
237 |
238 | $sms .= count($ap['b'])."行送翻譯";
239 |
240 | //一次送多組
241 | for ($i = 0; $i < count($ap['b']); $i++) {
242 | $iurlq .= "&q=" . urlencode($ap['b'][$i]); //要翻譯的字要編碼
243 | }
244 | $iurl = $url . $iurlq;
245 | $response = curl_get($iurl);//送翻譯
246 | $data = json_decode($response, true); //接收;
247 | //print_r($iurl);
248 | //print_r($data);
249 |
250 | if (isset($data['error'])) {
251 | echo "翻譯失敗";
252 | print_r($data['error']);
253 | exit;
254 | } else {
255 | //翻譯成功
256 | $sms .= "翻譯成功";
257 | //把翻譯內容處理一遍
258 | for ($i = 0; $i < count($data['data']['translations']); $i++) {
259 | $text_array[] = translated_and_replaced($data['data']['translations'][$i]['translatedText']); //翻譯後的取代工作
260 | }
261 | //print_r($text_array);
262 | }
263 | $apend = $ap;
264 | $apend['c'] = $text_array;
265 | $apend['f'] = $f; //檔案相關資訊
266 | //print_r($apend);
267 | //組出檔案內容
268 | $context = '';
269 | $context1p = '';
270 | for ($i = 0; $i < count($apend['a']); $i++) {
271 | $context1p = $apend['a'][$i]; //這沒有換行的
272 | if (trim($apend['c'][$i])) {
273 | //有翻譯才有
274 | $context1p .= " = '" . addslashesB($apend['c'][$i]) . "';"; //由於都用'包覆所以原本有'的要處理
275 | }
276 | if ($context1p == '\n') {
277 | //如果該行是空白只有1個\n
278 | //$context .= "\n";//換行都用\n
279 | } else {
280 | $context .= $context1p . "\n"; //換行都用\n
281 | }
282 |
283 | }
284 | $sms .= " 寫入檔案";
285 | file_put_contents($apend['f']['target'], $context); //寫入檔案
286 | $sms .= " 新增資料紀錄";
287 | $ss=add_mysql($apend,$sourceLanguage,$targetLanguage,$CT_CONFIG);//新增資料紀錄
288 | $sms .= $ss . "筆";
289 | echo $sms . $br;
290 | //exit; //測試做1次就停止
291 |
292 | $z['y1']++;
293 | } else {
294 | echo "沒找到檔案" . $br;
295 | $z['y2']++;
296 | }
297 | }
298 | cmysql($linkID); //關資料庫==============================================================
299 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PHP-GoogleTranslate
2 | # PHP使用Google Translate API來做自動化檔案翻譯工具
3 | -----------------------------
4 | # 前言
5 | -----------------------------
6 | 擁抱全球市場:網站內容多語化一個多國語言平台該怎麼寫
7 | ---
8 | 作者台灣碼農10號工程師
9 |
10 | 我的職業是在台灣當一位碼農,名子不能公開,所以你知道我的代號就好,我的代號是『10號工程師』
11 |
12 | 我不知道各位你們在面試時遇過要真正開發過多語系平台的工程師嗎,有人想找開發過多語系有經驗工程師找了2年還遇不到,等到人就出現在他面前時,還是認為我只是一位普通碼農,
13 |
14 | 好吧,開始說說我編的故事,多語系平台通常都是你先有了一個平台之後,然後你開始想說要擁抱全球市場國際化,然後你在打算將網站改成支援2總語系,然後3總,以此類推到8總以上,可是呢?多語系平台,是一開始沒規劃好後來就很難改的一種架構,如果你是工程師你一定聽過mvc架構優缺點,那麼有多語系支援的平台那就是
15 |
16 | MVC+L多語系架構
17 |
18 | >Model – 數據和組件處理
19 | View – 外觀處理
20 | Controller – 主控制程式
21 | Language – 語言處理
22 |
23 | 了解歸了解,請問你要怎樣實作呢,首先我要請問大家一個問題,多語系共存你要把語言資料放在資料表中還是檔案中,
24 |
25 | 回答用資料庫就可以搞定的是錯誤答案
26 |
27 | 資料表,那麼請問你要增加幾個欄位,答案是1個,你只要用原本的資料表多建1個欄位語系代號,這樣就解決了,但是也有絕對不能放在資料表的東西,選單上面的按鈕文字,可以放在資料庫裡嗎,答案是不應該,應該放在檔案中,也就是商品資料的多語系放在資料表中,選單上面的按鈕文字,應該無論如何放在檔案。
28 |
29 | 我說的有依據嗎?有OPENCART的語言系統就是是這樣幹的
30 |
31 | OPENCART這套購物車系統,它本身就是支援多國語言的,他會依照你後台的語系設定順序先找正體中文的語言檔,找不到才使用預設的英文語系檔
32 | 所以你只要將產生的正體中文的語言檔拷貝至OPENCART這套購物車系統的語言目錄,你就能將你的英文版插件或模板變為機器翻譯的中文版。
33 |
34 | 我們來隨便打開它的一個語言檔來看看
35 | 例如
36 | \admin\language\en-gb\user\user.php 英文語言
37 | \admin\language\ez-TW\user\user.php 繁體中文
38 | ```
39 | 改名成config.php
156 | 2. google翻譯Api key 這要自己去申請
157 | 申請好後再config.php 這個檔裡面改 define('googleApiKEY','自己申請到的KEY');//googleApiKEY
158 | 3. /README/t_translation_googleapi.sql 資料庫匯入後
159 | 4. /_inc/mysql.inc.php 在這個檔裡面設定資料庫帳密
160 | $dbuser = "sincethemachine";
161 | $dbpass = "1234567890";
162 | 5. 程式預設英翻中,要改在程式中改 例如:index10.php
163 |
164 | -----------------------------
165 | # google翻譯API申請網址
166 | -----------------------------
167 | https://cloud.google.com/translate/?hl=zh-tw
168 |
169 |
170 | -----------------------------
171 | # 語言代碼參考
172 | -----------------------------
173 | en-gb 英文
174 | zh-TW 正體中文
175 | zh-CN 簡體中文
176 |
177 | -----------------------------
178 | # 如果你要產生正體中文以外的翻譯檔
179 | -----------------------------
180 |
181 | 例如用 繁體去翻譯成 簡體的話 zh-TW=>zh-CN
182 | 那你目錄下要先放好檔案
183 | \01a\admin\language\zh-TW\
184 | \01b\admin\language\zh-CN\
185 | 另外在index11.php 中這2行要改
186 | $sourcelanguage = 'en-gb'; //來源語言
187 | $targetlanguage = 'zh-TW'; //目標語言
188 |
189 | -----------------------------
190 | # 是不是 任何原檔都可以丟進去翻意
191 | -----------------------------
192 |
193 | 當然不行,每總格式的文件都需要去專門開發
194 |
195 | 這是針對例如OPENCART 這種 MVC+L系統
196 |
197 | 語言檔 是把把陣列 寫成文字檔案這種
198 | = 號左邊的字一定不能翻譯,所以就 一行一行 切割 = 號右邊的字送去翻譯
199 | 然後再用程式組合回來
200 |
201 |
202 |
203 |
204 | | 檔案名稱 |
205 | 作用 |
206 | 作用目錄 |
207 | 重要度 |
208 |
209 |
210 | | 01_test_googlefree.php |
211 | 測試 GOOGLE 翻譯 API 寫法的第一支程式 |
212 | |
213 | |
214 |
215 |
216 | | 01_test_post_googleapi.php |
217 | 測試 GOOGLE 翻譯 API 寫法POST |
218 | |
219 | |
220 |
221 |
222 | | 02_tw_del_01a.php |
223 | 來源目錄要刪除現有翻譯過的中文檔案
224 | 以01a目錄和01zh-TW這2個目錄做比對 |
225 | |
226 | |
227 |
228 |
229 | | en-gb_com_zh-TW.php |
230 |
231 | 如果我有一份翻譯好的英文原版和中文版,比對2個目錄下的檔案,然後將翻譯對照表寫入資料庫,優先權設為1,以後翻譯會先以這分為準 |
232 | 比對01en-gb和01zh-TW這2個目錄 |
233 | 重要 |
234 |
235 |
236 | | index13.php |
237 | AUTO translation file googleapi
238 | 功能把01a目錄下的檔案全翻譯完
239 | 2017/12/5 會先比對資料庫,已有資料的就不會呼叫GOOGLEAPI去查
240 | 2017/12/6 多做沒翻完的提醒
241 | 2017/12/8 目標目錄不用自己建立了程式會自己建立-不論幾層 |
242 | 把01a目錄下的檔案自動翻譯完複製到01b目錄下 |
243 | 重要 |
244 |
245 |
246 | | |
247 | 以下為舊版 |
248 | |
249 | |
250 |
251 |
252 | | index5.php |
253 |
254 |
255 |
256 | 功能:把目錄下的檔案全翻譯完
257 |
258 |
259 | |
260 | |
261 | |
262 |
263 |
264 | | index6.php |
265 | |
266 | |
267 | |
268 |
269 |
270 | | index7.php |
271 | |
272 | |
273 | |
274 |
275 |
276 | | index8.php |
277 | |
278 | |
279 | |
280 |
281 |
282 | | index9.php |
283 |
284 | 2017/12/5 完工會用資料庫比對查
285 | |
286 | |
287 | |
288 |
289 |
290 | | index10.php |
291 | 資料庫的翻譯也有優先權-以數字小的為優先 |
292 | |
293 | |
294 |
295 |
296 | | index11.php |
297 |
298 | 2017/12/6 多做沒翻完的提醒
299 | |
300 | |
301 | |
302 |
303 |
304 | | index12.php |
305 | 2017/12/8 目標目錄不用自己建立了程式會自己建立-不論幾層 |
306 | |
307 | |
308 |
309 |
310 |
311 |
312 |
313 | --------------------------------
314 | # 翻譯資料表
315 |
316 | [翻譯資料表結構說明]:https://github.com/suffixbig/PHP-GoogleTranslate/tree/master/README/SQLREADME2.html
317 |
318 | [翻譯資料表SQL]:https://github.com/suffixbig/PHP-GoogleTranslate/tree/master/README/t_translation_googleapi.sql
319 | --------------------------------
320 |
321 | ```php
322 | --
323 | -- 資料表結構 `oc_t`
324 | --
325 |
326 | CREATE TABLE IF NOT EXISTS `oc_t` (
327 | `t_id` int(10) unsigned NOT NULL COMMENT '主鍵',
328 | `project_name` varchar(30) DEFAULT NULL COMMENT '專案名',
329 | `version` varchar(10) DEFAULT NULL COMMENT '版本號',
330 | `dirname` varchar(100) NOT NULL COMMENT '路徑名稱',
331 | `basename` varchar(30) NOT NULL COMMENT '檔案名稱',
332 | `var` varchar(200) DEFAULT NULL COMMENT '變數名',
333 | `sourcelanguage` varchar(5) NOT NULL COMMENT '來源語言',
334 | `sourcetext` text COMMENT '來源內容',
335 | `targetlanguage` varchar(5) NOT NULL COMMENT '目標語言',
336 | `targettext` text COMMENT '目標內容',
337 | `priority` int(2) unsigned NOT NULL DEFAULT '20' COMMENT '優先度數字越小越大為1的話不可複寫',
338 | `add_date` date NOT NULL COMMENT '資料建立日期'
339 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='翻譯資料表';
340 | ```
341 | -----------------------------
342 | # 本工具github上專案位置
343 | -----------------------------
344 | https://github.com/suffixbig/PHP-GoogleTranslate/
345 |
--------------------------------------------------------------------------------
/index8.php:
--------------------------------------------------------------------------------
1 | \n";
19 | //送出訊息
20 | //支援SSH的抓檔
21 | function curl_get($url)
22 | {
23 | $ch = @curl_init();
24 | curl_setopt($ch, CURLOPT_URL, $url);
25 | $head[] = "Connection: keep-alive";
26 | $head[] = "Keep-Alive: 300";
27 | $head[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
28 | $head[] = "Accept-Language: en-us,en;q=0.5";
29 | curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36');
30 | curl_setopt($ch, CURLOPT_ENCODING, '');
31 | curl_setopt($ch, CURLOPT_HTTPHEADER, $head);
32 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
33 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
34 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
35 | curl_setopt($ch, CURLOPT_TIMEOUT, 60);
36 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
37 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
38 | $page = curl_exec($ch);
39 | curl_close($ch);
40 | return $page;
41 | }
42 | //送出訊息
43 | function curl_post($url, $post)
44 | {
45 | $ch = curl_init();
46 | curl_setopt($ch, CURLOPT_URL, $url);
47 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
48 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //是否抓取跳轉後的頁面 //一定要開否則會錯
49 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //支援HTTPS
50 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //支援HTTPS
51 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 8); //等代秒數
52 | curl_setopt($ch, CURLOPT_HEADER, false); //不取得返回头信息
53 | curl_setopt($ch, CURLOPT_POST, 1); // 啟用POST
54 | $arrayPOST = http_build_query($post); //送出資料
55 | curl_setopt($ch, CURLOPT_POSTFIELDS, $arrayPOST); //送出資料
56 | curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); //抓圖要設2進制1
57 | $file_contents = curl_exec($ch);
58 | curl_close($ch);
59 | return $file_contents;
60 | }
61 |
62 | //獲取目錄下所有文件,包括子目錄
63 | function get_allfiles($path, &$files)
64 | {
65 | if (is_dir($path)) {
66 | $dp = dir($path);
67 | while ($file = $dp->read()) {
68 | if ($file != "." && $file != "..") {
69 | get_allfiles($path . "/" . $file, $files); //呼叫自己
70 | }
71 | }
72 | $dp->close();
73 | }
74 | if (is_file($path)) {
75 | $files[] = $path; //只把檔案加進去
76 | }
77 | }
78 |
79 | function get_filenamesbydir($dir)
80 | {
81 | $files = array();
82 | get_allfiles($dir, $files);
83 | return $files;
84 | }
85 |
86 | //翻譯後的取代工作
87 | function translated_and_replaced($str)
88 | {
89 | if (empty($str)) {
90 | return '';
91 | }
92 |
93 | $str = str_replace('%', '%', $str);
94 | $str = str_replace('?', '?', $str);
95 | $str = str_replace('&', '&', $str);
96 | $str = str_replace('!', '!', $str);
97 | $str = str_replace(':', ': ', $str);//這是1個:號加空格
98 | return $str;
99 | }
100 | //去除換行字元
101 | function no_r_n($str)
102 | {
103 | $str = str_replace(array("\r\n", "\r", "\n"), "", $str);
104 | return $str;
105 | }
106 | //整篇文章要翻譯的字
107 | function get_translated_word_test($file)
108 | {
109 | $files = array();
110 | $file = fopen($file, "r");
111 | //輸出文本中所有的行,直到文件結束為止。
112 | $key = "=";
113 | while (!feof($file)) {
114 | $strs = fgets($file);
115 | //找出字原位置
116 | $leng = strlen($strs);
117 | $place = 0;
118 | for ($i = 0; $i < $leng; $i++) {
119 | $word[$i] = substr($strs, $i, 1);
120 | if ($word[$i] == $key) {
121 | $place = $i;
122 | break;
123 | }
124 | }
125 | if ($place) {
126 | //該行不空白的話
127 | $a = no_r_n(substr($strs, 0, $place)); //換行字元要拿掉
128 | $b = trim(substr($strs, $place + 3)); //要翻譯的字
129 | $t = array('a' => $a, 'b' => substr($b, 0, -2));
130 | } else {
131 | //沒有=就用原本的字 有可能是 no_r_n($strs), 'b' => ''); //換行字元要拿掉
133 | }
134 | $files[] = $t;
135 | }
136 | $a = array();
137 | $b = array();
138 | fclose($file);
139 | for ($i = 0; $i < count($files); $i++) {
140 | $a[] = $files[$i]['a'];
141 | $b[] = $files[$i]['b'];
142 | }
143 | $files2 = array('a' => $a, 'b' => $b);
144 | return $files2;
145 | }
146 |
147 | //單引號處理
148 | function addslashesB($str)
149 | {
150 | $str = str_replace("\'", "'", $str);
151 | $str = str_replace("'", "\'", $str);
152 | return $str;
153 | }
154 |
155 | //新增資料
156 | function add_mysql($apend, $sourceLanguage, $targetLanguage, $CT_CONFIG)
157 | {
158 | $ss = 0;
159 | $db_name = $CT_CONFIG['db_name'] . '.' . $CT_CONFIG['db_sheet']; //資料表名稱
160 | $linkID = $CT_CONFIG['linkID'];
161 | for ($i = 0; $i < count($apend['b']); $i++) {
162 | if ($apend['b'][$i]) {
163 | $dirname = addslashes($apend['f']['dirname']);
164 | $basename = $apend['f']['basename'];
165 | $sourcelanguage = $sourceLanguage; //來源語言
166 | $sourcetext = $apend['b'][$i];
167 | $targetanguage = $targetLanguage; //目標語言;
168 | $targettext = $apend['c'][$i];
169 |
170 | //新增資料紀錄
171 | $sql = "INSERT INTO $db_name (`t_id`, `project_name`, `version`, `dirname`, `basename`, `sourcelanguage`, `sourcetext`, `targetanguage`, `targettext`, `priority`, `add_date`) VALUES (NULL, 'opencart', '2.3.0.2','$dirname','$basename','$sourcelanguage','$sourcetext','$targetanguage','$targettext','20', NOW());";
172 | $ok = mysql_insert_i($sql, $linkID);
173 | $oki = ($ok == 1) ? "成功" : "失敗!";
174 | //$sms.="新增資料:".$oki;
175 | $ss++;
176 | if ($ok != 1) {
177 | $sms .= "新增資料錯誤訊息:" . $ok;
178 | }
179 | }
180 | }
181 | return $ss;
182 | }
183 |
184 |
185 | //智慧翻譯
186 | function ai_translated($ap, $sourceLanguage, $targetLanguage, $CT_CONFIG, $sms)
187 | {
188 | $need_s = array(); //紀錄要翻譯的行數由0開始
189 | $before_translation=array();//翻譯前的
190 | $text_array = array();//翻譯後的
191 | for ($i = 0; $i < count($ap['b']); $i++) {
192 | if(trim($ap['b'][$i])) {
193 | //有內容的行
194 | $need_s[] = $i; //要翻譯的行號
195 | } else {
196 | //空白行不翻
197 | }
198 |
199 | }
200 | $sms .= "一共" . count($ap['b']) . "行,";
201 | $sms .= count($ap['b']) - count($need_s) . "行不翻譯";
202 | $sms .= count($need_s) . "行送翻譯";
203 |
204 |
205 |
206 | $iurlq = "&target=" . $targetLanguage;
207 | //一次送多組
208 | for ($i = 0; $i < count($need_s); $i++) {
209 | //只挑要送出去的行數
210 | $text = $ap['b'][$need_s[$i]];
211 | $before_translation[]=$text;//這個下面要用
212 | $iurlq .= "&q=" . urlencode($text); //要翻譯的字要編碼
213 | }
214 | $iurl = googleapi_url . $iurlq;
215 | $response = curl_get($iurl); //送翻譯
216 | $data = json_decode($response, true); //接收;
217 |
218 | if (isset($data['error'])) {
219 | echo "翻譯失敗";
220 | print_r($data['error']);
221 | exit;
222 | } else {
223 | //翻譯成功
224 | $sms .= "翻譯成功";
225 | //把翻譯內容處理一遍
226 | for ($i = 0; $i < count($data['data']['translations']); $i++) {
227 | $text_array[] = translated_and_replaced($data['data']['translations'][$i]['translatedText']); //翻譯後的取代工作
228 | }
229 |
230 | $sms .= " 新增資料紀錄";
231 | $apend=array();
232 | $apend['f']=$ap['f'];
233 | $apend['b']=$before_translation;//翻譯前的
234 | $apend['c']=$text_array;//翻譯後的
235 | $ss = add_mysql($apend, $sourceLanguage, $targetLanguage, $CT_CONFIG); //新增資料紀錄
236 | $sms .= $ss . "筆";
237 | }
238 |
239 |
240 | //挑回內容
241 | $cc1=$ap['b'];
242 | for ($i = 0; $i < count($need_s); $i++) {
243 | //只挑要送出去的行數取代
244 | $cc1[$need_s[$i]] = $text_array[$i];
245 | }
246 | /*
247 | echo $sms;
248 | print_r($iurl);
249 | print_r($text_array);
250 | print_r($data);
251 | exit;
252 | */
253 | $ap['c'] = $cc1;//原數組增加
254 | $a['sms'] = $sms;
255 | $a['ai_result'] = $ap;
256 |
257 | return $a;
258 | }
259 | /*********************************************************************************************/
260 | /*
261 | 翻譯超簡單使用
262 | 如果你有申請過該API-網址直打就會有返回值
263 | //$url='https://translation.googleapis.com/language/translate/v2?key=[請自己去申請KEY]&q=fuck&q=language&target=zh-TW';
264 | 申請KEY的位置
265 | 請通過訪問https://console.developers.google.com/apis/api/translate.googleapis來啟用它 這個 AIP名字叫 Google Cloud Translation API
266 | KEY不能用別人的
267 | */
268 |
269 | $url = 'https://translation.googleapis.com/language/translate/v2?key='.googleApiKEY;
270 | define('googleapi_url', $url);
271 | /*********************************************************************************************/
272 | $sourceLanguage = 'en-gb'; //來源語言
273 | $targetLanguage = 'zh-TW'; //目標語言
274 |
275 | $dir = dirname(__FILE__) . "\\01"; //要開啟的路徑
276 | $dir1 = $dir . "a"; //來源目錄 放有英文檔案
277 | $dir2 = $dir . "b"; //放有 翻譯過的中文檔案
278 |
279 | /*********************************************************************************************/
280 |
281 | $filenamesA = get_filenamesbydir($dir1); //獲取目錄下所有文件,包括子目錄
282 | $filenamesB = get_filenamesbydir($dir2); //獲取目錄下所有文件,包括子目錄
283 | /*********************************************************************************************/
284 | /* ********************************************************************************************* */
285 | $CT_CONFIG['db_name'] = 't_translation_googleapi'; //要開啟的資料庫
286 | $CT_CONFIG['db_sheet'] = DB_PREFIX . 't'; //子資料表
287 | $linkID = omysql($CT_CONFIG['db_name']); //開資料庫================================================
288 | $CT_CONFIG['linkID'] = $linkID;
289 |
290 | $z = array('y1' => 0, 'y2' => 0);
291 | //打印所有文件名,包括路徑
292 | foreach ($filenamesA as $value) {
293 | $ss = 0;
294 | //這裡不會有目錄名
295 | //echo $value . "
";//開啟檔案
296 | $sms = '';
297 | $f = array();
298 | //這裡不會有目錄名只有檔案名
299 | $value2 = str_replace($dir1, $dir2, $value); //要找的檔名
300 | $value2 = str_replace('/', '\\', $value2); //要找的檔名
301 | $value2 = str_replace($sourceLanguage, $targetLanguage, $value2); //要找的檔名
302 | $sms .= "目標檔案可寫入檢查" . $value2;
303 | $sms .= " |結果:";
304 | if (is_file($value2)) {
305 | $sms .= "找到檔案" . $br;
306 | $f['target'] = $value2; //目標檔名
307 | $f['dirname'] = substr(dirname($value2), strlen($dir2) + 1); //路徑要去掉相同部分
308 | $f['basename'] = basename($value2); //檔名
309 | //print_r($f);
310 |
311 | $ap = get_translated_word_test($value); //開檔案
312 | $ap['f'] = $f; //檔案相關資訊
313 |
314 | $ap = ai_translated($ap, $sourceLanguage, $targetLanguage, $CT_CONFIG, $sms); //AI翻譯
315 | $apend = $ap['ai_result'];
316 | $sms = $ap['sms'];
317 | //print_r($apend);
318 | //exit;
319 |
320 | //組出檔案內容
321 | $context = '';
322 | $context1p = '';
323 | for ($i = 0; $i < count($apend['a']); $i++) {
324 | $context1p = $apend['a'][$i]; //這沒有換行的
325 | if (trim($apend['c'][$i])) {
326 | //有翻譯才有
327 | $context1p .= " = '" . addslashesB($apend['c'][$i]) . "';"; //由於都用'包覆所以原本有'的要處理
328 | }
329 | if ($context1p == '\n') {
330 | //如果該行是空白只有1個\n
331 | //$context .= "\n";//換行都用\n
332 | } else {
333 | $context .= $context1p . "\n"; //換行都用\n
334 | }
335 |
336 | }
337 | $sms .= " 寫入檔案";
338 | file_put_contents($apend['f']['target'], $context); //寫入檔案
339 | echo $sms . $br;
340 | //exit; //測試做1次就停止
341 |
342 | $z['y1']++;
343 | } else {
344 | echo "沒找到檔案" . $br;
345 | $z['y2']++;
346 | }
347 | }
348 | cmysql($linkID); //關資料庫==============================================================
349 |
--------------------------------------------------------------------------------
/index9.php:
--------------------------------------------------------------------------------
1 | \n";
19 | //送出訊息
20 | //支援SSH的抓檔
21 | function curl_get($url)
22 | {
23 | $ch = @curl_init();
24 | curl_setopt($ch, CURLOPT_URL, $url);
25 | $head[] = "Connection: keep-alive";
26 | $head[] = "Keep-Alive: 300";
27 | $head[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
28 | $head[] = "Accept-Language: en-us,en;q=0.5";
29 | curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36');
30 | curl_setopt($ch, CURLOPT_ENCODING, '');
31 | curl_setopt($ch, CURLOPT_HTTPHEADER, $head);
32 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
33 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
34 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
35 | curl_setopt($ch, CURLOPT_TIMEOUT, 60);
36 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
37 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
38 | $page = curl_exec($ch);
39 | curl_close($ch);
40 | return $page;
41 | }
42 | //送出訊息
43 | function curl_post($url, $post)
44 | {
45 | $ch = curl_init();
46 | curl_setopt($ch, CURLOPT_URL, $url);
47 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
48 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //是否抓取跳轉後的頁面 //一定要開否則會錯
49 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //支援HTTPS
50 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //支援HTTPS
51 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 8); //等代秒數
52 | curl_setopt($ch, CURLOPT_HEADER, false); //不取得返回头信息
53 | curl_setopt($ch, CURLOPT_POST, 1); // 啟用POST
54 | $arrayPOST = http_build_query($post); //送出資料
55 | curl_setopt($ch, CURLOPT_POSTFIELDS, $arrayPOST); //送出資料
56 | curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); //抓圖要設2進制1
57 | $file_contents = curl_exec($ch);
58 | curl_close($ch);
59 | return $file_contents;
60 | }
61 |
62 | //獲取目錄下所有文件,包括子目錄
63 | function get_allfiles($path, &$files)
64 | {
65 | if (is_dir($path)) {
66 | $dp = dir($path);
67 | while ($file = $dp->read()) {
68 | if ($file != "." && $file != "..") {
69 | get_allfiles($path . "/" . $file, $files); //呼叫自己
70 | }
71 | }
72 | $dp->close();
73 | }
74 | if (is_file($path)) {
75 | $files[] = $path; //只把檔案加進去
76 | }
77 | }
78 |
79 | function get_filenamesbydir($dir)
80 | {
81 | $files = array();
82 | get_allfiles($dir, $files);
83 | return $files;
84 | }
85 |
86 | //翻譯後的取代工作
87 | function translated_and_replaced($str)
88 | {
89 | if (empty($str)) {
90 | return '';
91 | }
92 |
93 | $str = str_replace('%', '%', $str);
94 | $str = str_replace('?', '?', $str);
95 | $str = str_replace('&', '&', $str);
96 | $str = str_replace('!', '!', $str);
97 | $str = str_replace(':', ': ', $str); //這是1個:號加空格
98 | return $str;
99 | }
100 | //去除換行字元
101 | function no_r_n($str)
102 | {
103 | $str = str_replace(array("\r\n", "\r", "\n"), "", $str);
104 | return $str;
105 | }
106 | //整篇文章要翻譯的字
107 | function get_translated_word_test($file)
108 | {
109 | $files = array();
110 | $file = fopen($file, "r");
111 | //輸出文本中所有的行,直到文件結束為止。
112 | $key = "=";
113 | while (!feof($file)) {
114 | $strs = fgets($file);
115 | //找出字原位置
116 | $leng = strlen($strs);
117 | $place = 0;
118 | for ($i = 0; $i < $leng; $i++) {
119 | $word[$i] = substr($strs, $i, 1);
120 | if ($word[$i] == $key) {
121 | $place = $i;
122 | break;
123 | }
124 | }
125 | if ($place) {
126 | //該行不空白的話
127 | $a = no_r_n(substr($strs, 0, $place)); //換行字元要拿掉
128 | $b = trim(substr($strs, $place + 3)); //要翻譯的字
129 | $t = array('a' => $a, 'b' => substr($b, 0, -2));
130 | } else {
131 | //沒有=就用原本的字 有可能是 no_r_n($strs), 'b' => ''); //換行字元要拿掉
133 | }
134 | $files[] = $t;
135 | }
136 | $a = array();
137 | $b = array();
138 | fclose($file);
139 | for ($i = 0; $i < count($files); $i++) {
140 | $a[] = $files[$i]['a'];
141 | $b[] = $files[$i]['b'];
142 | }
143 | $files2 = array('a' => $a, 'b' => $b);
144 | return $files2;
145 | }
146 |
147 | //單引號處理
148 | function addslashesB($str)
149 | {
150 | $str = str_replace("\'", "'", $str);
151 | $str = str_replace("'", "\'", $str);
152 | return $str;
153 | }
154 |
155 | //新增資料
156 | function add_mysqltranslation($apend, $sourcelanguage, $targetlanguage, $CT_CONFIG, $sms = '')
157 | {
158 | $ss = 0;
159 | $db_name = $CT_CONFIG['db_name'] . '.' . $CT_CONFIG['db_sheet']; //資料表名稱
160 | $linkID = $CT_CONFIG['linkID'];
161 | $project_name = $CT_CONFIG['project_name']; //專案名稱
162 | $version = $CT_CONFIG['project_name']; //版本號
163 |
164 | for ($i = 0; $i < count($apend['b']); $i++) {
165 | if ($apend['b'][$i]) {
166 | $dirname = addslashes($apend['f']['dirname']);
167 | $basename = $apend['f']['basename'];
168 | $sourcelanguage = $sourcelanguage; //來源語言
169 | $sourcetext = $apend['b'][$i];
170 | $targetlanguage = $targetlanguage; //目標語言;
171 |
172 | //可能會有沒有翻譯的情況這種不要記錄
173 | if (empty($apend['c'][$i])) {
174 | $sms .= "發生GOOGLE翻譯無回傳:" . $sourcetext . "\n";
175 | } else {
176 | $targettext = $apend['c'][$i];
177 | //新增資料紀錄
178 | $sql = "INSERT INTO $db_name (`t_id`, `project_name`, `version`, `dirname`, `basename`, `sourcelanguage`, `sourcetext`, `targetlanguage`, `targettext`, `priority`, `add_date`) VALUES (NULL, '$project_name', '$version','$dirname','$basename','$sourcelanguage','$sourcetext','$targetlanguage','$targettext','20', NOW());";
179 | $ok = mysql_insert_i($sql, $linkID);
180 | $oki = ($ok == 1) ? "成功" : "失敗!";
181 | //$sms.="新增資料:".$oki;
182 | $ss++;
183 | if ($ok != 1) {
184 | $sms .= "新增資料錯誤訊息:" . $ok;
185 | }
186 | }
187 | }
188 | }
189 | return $ss;
190 | }
191 |
192 | //查詢資料庫的翻譯 這沒辦法整批查 只能1行1行查
193 | function q_data_translation($sourcetext, $sourcelanguage, $targetlanguage, $CT_CONFIG, $f = array('dirname' => '', 'basename' => ''))
194 | {
195 | $dirname = $f['dirname'];
196 | $basename = $f['basename'];
197 | $db_name = $CT_CONFIG['db_name'] . '.' . $CT_CONFIG['db_sheet']; //資料表名稱
198 | $linkID = $CT_CONFIG['linkID'];
199 | $sourcetext = addslashes($sourcetext);
200 | $sql = "SELECT `targettext` FROM `oc_t` WHERE `sourcelanguage` = '$sourcelanguage' AND `targetlanguage` = '$targetlanguage' AND `sourcetext` = '$sourcetext' ORDER BY `oc_t`.`priority` ASC";
201 | $date = row_sql1p($sql, 0, $linkID);
202 | return $date;
203 | }
204 |
205 | //智慧翻譯
206 | function ai_translated($ap, $sourcelanguage, $targetlanguage, $CT_CONFIG, $sms)
207 | {
208 | $need_s = array(); //紀錄要翻譯的行數由0開始
209 | $before_translation = array(); //送去GOOGLE翻譯前的
210 | $text_array = array(); //翻譯後的
211 | for ($i = 0; $i < count($ap['b']); $i++) {
212 | if (trim($ap['b'][$i])) {
213 | //有內容的行
214 | $need_s[] = $i; //要翻譯的行號
215 | } else {
216 | //空白行不翻
217 | }
218 |
219 | }
220 |
221 | //查資料庫-看是否翻譯過
222 | $rs = array();
223 | $yourself_translated = $ap['b'];
224 | for ($i = 0; $i < count($need_s); $i++) {
225 | //只挑要送出去的行數
226 | $sourcetext = $ap['b'][$need_s[$i]];
227 | //查詢資料庫
228 | $r = q_data_translation($sourcetext, $sourcelanguage, $targetlanguage, $CT_CONFIG, $ap['f']);
229 | if ($r) {
230 | //有查道的話
231 | $yourself_translated[$need_s[$i]] = $r; //取代字
232 | $rs[] = $need_s[$i]; //放查到的行數
233 | }
234 | }
235 |
236 | $need_s2 = array();
237 | //去除資料庫已有的翻譯的行
238 | for ($i = 0; $i < count($need_s); $i++) {
239 | if (in_array($need_s[$i], $rs)) {
240 | } else {
241 | $need_s2[] = $need_s[$i];
242 | }
243 | }
244 |
245 | $sms .= "一共" . count($ap['b']) . "行,";
246 | $sms .= count($ap['b']) - count($need_s) . "行是註解或空白";
247 | $sms .= count($rs) . "行翻譯過";
248 | $sms .= count($need_s2) . "行要送翻譯";
249 |
250 | $a['error'] = 1;
251 | //有要翻譯的才送
252 | if (count($need_s2)) {
253 | $iurlq = "&target=" . $targetlanguage;
254 | //一次送多組
255 | for ($i = 0; $i < count($need_s2); $i++) {
256 | //只挑要送出去的行數
257 | $text = $ap['b'][$need_s2[$i]];
258 | $before_translation[] = $text; //這個下面要用
259 | $iurlq .= "&q=" . urlencode($text); //要翻譯的字要編碼
260 | }
261 | $iurl = googleapi_url . $iurlq;
262 | $response = curl_get($iurl); //送翻譯
263 | if (preg_match("@Error 413@", $response)) {
264 | $sms .="。 | 客戶發出的請求太大 GOOGLE 拒絕翻譯 Error 413";
265 | $a['sms'] = $sms;
266 | $a['error'] = 1;
267 | return $a;
268 | } else {
269 | $data = json_decode($response, true); //接收;
270 | if (isset($data['error'])) {
271 | $sms .= "。 | 翻譯參數有問題" . $data['error'];
272 | $a['sms'] = $sms;
273 | $a['error'] = 1;
274 | return $a;
275 | } else {
276 | //翻譯成功
277 | $sms .= "翻譯成功";
278 | //把翻譯內容處理一遍
279 | for ($i = 0; $i < count($data['data']['translations']); $i++) {
280 | $text_array[] = translated_and_replaced($data['data']['translations'][$i]['translatedText']); //翻譯後的取代工作
281 | }
282 |
283 | $sms .= " 新增資料紀錄";
284 | $apend = array();
285 | $apend['f'] = $ap['f'];
286 | $apend['b'] = $before_translation; //翻譯前的
287 | $apend['c'] = $text_array; //翻譯後的
288 | $ss = add_mysqltranslation($apend, $sourcelanguage, $targetlanguage, $CT_CONFIG, $sms); //新增資料紀錄
289 | $sms .= $ss . "筆";
290 | }
291 | //挑回內容
292 | $cc1 = $yourself_translated; //查過自己翻譯過的
293 | for ($i = 0; $i < count($need_s2); $i++) {
294 | //只挑要送出去的行數取代
295 | $cc1[$need_s2[$i]] = $text_array[$i];
296 | }
297 | /*
298 | echo $sms;
299 | print_r($iurl);
300 | print_r($text_array);
301 | print_r($data);
302 | exit;
303 | */
304 | $ap['c'] = $cc1; //原數組增加
305 | $a['sms'] = $sms;
306 | $a['ai_result'] = $ap;
307 | $a['error'] = 0; //此次沒問題
308 | return $a;
309 | }
310 | }
311 | }
312 | /*********************************************************************************************/
313 | /*
314 | 翻譯超簡單使用
315 | 如果你有申請過該API-網址直打就會有返回值
316 | //$url='https://translation.googleapis.com/language/translate/v2?key=[請自己去申請KEY]&q=fuck&q=language&target=zh-TW';
317 | 申請KEY的位置
318 | 請通過訪問https://console.developers.google.com/apis/api/translate.googleapis來啟用它 這個 AIP名字叫 Google Cloud Translation API
319 | KEY不能用別人的
320 | */
321 |
322 | $url = 'https://translation.googleapis.com/language/translate/v2?key='.googleApiKEY;
323 | define('googleapi_url', $url);
324 | /*********************************************************************************************/
325 | $sourcelanguage = 'en-gb'; //來源語言
326 | $targetlanguage = 'zh-TW'; //目標語言
327 |
328 | $dir = dirname(__FILE__) . "\\01"; //要開啟的路徑
329 | $dir1 = $dir . "a"; //來源目錄 放有英文檔案
330 | $dir2 = $dir . "b"; //放有 翻譯過的中文檔案
331 |
332 | /*********************************************************************************************/
333 |
334 | $filenamesA = get_filenamesbydir($dir1); //獲取目錄下所有文件,包括子目錄
335 | $filenamesB = get_filenamesbydir($dir2); //獲取目錄下所有文件,包括子目錄
336 | /*********************************************************************************************/
337 | /* ********************************************************************************************* */
338 | $CT_CONFIG['db_name'] = 't_translation_googleapi'; //要開啟的資料庫
339 | $CT_CONFIG['db_sheet'] = DB_PREFIX . 't'; //子資料表
340 |
341 | $CT_CONFIG['project_name'] = 'opencart'; //專案名稱
342 | $CT_CONFIG['version'] = '2.3.0.2'; //版本號一律4碼
343 |
344 | $linkID = omysql($CT_CONFIG['db_name']); //開資料庫================================================
345 | $CT_CONFIG['linkID'] = $linkID;
346 |
347 | $z = array('y1' => 0, 'y2' => 0);
348 | //打印所有文件名,包括路徑
349 | foreach ($filenamesA as $value) {
350 | $ss = 0;
351 | //這裡不會有目錄名
352 | echo "來源" . $value; //開啟檔案
353 | $sms = '';
354 | $f = array();
355 | //這裡不會有目錄名只有檔案名
356 | $value2 = str_replace($dir1, $dir2, $value); //要找的檔名
357 | $value2 = str_replace('/', '\\', $value2); //要找的檔名
358 | $value2 = str_replace($sourcelanguage, $targetlanguage, $value2); //要找的檔名
359 | $sms .= "目標檔案可寫入檢查" . $value2;
360 | $sms .= " |結果:";
361 | if (is_file($value2)) {
362 | $sms .= "找到檔案" . $br;
363 | $f['target'] = $value2; //目標檔名
364 | $f['dirname'] = substr(dirname($value2), strlen($dir2) + 1); //路徑要去掉相同部分
365 | $f['basename'] = basename($value2); //檔名
366 | //print_r($f);
367 |
368 | $ap = get_translated_word_test($value); //開檔案
369 | $ap['f'] = $f; //檔案相關資訊
370 |
371 | $ap = ai_translated($ap, $sourcelanguage, $targetlanguage, $CT_CONFIG, $sms); //AI翻譯
372 |
373 | //有錯就不做下一步了
374 | if ($ap['error']) {
375 | $sms = $ap['sms'];
376 | } else {
377 | //沒錯才做下一步了
378 | $apend = $ap['ai_result'];
379 | $sms = $ap['sms'];
380 |
381 | //組出檔案內容
382 | $context = '';
383 | $context1p = '';
384 | for ($i = 0; $i < count($apend['a']); $i++) {
385 | $context1p = $apend['a'][$i]; //這沒有換行的
386 | if (trim($apend['c'][$i])) {
387 | //有翻譯才有
388 | $context1p .= " = '" . addslashesB($apend['c'][$i]) . "';"; //由於都用'包覆所以原本有'的要處理
389 | }
390 | if ($context1p == '\n') {
391 | //如果該行是空白只有1個\n
392 | } else {
393 | $context .= $context1p . "\n"; //換行都用\n
394 | }
395 |
396 | }
397 | $sms .= " 寫入檔案";
398 | file_put_contents($apend['f']['target'], $context); //寫入檔案
399 | }
400 |
401 |
402 | echo $sms . $br;
403 | //exit; //測試做1次就停止
404 | $z['y1']++; //處理檔案次數
405 | } else {
406 | echo "沒找到檔案" . $br;
407 | $z['y2']++;
408 | }
409 | }
410 | cmysql($linkID); //關資料庫==============================================================
411 | echo "
".$br;
412 | echo "以處理" . $z['y1'] . "個檔案" . $br;
413 |
--------------------------------------------------------------------------------
/p_td_lable-control/zh-TW/wg24themeoptionpanel.php:
--------------------------------------------------------------------------------
1 | $_['Howmuchlastprodutshowforasnewiconinproductbox'] = '產品盒中最後一個產品顯示為新圖標的數量';
2 | $_['Youcanshoworhideminiproductsliderforhomepage3'] = '您可以顯示或隱藏主頁3的迷你產品輪播';
3 | $_['YoucanChoose4typeheaderstyleforyourshop'] = '你可以選擇4種類型的店頭風格';
4 | $_['Categorymoduleproductshoworhide'] = '類別模塊產品顯示或隱藏';
5 | $_['HomemiddlefreeMoneyBackcontent'] = '首頁中免費退款內容';
6 | $_['HomeNewsFromBlogs'] = '主頁來自博客的新聞';
7 | $_['HomeNewsFromBlogscontent'] = '主頁新聞從博客內容';
8 | $_['HomebottomTestimonialsSlider'] = '主頁底部褒獎輪播';
9 | $_['HomebottomTestimonialsSlidercontent'] = '主頁底部推薦輪播內容';
10 | $_['Youcanchoose3typehomepage'] = '你可以選擇3種類型的主頁';
11 | $_['CategoryPageSidebar'] = '類別目錄側欄';
12 | $_['Categoryleftsidebarbannercontent'] = '類別左側廣告內容';
13 | $_['Categoryleftsidebarbanner'] = '類別左側廣告';
14 | $_['Productpage3typeslayout'] = '產品頁面3種類型的佈局';
15 | $_['HeadercontainerBgcolor'] = '標題容器Bg顏色';
16 | $_['MenuBGcolor'] = '選單BG顏色';
17 | $_['Menuboxshadowcolor'] = '選單框陰影顏色';
18 | $_['Menubordercolor'] = '選單邊框顏色';
19 | $_['Menuhoverbgcolor'] = '選單懸停bg顏色';
20 | $_['PrimaryColor1'] = '原色1';
21 | $_['Primarycolor2'] = '原色2';
22 | $_['Primarycolor3'] = '原色3';
23 | $_['Primarycolor4'] = '原色4';
24 | $_['SecendaryColor1'] = 'Secendary顏色1';
25 | $_['FooterBgcolor'] = '頁尾Bg顏色';
26 | $_['FooterHeaderscolor'] = '頁尾標題顏色';
27 | $_['Footerlinkscolor'] = '頁尾鍊接顏色';
28 | $_['Footerlinkshovercolor'] = '頁尾鍊接懸停顏色';
29 | $_['Footerbottombgcolor'] = '頁尾底部bg顏色';
30 | $_['Footerpoweredbytextcolor'] = '頁尾支持文字顏色';
31 | $_['Backgroundimages'] = '背景圖像';
32 | $_['Chooseapatternnumber'] = '選擇一個模式編號';
33 | $_['BaackgroundAttachment'] = '背景 附件';
34 | $_['BaackgroundRepeat'] = '背景 重複';
35 | $_['BackgorundPosition'] = '背景 位置';
36 | $_['Homebigslidercontent'] = '首頁大輪播';
37 | $_['Homebigslider'] = '首頁大輪播內容';
38 | $_['Homebigsliderbottompromobannercontent'] = '首頁大輪播底部促銷橫幅內容';
39 | $_['Homebigsliderbottompromobanner'] = '首頁大輪播底部促銷橫幅';
40 | $_['HomeChildFashion05Yearsbanner'] = '家庭兒童時裝(0-5歲)的標題';
41 | $_['HomeChildFashion05YearsBannerContent'] = '家庭兒童時裝(0-5歲)橫幅內容';
42 | $_['HomeKidsFashion612YearsBanner'] = '家庭兒童時裝(6-12歲)橫幅';
43 | $_['HomeKidsFashion612Yearscontent'] = '首頁兒童時裝(6-12歲)內容';
44 | $_['HomeToysBooks012Yearsbannercontent'] = '家庭玩具和書籍(0-12 歲)橫幅內容';
45 | $_['HomeToysBooks012Yearsbannercontent'] = '家庭玩具和書籍(0-12 歲)橫幅內容';
46 | $_['HomeSpecialOffersbannerscontent'] = '家特別優惠橫幅內容';
47 | $_['HomeSpecialOffersbanners'] = '家特別優惠橫幅';
48 | $_['Homebigsliderwithminibanner'] = '首頁與迷你橫幅大輪播';
49 | $_['Homebigsliderbottomminibannercontent'] = '首頁大輪播底部迷你橫幅內容';
50 | $_['Selectfontsource'] = '選擇字體來源';
51 | $_['BodyFonttosystem'] = '正文字體到系統';
52 | $_['BodyFonttogoogle'] = '身體字體谷歌';
53 | $_['Fontsize'] = '字體大小';
54 | $_['Selectfontsource'] = '選擇字體來源';
55 | $_['HeadingFonttosystem'] = '標題字體到系統';
56 | $_['HeadingFonttogoogle'] = '標題字體谷歌';
57 | $_['Texttransform'] = '文字轉換';
58 | $_['ProductheadersFontsize'] = '產品標題字體大小';
59 | $_['PageheadersFontsize'] = '頁眉字體大小';
60 | $_['LeftRightsidebarblockheadersFontsize'] = '左/右邊欄塊標題字體大小';
61 | $_['FooterheadersFontsize'] = '頁尾標題字體大小';
62 | $_['Headercustombanner1'] = '標題自定義橫幅1';
63 | $_['Headercustombanner1'] = '標題自定義橫幅1';
64 | $_['Headercustombanner2'] = '標題自定義橫幅2';
65 | $_['Headercustombanner2'] = '標題自定義橫幅2';
66 | $_['Contactinformationpage'] = '聯繫信息頁面';
67 | $_['Linkedinurl'] = 'Linkedin 網址';
68 | $_['Maestrourl'] = 'Maestro 網址';
69 | $_['AmericanExpressurl'] = '美國運通 網址';
70 | $_['Newtextforprodutbox'] = '產品盒的新文字';
71 | $_['Saletextforprodutbox'] = '銷售文字為產品箱子';
72 | $_['Saletextforcomparebox'] = '對比框的銷售文字';
73 | $_['Twittertextforfooter'] = 'Twitter 的腳本文字';
74 | $_['Footerfllowustext'] = '頁尾 聯繫我們 的文字';
75 | $_['TopBrandsName'] = '廠商品牌名稱';
76 | $_['Latestcategorytaballtext'] = '最新類別選項卡所有文字';
77 | $_['FeaturedProductstitlehomepage'] = '推薦產品 標題主頁';
78 | $_['LatestProductstitlehomepage'] = '最新產品 標題主頁';
79 | $_['BestSalestextforminiBestSalesproducttitle'] = '暢銷商品 標題文字';
80 | $_['SpecialtextforhomeminiSpecialproducttitle'] = '特價商品 標題文字';
81 | $_['Toprateproducttitle'] = '最高的產品標題';
82 | $_['Categorysidebartitle'] = '類別側邊欄標題';
83 | $_['footerpaymentaccepttext'] = '頁尾付款接受文字';
84 | $_['youcanshownewitemlimitfornewicon'] = '您可以顯示新圖標的新項目限制';
85 | $_['Youcanshoworhideshowscrolltotopbutton'] = '您可以顯示或隱藏顯示滾動到頂部按鈕';
86 | $_['Youcanshoworhideheaderstyleforyourshop'] = '您可以顯示或隱藏店舖的標題樣式';
87 | $_['Youcanshoworhideshowscrolltotopbutton'] = '您可以顯示或隱藏顯示滾動到頂部按鈕';
88 | $_['YoucanshoworhideCategorymoduleproduct'] = '您可以顯示或隱藏類別模塊產品';
89 | $_['HomemiddlefreeMoneyBackcontent'] = '首頁中免費退款內容';
90 | $_['IfyouwanttoshoworhideNewsFromBlogs'] = '如果您想要顯示或隱藏來自博客的新聞';
91 | $_['CustomtextunderhomeNewsFromBlogs'] = '自家博客下的自定義文字';
92 | $_['IfyouwanttoshoworhideHomebottomTestimonialsSlider'] = '如果你想顯示或隱藏家庭底部推薦輪播';
93 | $_['CustomtextunderhomeTestimonialsSlidercontent'] = '家中的自定義文字推薦輪播內容';
94 | $_['Youcanselecthomepage13'] = '您可以選擇主頁1 ..... 3';
95 | $_['Youcanshoworhidecategorypagesubcategory'] = '您可以顯示或隱藏類別目錄子類別';
96 | $_['ifyouwanttochangrcatalogpagedefaultviewstyle'] = '如果你想改變目錄頁面的默認視圖風格';
97 | $_['Youcanshowsidebarorwithoutsidebar'] = '您可以顯示側邊欄或沒有側邊欄';
98 | $_['YoucanshowCategoryleftsidebarbanner'] = '您可以顯示類別左側邊欄橫幅';
99 | $_['PleaseputyourCategoryleftsidebarbannercontent'] = '請將您的類別左側欄橫幅內容';
100 | $_['Youcanchoose3typeproductpage'] = '你可以選擇3型產品頁面';
101 | $_['Youcanshoworhidecustomtabpageonproduct'] = '您可以在產品上顯示或隱藏 自定義標籤頁';
102 | $_['customhtmltabtitledesigntoshowonproductpage'] = '自定義html標籤標題';
103 | $_['customHtmldesigntoshowonproductpage'] = '自定義Html在產品頁面上顯示';
104 | $_['Youcanloadcolorscheme'] = '您可以加載配色方案';
105 | $_['DefaultcolorFFFFFFifyouwanttochangethiscolor'] = '默認顏色:#FFFFFF。如果你想改變這種顏色';
106 | $_['Defaultcolor666666ifyouwanttochangethiscolor'] = '默認顏色:#666666。如果你想改變這種顏色';
107 | $_['Defaultcolor666666ifyouwanttochangethiscolor'] = '默認顏色:#666666。如果你想改變這種顏色';
108 | $_['Defaultcolor000000ifyouwanttochangethiscolor'] = '默認顏色:#000000。如果你想改變這種顏色';
109 | $_['DefaultcolorFFFFFFifyouwanttochangethiscolor'] = '默認顏色:#FFFFFF。如果你想改變這種顏色';
110 | $_['Defaultcolor595959ifyouwanttochangethiscolor'] = '默認顏色:#595959。如果你想改變這種顏色';
111 | $_['Defaultcolordcdcdcifyouwanttochangethiscolor'] = '默認顏色:#dcdcdc。如果你想改變這種顏色';
112 | $_['DefaultcolorFFFFFFifyouwanttochangethiscolor'] = '默認顏色:#FFFFFF。如果你想改變這種顏色';
113 | $_['DefaultcolorFFFFFFifyouwanttochangethiscolor'] = '默認顏色:#FFFFFF。如果你想改變這種顏色';
114 | $_['Defaultcoloreeeifyouwanttochangethiscolor'] = '默認顏色:#eee。如果你想改變這種顏色';
115 | $_['DefaultcolorE7E7E7ifyouwanttochangethiscolor'] = '默認顏色:#E7E7E7。如果你想改變這種顏色';
116 | $_['Defaultcolor000000ifyouwanttochangethiscolor'] = '默認顏色:#000000。如果你想改變這種顏色';
117 | $_['Defaultcolor333333ifyouwanttochangethiscolor'] = '默認顏色:#333333。如果你想改變這種顏色';
118 | $_['DefaultcolorFBFBFBifyouwanttochangethiscolor'] = '默認顏色:#FBFBFB。如果你想改變這種顏色';
119 | $_['DefaultcolorFCEFF1ifyouwanttochangethiscolor'] = '默認顏色:#FCEFF1。如果你想改變這種顏色';
120 | $_['Defaultcolor333333ifyouwanttochangethiscolor'] = '默認顏色:#333333。如果你想改變這種顏色';
121 | $_['Defaultcolor333333ifyouwanttochangethiscolor'] = '默認顏色:#333333。如果你想改變這種顏色';
122 | $_['Defaultcolor6fc191ifyouwanttochangethiscolor'] = '默認顏色:#6fc191。如果你想改變這種顏色';
123 | $_['Defaultcolorf37d8aifyouwanttochangethiscolor'] = '默認顏色:#f37d8a。如果你想改變這種顏色';
124 | $_['Defaultcolor77d0e4ifyouwanttochangethiscolor'] = '默認顏色:#77d0e4。如果你想改變這種顏色';
125 | $_['Defaultcolore5b856ifyouwanttochangethiscolor'] = '默認顏色:#e5b856。如果你想改變這種顏色';
126 | $_['Defaultcolor000000ifyouwanttochangethiscolor'] = '默認顏色:#000000。如果你想改變這種顏色';
127 | $_['Defaultcolorrgba515151098ifyouwanttochangethiscolor'] = '默認顏色:rgba(51,51,51,0.98)。如果你想改變這種顏色';
128 | $_['DefaultcolorFFFFFFifyouwanttochangethiscolor'] = '默認顏色:#FFFFFF。如果你想改變這種顏色';
129 | $_['Defaultcolor8e8e8eifyouwanttochangethiscolor'] = '默認顏色:#8e8e8e。如果你想改變這種顏色';
130 | $_['Defaultcolorfffifyouwanttochangethiscolor'] = '默認顏色:#fff。如果你想改變這種顏色';
131 | $_['Defaultcolorrgba444444098ifyouwanttochangethiscolor'] = '默認顏色:#rgba(44,44,44,0.98)。如果你想改變這種顏色';
132 | $_['Defaultcolor8e8e8eifyouwanttochangethiscolor'] = '默認顏色:#8e8e8e。如果你想改變這種顏色';
133 | $_['Ifyouwanttoshoworhidemainbodybackgroundimags'] = '如果你想顯示或隱藏主體背景圖像';
134 | $_['Firstuploadyourpatterncatalogviewthemebabystoreimagetheme_patterns'] = '首先上傳到目錄/視圖/主題/ catalog/view/theme/babystore/image/theme_patterns/';
135 | $_['Pleaseputyourhomeslidercontent'] = '請把你的主頁輪播內容';
136 | $_['IfyouwanttoshoworhideHomebigsliderbottompromobanner'] = '如果你想顯示或隱藏首頁大輪播底部促銷橫幅';
137 | $_['IfyouwanttoshoworhideChildFashion05Yearsbanner'] = '如果您想要顯示或隱藏童裝(0-5歲)橫幅';
138 | $_['Pleaseputyourhomesliderbottomfeaturescontent'] = '請將您的主頁輪播底部的功能內容';
139 | $_['IfyouwanttoshoworhideHomeKidsFashion612YearsBanner'] = '如果你想顯示或隱藏家庭兒童時裝(6-12歲)橫幅';
140 | $_['PleaseputyourHomeKidsFashion612Yearscontent'] = '請把你的家庭童裝時裝6-12年的內容';
141 | $_['IfyouwanttoshoworhideHomeKidsFashion012Yearsbanner'] = '如果你想顯示或隱藏家庭兒童時裝(0-12歲)的標題';
142 | $_['PleaseputyourHomeKidsFashion012Yearsbanner'] = '請把你的家庭時尚(0-12歲)的標題';
143 | $_['IfyouwanttoshoworhideHomeSpecialOffersbanners'] = '如果你想顯示或隱藏家庭特別優惠橫幅';
144 | $_['PleaseputyourHomeSpecialOffersbannerscontent'] = '請把你的家庭特別優惠橫幅內容';
145 | $_['IfyouwanttoshoworhideHomebigsliderwithminibanner'] = '如果你想用迷你橫幅顯示或隱藏首頁大輪播';
146 | $_['Pleaseputyourhomebannercontent'] = '請放置您的主頁橫幅內容';
147 | $_['IfyouwanttoSelectfontsourcesystemgoogle'] = '如果你想選擇字體源系統/谷歌。';
148 | $_['Youcanchangebodyfontstyle'] = '您可以更改主體字體樣式..';
149 | $_['Youcanchangebodyfontstyle'] = '您可以更改主體字體樣式。';
150 | $_['Youcanchangeheadingfontstyle'] = '您可以更改標題字體樣式..';
151 | $_['Youcanchangeheadingfontstyle'] = '您可以更改標題字體樣式。';
152 | $_['Pleaseputyourmessageboxcustomblockcontent'] = '請把你的消息框自定義塊內容';
153 | $_['YoucanshoworhideHomemessageboxcustomblock'] = '您可以顯示或隱藏主頁消息框自定義塊';
154 | $_['Putyourfacebookpageurlonthisbox'] = '把你的臉書頁面網址放在這個 區塊 裡。';
155 | $_['PutyourTwitterusername'] = '你的Twitter用戶名。';
156 | $_['Tweetscounts'] = '推文計數';
157 | $_['PutyourFacebookUrl'] = '你的 Facebook 網址';
158 | $_['PutyourTwitterUrl'] = '你的 Twitter 網址';
159 | $_['PutyourGoogleUrl'] = '你的 Google 網址';
160 | $_['PutyourRssUrl'] = '你的 Rss 網址';
161 | $_['PutyourSkypeUrl'] = '你的 Skype 網址';
162 | $_['Putyourpaypalurl'] = '你的 PayPal 網址';
163 | $_['Putyourvisaelectronurl'] = '你的 visaelectron 網址';
164 | $_['PutyourDiscoverurl'] = '你的 Discover 網址';
165 | $_['PutyourVisaurl'] = '你的 Visa 網址';
166 | $_['Putyourmastercardurl'] = '你的 萬事達 網址';
167 | $_['PutyourMaestrourl'] = '你的 Maestro 網址';
168 | $_['PutyourAmericanExpressurl'] = '你的 美國運通 網址';
169 | $_['Newtextfornewicon'] = '新圖標的文字';
170 | $_['customhtmltabtitledesigntoshowonproductpage'] = '自定義html標籤標題';
171 | $_['customhtmltabtitledesigntoshowoncomparepage'] = '自定義html標籤標題設計在比較頁面上顯示';
172 | $_['Footerfllowustext'] = '頁尾 聯繫我們 的文字';
173 | $_['Checkoutlatestproductstexthomepagemiddlesection'] = '查看最新產品文字主頁中間部分';
174 | $_['Latestcategorytaballtext'] = '最新類別選項卡所有文字';
175 | $_['FeaturedProductstitlehomepagebottomminiproducts'] = '特色產品標題主頁底部迷你產品';
176 | $_['LatestProductstitlehomepagebottomminiproducts'] = '最新產品標題主頁底部迷你產品';
177 | $_['BestSalestextforBestSalesproducttitle'] = 'Best Sales產品標題的最佳銷售文字';
178 | $_['SpecialtextforSpecialproducttitle'] = '特殊產品標題的特殊文字';
179 | $_['Toprateproducttitle'] = '最高的產品標題';
180 | $_['Categorysidebartitle'] = '類別側邊欄標題';
181 | $_['footerpaymentaccepttext'] = '頁尾付款接受文字';
182 | $_['YoucanaddGoogleanalyticscodeanothertrackingcodeinthisbox'] = '您可以在此框中添加Google分析代碼/其他跟踪代碼';
183 | $_['Addcustomcssshowinyourtheme'] = '在您的主題中添加自定義CSS展示';
184 | $_['Addcustomjssshowinyourtheme'] = '在您的主題中添加自定義jss顯示';
185 | $_['Homeslider'] = '主頁輪播';
186 | $_['Homebigsliderwithminibanner'] = '首頁與迷你橫幅大輪播';
187 | $_['BodyFont'] = '身體字體';
188 | $_['Headersfont'] = '標題字體';
189 | $_['CategoryPage'] = '類別目錄';
190 | $_['FOOTER'] = '頁尾';
191 | $_['Homeslider'] = '主頁輪播';
192 | $_['Homebigsliderwithminibanner'] = '首頁與迷你橫幅大輪播';
193 | $_['BodyFont'] = '身體字體';
194 | $_['Contactinformation'] = '商店聯繫信息';
195 | $_['Contactinformationpagecpntent'] = '商店聯繫信息頁面內容';
196 | $_['Themetexttranslator'] = '主題文字翻譯器';
197 | $_['Layout'] = '佈局';
198 | $_['HomePage'] = '首頁';
199 | $_['CategoryPage'] = '類別目錄';
200 | $_['Productpage'] = '產品頁面';
201 | $_['Loadcolorskin'] = '加載顏色皮膚';
202 | $_['Main'] = '主要';
203 | $_['MainMenu'] = '主選單';
204 | $_['GlobalColor'] = '全局配色';
205 | $_['Homepage1'] = '主頁1';
206 | $_['Homepage2'] = '主頁2';
207 | $_['Homepage3'] = '主頁3';
208 | $_['Bodyfont'] = '正文字體';
209 | $_['Headersfont'] = '標題字體';
210 | $_['TwitterFeedbox'] = 'Twitter Feed框';
211 | $_['ContactInformation'] = '聯繫信息';
212 | $_['SocialIcons'] = '社群圖示';
213 | $_['Poweredby'] = '技術支援訊息';
214 | $_['PaymentIcon'] = '付款圖示';
215 | $_['Enable'] = '開啟';
216 | $_['Disable'] = '關閉';
217 |
--------------------------------------------------------------------------------
/_inc/toolsfunction.php:
--------------------------------------------------------------------------------
1 | $value) {
32 | $fields_string .= 'q=' . urlencode($value) . '&';
33 | //不做urlencode處理也會自動有處理
34 | //長度超過5000字元就中斷 經過測試只能2600
35 | if (strlen($fields_string) >= $s) {
36 | break;
37 | }
38 |
39 | }
40 | $fields_string = rtrim($fields_string, '&'); //去掉最尾的&
41 |
42 | // Open connection
43 | $ch = curl_init();
44 | // Set the url, number of POST vars, POST data
45 | curl_setopt($ch, CURLOPT_URL, $url);
46 | curl_setopt($ch, CURLOPT_POST, count($fields));
47 | curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
48 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
49 | curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
50 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
51 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
52 | //curl_setopt($ch, CURLOPT_USERAGENT, 'AndroidTranslate/5.3.0.RC02.130475354-53000263 5.1 phone TRANSLATE_OPM5_TEST_1');
53 | // Execute post
54 | $result = curl_exec($ch);
55 | // Close connection
56 | curl_close($ch);
57 | return $result;
58 | }
59 |
60 | //獲取目錄下所有文件,包括子目錄
61 | function get_allfiles($path, &$files)
62 | {
63 | if (is_dir($path)) {
64 | $dp = dir($path);
65 | while ($file = $dp->read()) {
66 | if ($file != "." && $file != "..") {
67 | get_allfiles($path . "/" . $file, $files); //呼叫自己
68 | }
69 | }
70 | $dp->close();
71 | }
72 | if (is_file($path)) {
73 | $files[] = $path; //只把檔案加進去
74 | }
75 | }
76 |
77 | function get_filenamesbydir($dir)
78 | {
79 | $files = array();
80 | get_allfiles($dir, $files);
81 | return $files;
82 | }
83 |
84 | //翻譯後的取代工作
85 | function translated_and_replaced($str)
86 | {
87 | if (empty($str)) {
88 | return '';
89 | }
90 | $str = urldecode($str); //解回
91 | $str = str_replace('%', '%', $str);
92 | $str = str_replace('?', '?', $str);
93 | $str = str_replace('&', '&', $str);
94 | $str = str_replace('!', '!', $str);
95 | $str = str_replace(':', ': ', $str); //這是1個:號加空格
96 | $str = str_replace('#', '# ', $str);
97 | $str = str_replace('。', '.', $str);
98 | $str = str_replace('”>“', ' > ', $str);
99 | $str = str_replace('> =', ' >= ', $str);
100 | $str = str_replace('< =', ' <= ', $str);
101 | $str = str_replace('<', ' < ', $str);
102 |
103 | return $str;
104 | }
105 | //去除換行字元
106 | function no_r_n($str)
107 | {
108 | $str = str_replace(array("\r\n", "\r", "\n"), "", $str);
109 | return $str;
110 | }
111 | //整篇文章要翻譯的字
112 | function get_translated_word_test($file)
113 | {
114 | $files = array();
115 | $file = fopen($file, "r");
116 | //輸出文本中所有的行,直到文件結束為止。
117 | $key = "=";
118 | while (!feof($file)) {
119 | $strs = fgets($file);
120 | //找出字原位置
121 | $leng = strlen($strs);
122 | $place = 0;
123 | for ($i = 0; $i < $leng; $i++) {
124 | $word[$i] = substr($strs, $i, 1);
125 | if ($word[$i] == $key) {
126 | $place = $i;
127 | break;
128 | }
129 | }
130 | if ($place) {
131 | //該行不空白的話
132 | $a = no_r_n(substr($strs, 0, $place)); //換行字元要拿掉
133 | $b = trim(substr($strs, $place + 3)); //要翻譯的字
134 | $t = array('a' => $a, 'b' => substr($b, 0, -2));
135 | } else {
136 | //沒有=就用原本的字 有可能是 no_r_n($strs), 'b' => ''); //換行字元要拿掉
138 | }
139 | $files[] = $t;
140 | }
141 | $a = array();
142 | $b = array();
143 | fclose($file);
144 | for ($i = 0; $i < count($files); $i++) {
145 | $a[] = $files[$i]['a'];
146 | $b[] = $files[$i]['b'];
147 | }
148 | $files2 = array('a' => $a, 'b' => $b);
149 | return $files2;
150 | }
151 |
152 | //單引號處理
153 | function addslashesB($str)
154 | {
155 | $str = str_replace("\'", "'", $str);
156 | $str = str_replace("'", "\'", $str);
157 | return $str;
158 | }
159 |
160 | //新增資料
161 | function add_mysqltranslation($apend, $sourcelanguage, $targetlanguage, $CT_CONFIG, $sms = '')
162 | {
163 | $ss = 0;
164 | $db_name = $CT_CONFIG['db_name'] . '.' . $CT_CONFIG['db_sheet']; //資料表名稱
165 | $linkID = $CT_CONFIG['linkID'];
166 | $project_name = $CT_CONFIG['project_name']; //專案名稱
167 | $version = $CT_CONFIG['project_name']; //版本號
168 | $priority = 20;//優先權
169 |
170 | for ($i = 0; $i < count($apend['b']); $i++) {
171 | if ($apend['b'][$i]) {
172 | $dirname = addslashes($apend['f']['dirname']);
173 | $basename = $apend['f']['basename'];
174 | $sourcelanguage = $sourcelanguage; //來源語言
175 | $sourcetext = $apend['b'][$i];
176 | $targetlanguage = $targetlanguage; //目標語言;
177 |
178 | //可能會有沒有翻譯的情況這種不要記錄
179 | if (empty($apend['c'][$i])) {
180 | $sms .= "發生GOOGLE翻譯無回傳:" . $sourcetext . "\n";
181 | } else {
182 | $targettext = $apend['c'][$i];
183 |
184 | $var2 = trim($apend['a'][$i]); //比對一定要去除空格
185 | $var = substr($var2, 4, strlen($var2) - 6); //變數名//以目標版為準
186 | //新增資料紀錄
187 | $sql = "INSERT INTO $db_name (`t_id`, `project_name`, `version`, `dirname`, `basename`, `var` ,`sourcelanguage`, `sourcetext`, `targetlanguage`, `targettext`, `priority`, `add_date`) VALUES (NULL, '$project_name', '$version','$dirname','$basename','$var','$sourcelanguage','$sourcetext','$targetlanguage','$targettext','$priority', NOW());";
188 | $ok = mysql_insert_i($sql, $linkID);
189 | //echo $sql;exit;
190 |
191 | $oki = ($ok == 1) ? "成功" : "失敗!";
192 | //$sms.="新增資料:".$oki;
193 | $ss++;
194 | if ($ok != 1) {
195 | $sms .= "新增資料錯誤訊息:" . $ok;
196 | }
197 | }
198 | }
199 | }
200 | return $ss;
201 | }
202 |
203 | //查詢資料庫的翻譯 這沒辦法整批查 只能1行1行查
204 | function q_data_translation($sourcetext, $sourcelanguage, $targetlanguage, $CT_CONFIG, $f = array('dirname' => '', 'basename' => ''))
205 | {
206 | $dirname = $f['dirname'];
207 | $basename = $f['basename'];
208 | $db_name = $CT_CONFIG['db_name'] . '.' . $CT_CONFIG['db_sheet']; //資料表名稱
209 | $linkID = $CT_CONFIG['linkID'];
210 | $sourcetext = addslashes($sourcetext);
211 | $sql = "SELECT `targettext` FROM `oc_t` WHERE `sourcelanguage` = '$sourcelanguage' AND `targetlanguage` = '$targetlanguage' AND `sourcetext` = '$sourcetext' ORDER BY `oc_t`.`priority` ASC";
212 | $date = row_sql1p($sql, 0, $linkID);
213 | return $date;
214 | }
215 |
216 | //智慧翻譯
217 | function ai_translated($ap, $sourcelanguage, $targetlanguage, $CT_CONFIG, $sms)
218 | {
219 | $need_s = array(); //紀錄要翻譯的行數由0開始
220 | $before_translation = array(); //送去GOOGLE翻譯前的
221 | $aa = array(); //原本變數名稱
222 | $text_array = array(); //翻譯後的
223 | for ($i = 0; $i < count($ap['b']); $i++) {
224 | if (trim($ap['b'][$i])) {
225 | //有內容的行
226 | $need_s[] = $i; //要翻譯的行號
227 | } else {
228 | //空白行不翻
229 | }
230 |
231 | }
232 | //print_r($ap);exit;
233 | //查資料庫-看是否翻譯過
234 | $rs = array();
235 | $yourself_translated = $ap['b'];
236 | for ($i = 0; $i < count($need_s); $i++) {
237 | //只挑要送出去的行數
238 | $sourcetext = $ap['b'][$need_s[$i]];
239 | //查詢資料庫
240 | $r = q_data_translation($sourcetext, $sourcelanguage, $targetlanguage, $CT_CONFIG, $ap['f']);
241 | if ($r) {
242 | //有查道的話
243 | $yourself_translated[$need_s[$i]] = $r; //取代字
244 | $rs[] = $need_s[$i]; //放查到的行數
245 | }
246 | }
247 |
248 | $need_s2 = array();
249 | //去除資料庫已有的翻譯的行
250 | for ($i = 0; $i < count($need_s); $i++) {
251 | if (in_array($need_s[$i], $rs)) {
252 | } else {
253 | $need_s2[] = $need_s[$i];
254 | }
255 | }
256 |
257 | $sms .= "一共" . count($ap['b']) . "行,";
258 | $sms .= count($ap['b']) - count($need_s) . "行是註解或空白";
259 | $sms .= count($rs) . "行翻譯過";
260 | $sms .= count($need_s2) . "行要送翻譯";
261 |
262 | $a['error'] = 1;
263 | //有要翻譯的才送
264 | if (count($need_s2)) {
265 | $iurlq = "&target=" . $targetlanguage;
266 | //一次送多組
267 | for ($i = 0; $i < count($need_s2); $i++) {
268 | //只挑要送出去的行數
269 | $text = $ap['b'][$need_s2[$i]];
270 | $before_translation[] = $text; //這個下面要用
271 | $aa[]= $ap['a'][$need_s2[$i]]; //這個下面要用原本變數名稱
272 | }
273 | $iurl = googleapi_url . $iurlq;
274 | $response = curl_post($iurl, $before_translation); //送翻譯
275 | //print_r($iurl);
276 | if (preg_match("@Error 413@", $response)) {
277 | $sms .= "。 | 客戶發出的請求太大 GOOGLE 拒絕翻譯 Error 413";
278 | $a['sms'] = $sms;
279 | $a['error'] = 1;
280 | return $a;
281 | } else if (preg_match("@Error 400@", $response)) {
282 | $sms .= "。 | 您的客戶發出格式不正確或非法的請求。 Error 400";
283 | $a['sms'] = $sms;
284 | $a['error'] = 1;
285 | return $a;
286 | } else {
287 | $data = json_decode($response, true); //接收;
288 | if (isset($data['error'])) {
289 | if ($data['error']['code'] == 400) {
290 | //再送1次翻譯
291 | echo "再送1次翻譯";
292 | $response = curl_post($iurl, $before_translation, 1000); //送翻譯
293 | $data = json_decode($response, true); //接收;
294 |
295 | if (isset($data['error'])) {
296 | if($data['error']['code'] == 400){
297 | $sms .= "。 | 翻譯參數有問題" . json_encode($data['error']);
298 | $a['sms'] = $sms;
299 | }else{
300 | $sms .= "。 | 翻譯錯誤" . json_encode($data['error']);
301 | $a['sms'] = $sms;
302 | }
303 |
304 | $a['error'] = 1;
305 | return $a;
306 | } else {
307 | $sms .= "翻譯成功";
308 | //把翻譯內容處理一遍
309 | for ($i = 0; $i < count($data['data']['translations']); $i++) {
310 | $text_array[] = translated_and_replaced($data['data']['translations'][$i]['translatedText']); //翻譯後的取代工作
311 | }
312 | //注意這相同有2段
313 | $sms .= " 新增資料紀錄";
314 | $apend = array();
315 | $apend['a'] = $aa;//變數名稱
316 | $apend['f'] = $ap['f'];
317 | $apend['b'] = $before_translation; //翻譯前的
318 | $apend['c'] = $text_array; //翻譯後的 入資料庫的字要是處理過的
319 | $ss = add_mysqltranslation($apend, $sourcelanguage, $targetlanguage, $CT_CONFIG, $sms); //新增資料紀錄
320 | $sms .= $ss . "筆";
321 |
322 | }
323 | }
324 | } else {
325 | //翻譯成功
326 | $sms .= "翻譯成功";
327 | //把翻譯內容處理一遍
328 | for ($i = 0; $i < count($data['data']['translations']); $i++) {
329 | $text_array[] = translated_and_replaced($data['data']['translations'][$i]['translatedText']); //翻譯後的取代工作
330 | }
331 |
332 | $sms .= " 新增資料紀錄";
333 | $apend = array();
334 | $apend['a'] = $aa;//變數名稱
335 | $apend['f'] = $ap['f'];
336 | $apend['b'] = $before_translation; //翻譯前的
337 | $apend['c'] = $text_array; //翻譯後的 入資料庫的字要是處理過的
338 | $ss = add_mysqltranslation($apend, $sourcelanguage, $targetlanguage, $CT_CONFIG, $sms); //新增資料紀錄
339 | $sms .= $ss . "筆";
340 | }
341 |
342 | $not_finished = count($need_s2) - count($text_array);
343 | if ($not_finished) {
344 | //數量有差表示沒翻譯完要紅字提醒
345 | $sms .= " 因GOOGLE翻譯字數上限本次尚有 " . $not_finished . "筆未翻譯. ";
346 | }
347 |
348 | //挑回內容
349 | $cc1 = $yourself_translated; //查過自己翻譯後剩下
350 | //只挑要送出去的行數取代
351 | //如果翻譯不完全就會有只有部分 所以次數用$text_array
352 | for ($i = 0; $i < count($text_array); $i++) {
353 | $cc1[$need_s2[$i]] = $text_array[$i];
354 | }
355 |
356 | /*
357 | echo $sms;
358 | print_r($cc1);
359 | print_r($need_s2);
360 | print_r($text_array);
361 | exit;
362 | */
363 | $ap['c'] = $cc1; //原數組增加
364 | $a['sms'] = $sms;
365 | $a['ai_result'] = $ap;
366 | $a['error'] = 0; //此次沒問題
367 | return $a;
368 | }
369 | } else {
370 | //全部翻譯資料庫都有自建好
371 | $ap['c'] = $yourself_translated; //查過自己翻譯過的就好
372 | $a['sms'] = $sms;
373 | $a['ai_result'] = $ap;
374 | $a['error'] = 0; //此次沒問題
375 | return $a;
376 | }
377 | }
378 |
379 | //查路徑目錄在不在,不在就建立目錄
380 | //一層一層 建好目錄
381 | function auto_mkdir($file)
382 | {
383 | $path = '';
384 | $dir = dirname($file);
385 | if (is_dir($dir)) {
386 | //echo "目錄在";
387 | } else {
388 | //echo "目錄不在";
389 | $file = str_replace('\\', '/', $file);
390 | $directories = explode('/', dirname($file));
391 | $s = 0;
392 | foreach ($directories as $directory) {
393 | if ($s == 0) {
394 | $path = $directory;
395 | } else {
396 | $path .= '/' . $directory;
397 | if (!is_dir($path)) {
398 | @mkdir($path, 0777);
399 | }
400 | }
401 | $s++;
402 | }
403 | }
404 | }
405 |
406 |
407 | //====
408 | //txt檔翻譯用
409 | //===
410 |
411 | //空格取代為沒有-變數名稱中不要有空格()號\號
412 | function t_($text)
413 | {
414 | $text2=trim($text);
415 | $text2=str_replace(' ', '',$text2);
416 | $text2=str_replace('&', '',$text2);
417 | $text2=str_replace('?', '',$text2);
418 | $text2=str_replace('^', '',$text2);
419 | $text2=str_replace('*', '',$text2);
420 | $text2=str_replace('#', '',$text2);
421 | $text2=str_replace('~', '',$text2);
422 | $text2=str_replace('-', '',$text2);
423 | $text2=str_replace('!', '',$text2);
424 | $text2=str_replace('/', '',$text2);
425 | $text2=str_replace('+', '',$text2);
426 | $text2=str_replace('%', '',$text2);
427 | $text2=str_replace('\\', '',$text2);
428 | $text2=str_replace("(","",$text2);
429 | $text2=str_replace(")","",$text2);
430 | $text2=str_replace(".","",$text2);
431 | $text2=str_replace("。","",$text2);
432 | $text2=str_replace(",","",$text2);
433 | $text2=str_replace(":","",$text2);
434 | $text2=str_replace(";","",$text2);
435 | return $text2;
436 | }
437 |
438 | //讓空格變整齊以變數長度決定空格數目 參數1變數,參數2最大長度
439 | function tt_($v,$s=53)
440 | {
441 | $text=" ";
442 | $s=53;//預設最常空格多少個;
443 | $s2=strlen(t_($v));//以去除後的字數做計算
444 | //print_r($s2);echo "\n";
445 | $td=$s-($s2+6);
446 |
447 | for($i=0;$i<$td;$i++){
448 | $text.=" ";
449 | }
450 | return $text;
451 | }
--------------------------------------------------------------------------------
/index10.php:
--------------------------------------------------------------------------------
1 | \n";
19 | //送出訊息
20 | //支援SSH的抓檔
21 | function curl_get($url)
22 | {
23 | $ch = @curl_init();
24 | curl_setopt($ch, CURLOPT_URL, $url);
25 | $head[] = "Connection: keep-alive";
26 | $head[] = "Keep-Alive: 300";
27 | $head[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
28 | $head[] = "Accept-Language: en-us,en;q=0.5";
29 | curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36');
30 | curl_setopt($ch, CURLOPT_ENCODING, '');
31 | curl_setopt($ch, CURLOPT_HTTPHEADER, $head);
32 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
33 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
34 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
35 | curl_setopt($ch, CURLOPT_TIMEOUT, 60);
36 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
37 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
38 | $page = curl_exec($ch);
39 | curl_close($ch);
40 | return $page;
41 | }
42 | //送出訊息
43 | function curl_post($url, $fields)
44 | {
45 | //將$post 組成要送過去的字
46 | $fields_string = "";
47 | foreach ($fields as $key => $value) {
48 | $fields_string .= 'q=' . urlencode($value) . '&';
49 | //不做urlencode處理也會自動有處理
50 | //長度超過5000字元就中斷 經過測試只能2600
51 | if (strlen($fields_string) >= 2600) {
52 | break;
53 | }
54 |
55 | }
56 | $fields_string = rtrim($fields_string, '&'); //去掉最尾的&
57 |
58 | // Open connection
59 | $ch = curl_init();
60 | // Set the url, number of POST vars, POST data
61 | curl_setopt($ch, CURLOPT_URL, $url);
62 | curl_setopt($ch, CURLOPT_POST, count($fields));
63 | curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
64 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
65 | curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
66 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
67 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
68 | curl_setopt($ch, CURLOPT_USERAGENT, 'AndroidTranslate/5.3.0.RC02.130475354-53000263 5.1 phone TRANSLATE_OPM5_TEST_1');
69 | // Execute post
70 | $result = curl_exec($ch);
71 | // Close connection
72 | curl_close($ch);
73 | return $result;
74 | }
75 |
76 | //獲取目錄下所有文件,包括子目錄
77 | function get_allfiles($path, &$files)
78 | {
79 | if (is_dir($path)) {
80 | $dp = dir($path);
81 | while ($file = $dp->read()) {
82 | if ($file != "." && $file != "..") {
83 | get_allfiles($path . "/" . $file, $files); //呼叫自己
84 | }
85 | }
86 | $dp->close();
87 | }
88 | if (is_file($path)) {
89 | $files[] = $path; //只把檔案加進去
90 | }
91 | }
92 |
93 | function get_filenamesbydir($dir)
94 | {
95 | $files = array();
96 | get_allfiles($dir, $files);
97 | return $files;
98 | }
99 |
100 | //翻譯後的取代工作
101 | function translated_and_replaced($str)
102 | {
103 | if (empty($str)) {
104 | return '';
105 | }
106 | $str = urldecode($str); //解回
107 | $str = str_replace('%', '%', $str);
108 | $str = str_replace('?', '?', $str);
109 | $str = str_replace('&', '&', $str);
110 | $str = str_replace('!', '!', $str);
111 | $str = str_replace(':', ': ', $str); //這是1個:號加空格
112 | $str = str_replace('#', '# ', $str);
113 | $str = str_replace('。', '.', $str);
114 | $str = str_replace('”>“', ' > ', $str);
115 | $str = str_replace('> =', ' >= ', $str);
116 | $str = str_replace('< =', ' <= ', $str);
117 | $str = str_replace('<', ' < ', $str);
118 |
119 | return $str;
120 | }
121 | //去除換行字元
122 | function no_r_n($str)
123 | {
124 | $str = str_replace(array("\r\n", "\r", "\n"), "", $str);
125 | return $str;
126 | }
127 | //整篇文章要翻譯的字
128 | function get_translated_word_test($file)
129 | {
130 | $files = array();
131 | $file = fopen($file, "r");
132 | //輸出文本中所有的行,直到文件結束為止。
133 | $key = "=";
134 | while (!feof($file)) {
135 | $strs = fgets($file);
136 | //找出字原位置
137 | $leng = strlen($strs);
138 | $place = 0;
139 | for ($i = 0; $i < $leng; $i++) {
140 | $word[$i] = substr($strs, $i, 1);
141 | if ($word[$i] == $key) {
142 | $place = $i;
143 | break;
144 | }
145 | }
146 | if ($place) {
147 | //該行不空白的話
148 | $a = no_r_n(substr($strs, 0, $place)); //換行字元要拿掉
149 | $b = trim(substr($strs, $place + 3)); //要翻譯的字
150 | $t = array('a' => $a, 'b' => substr($b, 0, -2));
151 | } else {
152 | //沒有=就用原本的字 有可能是 no_r_n($strs), 'b' => ''); //換行字元要拿掉
154 | }
155 | $files[] = $t;
156 | }
157 | $a = array();
158 | $b = array();
159 | fclose($file);
160 | for ($i = 0; $i < count($files); $i++) {
161 | $a[] = $files[$i]['a'];
162 | $b[] = $files[$i]['b'];
163 | }
164 | $files2 = array('a' => $a, 'b' => $b);
165 | return $files2;
166 | }
167 |
168 | //單引號處理
169 | function addslashesB($str)
170 | {
171 | $str = str_replace("\'", "'", $str);
172 | $str = str_replace("'", "\'", $str);
173 | return $str;
174 | }
175 |
176 | //新增資料
177 | function add_mysqltranslation($apend, $sourcelanguage, $targetlanguage, $CT_CONFIG, $sms = '')
178 | {
179 | $ss = 0;
180 | $db_name = $CT_CONFIG['db_name'] . '.' . $CT_CONFIG['db_sheet']; //資料表名稱
181 | $linkID = $CT_CONFIG['linkID'];
182 | $project_name = $CT_CONFIG['project_name']; //專案名稱
183 | $version = $CT_CONFIG['project_name']; //版本號
184 |
185 | for ($i = 0; $i < count($apend['b']); $i++) {
186 | if ($apend['b'][$i]) {
187 | $dirname = addslashes($apend['f']['dirname']);
188 | $basename = $apend['f']['basename'];
189 | $sourcelanguage = $sourcelanguage; //來源語言
190 | $sourcetext = $apend['b'][$i];
191 | $targetlanguage = $targetlanguage; //目標語言;
192 |
193 | //可能會有沒有翻譯的情況這種不要記錄
194 | if (empty($apend['c'][$i])) {
195 | $sms .= "發生GOOGLE翻譯無回傳:" . $sourcetext . "\n";
196 | } else {
197 | $targettext = $apend['c'][$i];
198 | //新增資料紀錄
199 | $sql = "INSERT INTO $db_name (`t_id`, `project_name`, `version`, `dirname`, `basename`, `sourcelanguage`, `sourcetext`, `targetlanguage`, `targettext`, `priority`, `add_date`) VALUES (NULL, '$project_name', '$version','$dirname','$basename','$sourcelanguage','$sourcetext','$targetlanguage','$targettext','20', NOW());";
200 | $ok = mysql_insert_i($sql, $linkID);
201 | $oki = ($ok == 1) ? "成功" : "失敗!";
202 | //$sms.="新增資料:".$oki;
203 | $ss++;
204 | if ($ok != 1) {
205 | $sms .= "新增資料錯誤訊息:" . $ok;
206 | }
207 | }
208 | }
209 | }
210 | return $ss;
211 | }
212 |
213 | //查詢資料庫的翻譯 這沒辦法整批查 只能1行1行查
214 | function q_data_translation($sourcetext, $sourcelanguage, $targetlanguage, $CT_CONFIG, $f = array('dirname' => '', 'basename' => ''))
215 | {
216 | $dirname = $f['dirname'];
217 | $basename = $f['basename'];
218 | $db_name = $CT_CONFIG['db_name'] . '.' . $CT_CONFIG['db_sheet']; //資料表名稱
219 | $linkID = $CT_CONFIG['linkID'];
220 | $sourcetext = addslashes($sourcetext);
221 | $sql = "SELECT `targettext` FROM `oc_t` WHERE `sourcelanguage` = '$sourcelanguage' AND `targetlanguage` = '$targetlanguage' AND `sourcetext` = '$sourcetext' ORDER BY `oc_t`.`priority` ASC";
222 | $date = row_sql1p($sql, 0, $linkID);
223 | return $date;
224 | }
225 |
226 | //智慧翻譯
227 | function ai_translated($ap, $sourcelanguage, $targetlanguage, $CT_CONFIG, $sms)
228 | {
229 | $need_s = array(); //紀錄要翻譯的行數由0開始
230 | $before_translation = array(); //送去GOOGLE翻譯前的
231 | $text_array = array(); //翻譯後的
232 | for ($i = 0; $i < count($ap['b']); $i++) {
233 | if (trim($ap['b'][$i])) {
234 | //有內容的行
235 | $need_s[] = $i; //要翻譯的行號
236 | } else {
237 | //空白行不翻
238 | }
239 |
240 | }
241 |
242 | //查資料庫-看是否翻譯過
243 | $rs = array();
244 | $yourself_translated = $ap['b'];
245 | for ($i = 0; $i < count($need_s); $i++) {
246 | //只挑要送出去的行數
247 | $sourcetext = $ap['b'][$need_s[$i]];
248 | //查詢資料庫
249 | $r = q_data_translation($sourcetext, $sourcelanguage, $targetlanguage, $CT_CONFIG, $ap['f']);
250 | if ($r) {
251 | //有查道的話
252 | $yourself_translated[$need_s[$i]] = $r; //取代字
253 | $rs[] = $need_s[$i]; //放查到的行數
254 | }
255 | }
256 |
257 | $need_s2 = array();
258 | //去除資料庫已有的翻譯的行
259 | for ($i = 0; $i < count($need_s); $i++) {
260 | if (in_array($need_s[$i], $rs)) {
261 | } else {
262 | $need_s2[] = $need_s[$i];
263 | }
264 | }
265 |
266 | $sms .= "一共" . count($ap['b']) . "行,";
267 | $sms .= count($ap['b']) - count($need_s) . "行是註解或空白";
268 | $sms .= count($rs) . "行翻譯過";
269 | $sms .= count($need_s2) . "行要送翻譯";
270 |
271 | $a['error'] = 1;
272 | //有要翻譯的才送
273 | if (count($need_s2)) {
274 | $iurlq = "&target=" . $targetlanguage;
275 | //一次送多組
276 | for ($i = 0; $i < count($need_s2); $i++) {
277 | //只挑要送出去的行數
278 | $text = $ap['b'][$need_s2[$i]];
279 | $before_translation[] = $text; //這個下面要用
280 | }
281 | $iurl = googleapi_url . $iurlq;
282 | $response = curl_post($iurl, $before_translation); //送翻譯
283 | //print_r($iurl);
284 | if (preg_match("@Error 413@", $response)) {
285 | $sms .= "。 | 客戶發出的請求太大 GOOGLE 拒絕翻譯 Error 413";
286 | $a['sms'] = $sms;
287 | $a['error'] = 1;
288 | return $a;
289 | } else if (preg_match("@Error 400@", $response)) {
290 | $sms .= "。 | 您的客戶發出格式不正確或非法的請求。 Error 400";
291 | $a['sms'] = $sms;
292 | $a['error'] = 1;
293 | return $a;
294 | } else {
295 | $data = json_decode($response, true); //接收;
296 | if (isset($data['error'])) {
297 | $sms .= "。 | 翻譯參數有問題" . json_encode($data['error']);
298 | $a['sms'] = $sms;
299 | $a['error'] = 1;
300 | return $a;
301 | } else {
302 | //翻譯成功
303 | $sms .= "翻譯成功";
304 | //把翻譯內容處理一遍
305 | for ($i = 0; $i < count($data['data']['translations']); $i++) {
306 | $text_array[] = translated_and_replaced($data['data']['translations'][$i]['translatedText']); //翻譯後的取代工作
307 | }
308 |
309 | $sms .= " 新增資料紀錄";
310 | $apend = array();
311 | $apend['f'] = $ap['f'];
312 | $apend['b'] = $before_translation; //翻譯前的
313 | $apend['c'] = $text_array; //翻譯後的 入資料庫的字要是處理過的
314 | $ss = add_mysqltranslation($apend, $sourcelanguage, $targetlanguage, $CT_CONFIG, $sms); //新增資料紀錄
315 | $sms .= $ss . "筆";
316 | }
317 |
318 | //挑回內容
319 | $cc1 = $yourself_translated; //查過自己翻譯後剩下
320 | //只挑要送出去的行數取代
321 | //如果翻譯不完全就會有只有部分 所以次數用$text_array
322 | for ($i = 0; $i < count($text_array); $i++) {
323 | $cc1[$need_s2[$i]] = $text_array[$i];
324 | }
325 | /*
326 | echo $sms;
327 | print_r($cc1);
328 | print_r($need_s2);
329 | print_r($text_array);
330 | exit;
331 | */
332 | $ap['c'] = $cc1; //原數組增加
333 | $a['sms'] = $sms;
334 | $a['ai_result'] = $ap;
335 | $a['error'] = 0; //此次沒問題
336 | return $a;
337 | }
338 | }
339 | }
340 | /*********************************************************************************************/
341 | /*
342 | 翻譯超簡單使用
343 | 如果你有申請過該API-網址直打就會有返回值
344 | //$url='https://translation.googleapis.com/language/translate/v2?key=[請自己去申請KEY]&q=fuck&q=language&target=zh-TW';
345 | 申請KEY的位置
346 | 請通過訪問https://console.developers.google.com/apis/api/translate.googleapis來啟用它 這個 AIP名字叫 Google Cloud Translation API
347 | KEY不能用別人的
348 | */
349 |
350 | $url = 'https://translation.googleapis.com/language/translate/v2?key=' . googleApiKEY;
351 | define('googleapi_url', $url);
352 | /*********************************************************************************************/
353 | $sourcelanguage = 'en-gb'; //來源語言
354 | $targetlanguage = 'zh-TW'; //目標語言
355 |
356 | $dir = dirname(__FILE__) . "\\01"; //要開啟的路徑
357 | $dir1 = $dir . "a"; //來源目錄 放有英文檔案
358 | $dir2 = $dir . "b"; //放有 翻譯過的中文檔案
359 |
360 | /*********************************************************************************************/
361 |
362 | $filenamesA = get_filenamesbydir($dir1); //獲取目錄下所有文件,包括子目錄
363 | $filenamesB = get_filenamesbydir($dir2); //獲取目錄下所有文件,包括子目錄
364 | /*********************************************************************************************/
365 | /* ********************************************************************************************* */
366 | $CT_CONFIG['db_name'] = 't_translation_googleapi'; //要開啟的資料庫
367 | $CT_CONFIG['db_sheet'] = DB_PREFIX . 't'; //子資料表
368 |
369 | $CT_CONFIG['project_name'] = 'opencart'; //專案名稱
370 | $CT_CONFIG['version'] = '2.3.0.2'; //版本號一律4碼
371 |
372 | $linkID = omysql($CT_CONFIG['db_name']); //開資料庫================================================
373 | $CT_CONFIG['linkID'] = $linkID;
374 |
375 | $z = array('y1' => 0, 'y2' => 0);
376 | //打印所有文件名,包括路徑
377 | foreach ($filenamesA as $value) {
378 | $ss = 0;
379 | //這裡不會有目錄名
380 | echo "來源" . $value; //開啟檔案
381 | $sms = '';
382 | $f = array();
383 | //這裡不會有目錄名只有檔案名
384 | $value2 = str_replace($dir1, $dir2, $value); //要找的檔名
385 | $value2 = str_replace('/', '\\', $value2); //要找的檔名
386 | $value2 = str_replace($sourcelanguage, $targetlanguage, $value2); //要找的檔名
387 | $sms .= "目標檔案可寫入檢查" . $value2;
388 | $sms .= " |結果:";
389 | if (is_file($value2)) {
390 | $sms .= "找到檔案" . $br;
391 | $f['target'] = $value2; //目標檔名
392 | $f['dirname'] = substr(dirname($value2), strlen($dir2) + 1); //路徑要去掉相同部分
393 | $f['basename'] = basename($value2); //檔名
394 | //print_r($f);
395 |
396 | $ap = get_translated_word_test($value); //開檔案
397 | $ap['f'] = $f; //檔案相關資訊
398 |
399 | $ap = ai_translated($ap, $sourcelanguage, $targetlanguage, $CT_CONFIG, $sms); //AI翻譯
400 |
401 | //有錯就不做下一步了
402 | if ($ap['error']) {
403 | $sms = $ap['sms'];
404 | } else {
405 | //沒錯才做下一步了
406 | $apend = $ap['ai_result'];
407 | $sms = $ap['sms'];
408 |
409 | //組出檔案內容
410 | $context = '';
411 | $context1p = '';
412 | for ($i = 0; $i < count($apend['a']); $i++) {
413 | $context1p = $apend['a'][$i]; //這沒有換行的
414 | if (trim($apend['c'][$i])) {
415 | //有翻譯才有
416 | $context1p .= " = '" . addslashesB($apend['c'][$i]) . "';"; //由於都用'包覆所以原本有'的要處理
417 | }
418 | if ($context1p == '\n') {
419 | //如果該行是空白只有1個\n
420 | } else {
421 | $context .= $context1p . "\n"; //換行都用\n
422 | }
423 |
424 | }
425 | $sms .= " 寫入檔案";
426 | file_put_contents($value2, $context); //寫入檔案
427 | }
428 |
429 | echo $sms . $br;
430 | //exit; //測試做1次就停止
431 | $z['y1']++; //處理檔案次數
432 | } else {
433 | echo "沒找到檔案" . $br;
434 | $z['y2']++;
435 | }
436 | }
437 | cmysql($linkID); //關資料庫==============================================================
438 | echo "
" . $br;
439 | echo "以處理" . $z['y1'] . "個檔案" . $br;
440 |
--------------------------------------------------------------------------------