Skip to content

Commit

Permalink
Merge pull request #53 from hideki0403/develop
Browse files Browse the repository at this point in the history
release: v1.4.0
  • Loading branch information
hideki0403 authored Jul 9, 2022
2 parents 77158e9 + 63103f3 commit 9023a0a
Show file tree
Hide file tree
Showing 11 changed files with 2,161 additions and 830 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
paths:
- 'locales/*.json5'
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -24,7 +24,7 @@ jobs:
with:
node-version: 'lts/*'
cache: npm

- name: npm ci
run: npm ci

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
- name: create release
if: steps.check-tag.outputs.exists == 'false'
uses: softprops/action-gh-release@v1
with:
with:
name: v${{ steps.package-version.outputs.current-version }}
tag_name: v${{ steps.package-version.outputs.current-version }}
prerelease: ${{ steps.pre-release.outputs.pre }}
Expand Down
1,555 changes: 1,136 additions & 419 deletions locales/ja.json5

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "better-japanese",
"version": "1.3.1",
"version": "1.4.0",
"description": "",
"main": "index.js",
"scripts": {
Expand All @@ -25,6 +25,7 @@
},
"homepage": "https://github.com/hideki0403/better-japanese#readme",
"devDependencies": {
"chalk": "^4.1.2",
"chokidar": "^3.5.3",
"debug": "^4.3.4",
"eslint": "^8.17.0",
Expand Down
912 changes: 516 additions & 396 deletions src/common/main.js

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions src/web-embed/JA.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
// BetterJapanese Injector
LoadLang(`loc/JA_fallback.js?v=${Game.version}`)

let conf = JSON.parse(localStorage.getItem('BJPConfig') || '{"replaceJP": false}')
let language = localStorage.getItem('BJPLangPack')

// localStorageに翻訳データが保存されていない場合はfallbackを使用
if (!language) {
LoadLang(`loc/JA_fallback.js?v=${Game.version}`)
}

if (language && conf.replaceJP) {
AddLanguage('JA', 'japanese', JSON.parse(language))
ModLanguage('JA', JSON.parse(language))
}

Game.LoadMod(`https://pages.yukineko.me/better-japanese/assets/main.js?v=${Game.version}`)
385 changes: 385 additions & 0 deletions src/web/rebuild.js

Large diffs are not rendered by default.

55 changes: 53 additions & 2 deletions tools/publish.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const config = {
language: process.env.TARGET_LOCALE || 'ja',
url: process.env.BASE_URL ? `${process.env.BASE_URL}/assets/translate.json` : 'https://pages.yukineko.me/better-japanese/assets/translate.json',
url: {
translate: process.env.BASE_URL ? `${process.env.BASE_URL}/assets/translate.json` : 'https://pages.yukineko.me/better-japanese/assets/translate.json',
category: process.env.BASE_URL ? `${process.env.BASE_URL}/assets/category.json` : 'https://pages.yukineko.me/better-japanese/assets/category.json',
},
date: Date.now(),
hash: 0,
}
Expand All @@ -14,13 +17,61 @@ const apiDir = path.join(distDir, './api/')
const assetsDir = path.join(distDir, './assets/')
const localeFile = path.join(rootDir, `./locales/${config.language}.json5`)
const releaseLocaleFile = path.join(assetsDir, './translate.json')
const releaseCategoryFile = path.join(assetsDir, './category.json')
const json5 = require('json5')
const color = require('chalk')

if (!fs.existsSync(distDir)) fs.mkdirSync(distDir)
if (!fs.existsSync(apiDir)) fs.mkdirSync(apiDir)
if (!fs.existsSync(assetsDir)) fs.mkdirSync(assetsDir)

fs.writeJSONSync(releaseLocaleFile, json5.parse(fs.readFileSync(localeFile, 'utf-8')))
let translatedJson = json5.parse(fs.readFileSync(localeFile, 'utf-8'))
let category = {}
let currentCategory = null
let parent = null
let parentKey = null

for (let key of Object.keys(translatedJson)) {
if (key.startsWith('#CATEGORY: ')) {
// カテゴリを生成してcurrentCategoryに指定
currentCategory = category

key.replace('#CATEGORY: ', '').split('/').forEach(cat => {
if (currentCategory.constructor === Array && parent !== null) {
if (currentCategory.length) {
console.error(color.red('親となるカテゴリに要素が含まれているため、子カテゴリを追加できません。\n(例えばカテゴリ「ミニゲーム」が存在する場合は「ミニゲーム/農場」カテゴリを設定することができません)'))
return
}

parent[parentKey] = {}
currentCategory = parent[parentKey]
}

if (!currentCategory[cat]) currentCategory[cat] = []
parent = currentCategory
parentKey = cat
currentCategory = currentCategory[cat]
})

delete translatedJson[key]
continue
}

if (key.startsWith('#ENDCATEGORY:')) {
currentCategory = null
delete translatedJson[key]
continue
}

if (currentCategory === null) continue

if (currentCategory.constructor !== Array) console.error(color.red('カテゴリがネストしているため、親となるカテゴリに要素を追加することができません。\n(例えばカテゴリ「ミニゲーム/農場」が存在する場合は「ミニゲーム」カテゴリを設定することができません)'))

currentCategory.push(key)
}

fs.writeJSONSync(releaseLocaleFile, translatedJson)
fs.writeJSONSync(releaseCategoryFile, category)

config.hash = hash.sync(releaseLocaleFile)

Expand Down
10 changes: 10 additions & 0 deletions tools/replace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const locJa = []

const locEn = []

const result = {}
for(let i = 0; i < locEn.length; i++) {
result[locEn[i].replace('News : ', '')] = locJa[i]
}

console.log(JSON.stringify(result, null, ' '))
52 changes: 51 additions & 1 deletion tools/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const localeFile = path.join(rootDir, `./locales/${targetLanguage}.json5`)
const json5 = require('json5')
const ESLINT = require('eslint').ESLint
const eslint = new ESLINT()
const color = require('chalk')
log.enabled = true

async function initFormatter() {
Expand All @@ -30,9 +31,58 @@ async function copyFiles(file) {
if (!!result) return false
}

let translatedJson = json5.parse(fs.readFileSync(localeFile, 'utf-8'))
let category = {}
if (!file || file.match('.json5')) {
let currentCategory = null
let parent = null
let parentKey = null

for (let key of Object.keys(translatedJson)) {
if (key.startsWith('#CATEGORY: ')) {
// カテゴリを生成してcurrentCategoryに指定
currentCategory = category

key.replace('#CATEGORY: ', '').split('/').forEach(cat => {
if (currentCategory.constructor === Array && parent !== null) {
if (currentCategory.length) {
console.error(color.red('親となるカテゴリに要素が含まれているため、子カテゴリを追加できません。\n(例えばカテゴリ「ミニゲーム」が存在する場合は「ミニゲーム/農場」カテゴリを設定することができません)'))
return
}

parent[parentKey] = {}
currentCategory = parent[parentKey]
}

if (!currentCategory[cat]) currentCategory[cat] = []
parent = currentCategory
parentKey = cat
currentCategory = currentCategory[cat]
})

delete translatedJson[key]
continue
}

if (key.startsWith('#ENDCATEGORY:')) {
currentCategory = null
delete translatedJson[key]
continue
}

if (currentCategory === null) continue

if (currentCategory.constructor !== Array) console.error(color.red('カテゴリがネストしているため、親となるカテゴリに要素を追加することができません。\n(例えばカテゴリ「ミニゲーム/農場」が存在する場合は「ミニゲーム」カテゴリを設定することができません)'))

currentCategory.push(key)
}
}

fs.copySync(srcDir, distDir)
fs.copySync(assetsDir, distDir)
fs.writeJSONSync(path.join(distDir, 'translate.json'), json5.parse(fs.readFileSync(localeFile, 'utf-8')))
fs.writeJSONSync(path.join(distDir, 'translate.json'), translatedJson)
if (Object.keys(category).length) fs.writeJSONSync(path.join(distDir, 'category.json'), category)

return true
}

Expand Down

0 comments on commit 9023a0a

Please sign in to comment.