Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

汉化脚本 #184

Open
unknowissue opened this issue Apr 29, 2024 · 12 comments
Open

汉化脚本 #184

unknowissue opened this issue Apr 29, 2024 · 12 comments

Comments

@unknowissue
Copy link

unknowissue commented Apr 29, 2024

仅适用win:

逻辑

  1. 读取环境变量
    $username = $env:USERNAME
  2. 读取文件 C:\Users\$username\AppData\Roaming\Notion\latestVersion.json 中 version 字段
  3. 根据 version 字段的值,是否存在以下两个文件
    C:\Users\$username\AppData\Roaming\Notion\notionAssetCache-v2\$version\assets_assets\index-en-US-***.html
    C:\Users\$username\AppData\Roaming\Notion\notionAssetCache-v2\$version\assets_assets\localeSetup-zh-CN-***.js
    4.如果存在这两个文件,
    读取 C:\Users\$username\AppData\Roaming\Notion\notionAssetCache-v2\$version\assets_assets\localeSetup-zh-CN-***.js 的文件名 并复制给 $name_localeSetup-zh-CN
  4. 得到以下字符串
    <!doctype html><script defer="defer" src="/_assets/$name_localeSetup-zh-CN"></script>'
  5. 在文件 C:\Users\$username\AppData\Roaming\Notion\notionAssetCache-v2\$version\assets_assets\index-en-US-***.html
    将<!doctype html>
    替换为
    <!doctype html><script defer="defer" src="/_assets/$name_localeSetup-zh-CN"></script>'

另外,由于win安全策略设置,需要用bat启动powershell脚本

实现:

D:\soft\notion_zh\mod_zh-ch.ps1

# 读取当前用户名环境变量
$username = $env:USERNAME

# 更新 Notion 版本文件的路径
$jsonFilePath = "C:\Users\$username\AppData\Roaming\Notion\notionAssetCache-v2\latestVersion.json"
$assetsDir = "C:\Users\$username\AppData\Roaming\Notion\notionAssetCache-v2"

# 获取当前日期,格式为 yyyyMMddHHmmss
$date = Get-Date -Format "yyyyMMddHHmmss"

# 读取 JSON 文件中的 version 字段
if (Test-Path $jsonFilePath) {
    $version = (Get-Content $jsonFilePath | ConvertFrom-Json).version
} else {
    Write-Error "Version file does not exist"
    exit
}

# 定义需要检查的文件路径
$htmlFilePath = "$assetsDir\$version\assets\_assets\index-en-US-*.html"
$jsFilePath = "$assetsDir\$version\assets\_assets\localeSetup-zh-CN-*.js"

# 检查是否存在 HTML 和 JS 文件
$htmlFile = Get-ChildItem $htmlFilePath -ErrorAction SilentlyContinue
$jsFile = Get-ChildItem $jsFilePath -ErrorAction SilentlyContinue

if ($htmlFile -and $jsFile) {
    # 定义要替换的 HTML 内容
    $name_localeSetup = $jsFile.Name
    $newHeadHtml = "<!doctype html><html class=""notion-html""><head lang=""en""><script defer=""defer"" src=""/_assets/$name_localeSetup""></script>"

    # 创建备份文件
    $backupFile = $htmlFile.DirectoryName + "\bak_" + $date + "_" + $htmlFile.Name
    Copy-Item $htmlFile.FullName -Destination $backupFile

    # 读取 HTML 文件内容
    $htmlContent = Get-Content $htmlFile.FullName -Raw

    # 检查是否已包含新的头部 HTML
    if ($htmlContent -notmatch $newHeadHtml) {
        $htmlContent = $htmlContent -replace '<!doctype html><html class="notion-html"><head lang="en">', $newHeadHtml
        Set-Content $htmlFile.FullName -Value $htmlContent
        Write-Output "HTML file updated and backup created."
    } else {
        Write-Output "No changes needed. The HTML file already contains the required script tag."
    }
} else {
    Write-Output "Required files do not exist."
}




Start-Process -FilePath "C:\Users\$username\AppData\Local\Programs\Notion\Notion.exe"  -ArgumentList "--proxy-server=socks5://127.0.0.1:8181  —enable-features=OverlayScrollbar"  -NoNewWindow

D:\soft\notion_zh\start_notion.bat

powershell -ExecutionPolicy RemoteSigned  -File D:\soft\notion_zh\mod_zh-ch.ps1

@M3ngZ
Copy link

M3ngZ commented Apr 29, 2024

最新版是不是没有这两个文件夹了

@unknowissue
Copy link
Author

最新版是不是没有这两个文件夹了

23.13.0.200
我用的版本是,是有的

@ld0574
Copy link

ld0574 commented May 4, 2024

亲测有效,win 桌面版3.5.0

@M3ngZ
Copy link

M3ngZ commented May 4, 2024

是的 有效,文件夹需要等一段时间才会出现 感谢分享

@aaazz47
Copy link

aaazz47 commented May 7, 2024

3.6.0亲测有效,大家使用的时候需要注意 bat 文件中的路径

@M3ngZ
Copy link

M3ngZ commented May 7, 2024

新版也有效 这边直接使用powershell打开 没有遇到过什么问题
汉化其实一开始用来上手吧,习惯了之后用英文也无所谓了,一些/+块名 可能用英文好搜索些

@ainihulu
Copy link

ainihulu commented May 8, 2024

新版也有效 这边直接使用powershell打开 没有遇到过什么问题 汉化其实一开始用来上手吧,习惯了之后用英文也无所谓了,一些/+块名 可能用英文好搜索些

确实

@yuanshuoastro
Copy link

Mac 怎么用

@unknowissue
Copy link
Author

Mac 怎么用

抱歉,不会Mac脚本。仅适用win

@x-haose
Copy link

x-haose commented May 21, 2024

兄弟们,我用Rust写了个简单的脚本,感兴趣的可以去看看:https://github.com/x-haose/notion_chinese

@lzh0011
Copy link

lzh0011 commented May 24, 2024

兄弟们,我用Rust写了个简单的脚本,感兴趣的可以去看看:https://github.com/x-haose/notion_chinese

牛,已验证可用。回头学学这门神奇的语言。

@zhaozuo
Copy link

zhaozuo commented May 27, 2024

兄弟们,我用Rust写了个简单的脚本,感兴趣的可以去看看:https://github.com/x-haose/notion_chinese

亲测3.8.1可用👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants