Skip to content

Commit

Permalink
Merge pull request #42 from kmvan/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
kmvan authored Sep 19, 2019
2 parents d4427c3 + 44bfad8 commit 4d1736c
Show file tree
Hide file tree
Showing 26 changed files with 2,880 additions and 3,155 deletions.
4 changes: 2 additions & 2 deletions AppConfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"APP_VERSION": "3.2",
"APP_VERSION": "3.3",
"APP_NAME": "X Prober",
"APP_URL": "https://github.com/kmvan/x-prober",
"AUTHOR_URL": "https://inn-studio.com/prober",
Expand All @@ -11,7 +11,7 @@
"APP_CONFIG_URL_DEV": "http://127.0.0.1/prober/AppConfig.json",
"AUTHOR_NAME": "INN STUDIO",
"LATEST_PHP_STABLE_VERSION": 7,
"LATEST_NGINX_STABLE_VERSION": "1.16.0",
"LATEST_NGINX_STABLE_VERSION": "1.16.1",
"LATEST_SQLITE3_STABLE_VERSION": "3.28.0",
"LATEST_MYSQL_CLIENT_STABLE_VERSION": "50012",
"BENCHMARKS": [
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

All Notable changes to `X-Prober` will be documented in this file

## 3.3.0 - 2019-09-19

### Optimize

- Optimize notch position
- Optimize languages generation tool

###

- Update Nginx version to 1.16.1

## 3.2 - 2019-08-03

### Fix
Expand Down
8 changes: 3 additions & 5 deletions README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- 安装 npm 模块:`$ npm install`
- 监听脚本:`$ npm run dev`
- 安装 composer:`$ composer install && composer dumpautoload -o`
- 生成多国语言:`$ npm run lang``$ node ./build-lang.js` 来重建 `./languages/lang.pot` 语言模板。
- 编译 **开发环境**`$ php ./Make.php dev`
- 编译 **生产环境**: `$ npm run build && php ./Make.php build`
- 通过浏览器访问 `./dist/prober.php`
Expand All @@ -44,8 +45,8 @@
## 参与翻译更多语言

- **Fork** 项目。
- 使用 [Poedit](https://poedit.net/) 通过 `./languages/js-language.pot` 语言模板来创建和翻译您的语言。
- 保存翻译语言文件 _(例如:`js-en_US.po`)_`./languages` 目录里面。
- 使用 [Poedit](https://poedit.net/) 通过 `./languages/lang.pot` 语言模板来创建和翻译您的语言。
- 保存翻译语言文件 _(例如:`en_US.po`)_`./languages` 目录里面。
- 添加您的称呼到贡献者名单里面。
- 进行 Pull Request,十分感谢。😘

Expand All @@ -55,9 +56,6 @@

## 贡献者名单

- Km.Van https://inn-studio.com
- Jack Cherng https://github.com/jfcherng

<a href="https://github.com/kmvan/x-prober/graphs/contributors"><img src="https://opencollective.com/x-prober/contributors.svg?width=890&button=false" /></a>

## 支持者
Expand Down
10 changes: 4 additions & 6 deletions README-zh_HK.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# 😎 X 探針、劉海探針

> 這是一款 PHP 環境探針程式,它不僅可以十分直觀地為您顯示伺服器的信息,而且最重要的是:它跟 📱 **iPhone X/XS/XS Max/XR** 一樣有醜陋的劉海!
> 這是一款 PHP 環境探針程式,它不僅可以十分直觀地為您顯示伺服器的信息,而且最重要的是:它跟 📱 **iPhone X/XS/XS Max/XR/11/11 Pro/11 Pro Max** 一樣有醜陋的劉海!
[![Backers on Open Collective](https://opencollective.com/x-prober/backers/badge.svg)](#backers)
[![Sponsors on Open Collective](https://opencollective.com/x-prober/sponsors/badge.svg)](#sponsors)
Expand Down Expand Up @@ -36,6 +36,7 @@
- 安裝 npm 模塊:`$ npm install`
- 監視腳本:`$ npm run dev`
- 安裝 composer:`$ composer install && composer dumpautoload -o`
- 生成多國語言:`$ npm run lang``$ node ./build-lang.js` 來重建 `./languages/lang.pot` 語言模板。
- 編譯 **開發環境**`$ php ./Make.php dev`
- 編譯 **生產環境**: `$ npm run build && php ./Make.php build`
- 通過瀏覽器訪問 `./dist/prober.php`
Expand All @@ -44,8 +45,8 @@
## 參與翻譯更多語言

- **Fork** 項目。
- 使用 [Poedit](https://poedit.net/) 通過 `./languages/js-language.pot` 語言模板來創建和翻譯您的語言。
- 保存翻譯語言文件 _(例如:`js-en_US.po`)_`./languages` 目錄裏面。
- 使用 [Poedit](https://poedit.net/) 通過 `./languages/lang.pot` 語言模板來創建和翻譯您的語言。
- 保存翻譯語言文件 (例如:`en_US.po`) 到 `./languages` 目錄裏面。
- 添加您的稱呼到貢獻者名單裏面。
- 進行 Pull Request,十分感謝。😘

Expand All @@ -55,9 +56,6 @@

## 貢獻者名單

- Km.Van https://inn-studio.com
- Jack Cherng https://github.com/jfcherng

<a href="https://github.com/kmvan/x-prober/graphs/contributors"><img src="https://opencollective.com/x-prober/contributors.svg?width=890&button=false" /></a>

## 支援者
Expand Down
10 changes: 4 additions & 6 deletions README-zh_TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# 😎 X 探針、劉海探針

> 這是一款 PHP 環境探針程式,它不僅可以十分直觀地為您顯示伺服器的信息,而且最重要的是:它跟 📱 **iPhone X/XS/XS Max/XR** 一樣有醜陋的劉海!
> 這是一款 PHP 環境探針程式,它不僅可以十分直觀地為您顯示伺服器的信息,而且最重要的是:它跟 📱 **iPhone X/XS/XS Max/XR/11/11 Pro/11 Pro Max** 一樣有醜陋的劉海!
[![Backers on Open Collective](https://opencollective.com/x-prober/backers/badge.svg)](#backers)
[![Sponsors on Open Collective](https://opencollective.com/x-prober/sponsors/badge.svg)](#sponsors)
Expand Down Expand Up @@ -36,6 +36,7 @@
- 安裝 npm 模塊:`$ npm install`
- 監視腳本:`$ npm run dev`
- 安裝 composer:`$ composer install && composer dumpautoload -o`
- 生成多國語言:`$ npm run lang``$ node ./build-lang.js` 來重建 `./languages/lang.pot` 語言模板。
- 編譯 **開發環境**`$ php ./Make.php dev`
- 編譯 **生產環境**: `$ npm run build && php ./Make.php build`
- 通過瀏覽器訪問 `./dist/prober.php`
Expand All @@ -44,8 +45,8 @@
## 參與翻譯更多語言

- **Fork** 項目。
- 使用 [Poedit](https://poedit.net/) 通過 `./languages/js-language.pot` 語言模板來創建和翻譯您的語言。
- 保存翻譯語言文件 _(例如:`js-en_US.po`)_`./languages` 目錄裏面。
- 使用 [Poedit](https://poedit.net/) 通過 `./languages/lang.pot` 語言模板來創建和翻譯您的語言。
- 保存翻譯語言文件 (例如:`en_US.po`) 到 `./languages` 目錄裏面。
- 添加您的稱呼到貢獻者名單裏面。
- 進行 Pull Request,十分感謝。😘

Expand All @@ -55,9 +56,6 @@

## 貢獻者名單

- Km.Van https://inn-studio.com
- Jack Cherng https://github.com/jfcherng

<a href="https://github.com/kmvan/x-prober/graphs/contributors"><img src="https://opencollective.com/x-prober/contributors.svg?width=890&button=false" /></a>

## 支援者
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ And the most important thing is that it's like 📱 **iPhone X/XS/XS Max/XR/11/1
- Watch scripts: `$ npm run dev`.
- Generate composer vendor: `$ composer install && composer dumpautoload -o`.
- Compile **development**: `$ php ./Make.php dev`.
- Generate languages: `$ npm run lang` or `node ./build-lang.js` to remake `./languages/lang.pot` language template.
- Compile **production**: `$ npm run build && php ./Make.php build`.
- Access `./dist/prober.php` from HTTP browser.
- Enjoy it. 😄
Expand All @@ -62,8 +63,8 @@ And the most important thing is that it's like 📱 **iPhone X/XS/XS Max/XR/11/1

- **Fork** project.
- Fetch your project.
- Use [Poedit](https://poedit.net/) to create your language from `./languages/js-language.pot` language template file and translates it.
- Save your language file _(like: `js-en_US.po`)_ into `./languages`.
- Use [Poedit](https://poedit.net/) to create your language from `./languages/lang.pot` language template file and translates it.
- Save your language file (like: `en_US.po`) into `./languages`.
- Pull Request and thank you. 😘

## Note for participate in contribution
Expand Down
132 changes: 132 additions & 0 deletions build-lang.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/**
* @version 1.0.5
*/

const trim = require('lodash/trim')
const glob = require('glob')
const fs = require('fs')
const PO = require('pofile')
const path = require('path')
const dirSrc = path.resolve(__dirname, 'src')
const dirComponents = `${dirSrc}/Components`
const langs = {}
const poEntries = {}

const parseFile = filePath => {
const code = fs.readFileSync(filePath).toString()
const reg = new RegExp(
`gettext\\s*\\(\\s*('.+?')\\s*,*\\s*('.+?')*\\s*\\)`,
'gm'
)

const matches = code.matchAll(reg)

if (matches) {
for (const match of matches) {
const msgid = trim(match[1], "'")
const msgctxt = trim(match[2] || '', "'")
if (poEntries[`${msgid}${msgctxt}`]) {
continue
}

poEntries[`${msgid}${msgctxt}`] = `
${msgctxt ? `msgctxt ${JSON.stringify(msgctxt)}` : ''}
msgid ${JSON.stringify(msgid)}
msgstr ""
`.trim()
}
}
}

const fetchDirOrFile = filePathOrDir => {
if (fs.lstatSync(filePathOrDir).isDirectory()) {
fs.readdirSync(filePathOrDir).map(p =>
fetchDirOrFile(`${filePathOrDir}/${p}`)
)
} else {
if (['.ts', '.tsx'].includes(path.extname(filePathOrDir))) {
parseFile(filePathOrDir)
}
}
}

const createPot = () => {
const toWriteData = `
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: \\n"
"POT-Creation-Date: \\n"
"PO-Revision-Date: \\n"
"Last-Translator: \\n"
"Language-Team: \\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
"X-Generator: Poedit 2.2.1\\n"
"X-Poedit-Basepath: ../src\\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\\n"
"X-Poedit-SourceCharset: UTF-8\\n"
"X-Poedit-KeywordsList: gettext\\n"
${Object.values(poEntries).join('\n\n')}
`.trim()
// write pot
fs.writeFileSync(
path.resolve(__dirname, 'languages/lang.pot'),
toWriteData,
'utf8'
)
}

fetchDirOrFile(dirComponents)
// create pot
createPot()

const formatItem = items => {
return items.map(({ msgctxt, msgid, msgstr }) => {
return {
msgctxt,
msgid,
msgstr: msgstr[0],
}
})
}

const getItem = async filepath => {
return new Promise(resolve => {
PO.load(filepath, (err, data) => {
const langId = data.headers.Language
const items = formatItem(data.items)
resolve({
items,
langId,
})
})
})
}

const writeJsData = ({ langId, items }) => {
items.map(({ msgstr, msgid, msgctxt }) => {
const key = `${msgctxt || ''}${msgid}`
if (!langs[key]) {
langs[key] = {}
}

langs[key][langId] = msgstr
})

fs.writeFileSync(
path.resolve(__dirname, 'src/Components/Language/lang.json'),
JSON.stringify(langs, null, 2),
err => {
if (err) {
throw err
}
}
)
}

glob.sync(path.resolve(__dirname, 'languages/*.po')).map(async filepath => {
writeJsData(await getItem(filepath))
})
66 changes: 0 additions & 66 deletions build-languages.js

This file was deleted.

Loading

0 comments on commit 4d1736c

Please sign in to comment.