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

關於 cli 版的 config 選項的一些建議 #845

Closed
plum7x opened this issue Feb 19, 2024 · 4 comments
Closed

關於 cli 版的 config 選項的一些建議 #845

plum7x opened this issue Feb 19, 2024 · 4 comments

Comments

@plum7x
Copy link

plum7x commented Feb 19, 2024

在 windows 中使用 opencc 只能通過完整路徑指定 config,否則只能把工作目錄設定到 config 目錄。也就是需要一個放置 config 的固定位置,以避免需要指定 config 的完整路徑的情況。

例如優先使用 opencc.exe 所在目錄下的 config
-c s2t.json

  1. "opencc.exe 所在目錄\s2t.json"
  2. "opencc.exe 所在目錄\configs\s2t.json"

另外,希望允許使用 base name 指定 config
例如 -c s2t-c s2t.json

@plum7x
Copy link
Author

plum7x commented Apr 20, 2024

FFmpeg 使用了一個環境變數 FFMPEG_DATADIR
來為其指定放置 preset 的目錄
這看起來是比較好的解決方案了

@t1anchen
Copy link

t1anchen commented Jun 21, 2024

也遇到了類似的問題

version: opencc 1.1.7
os: win11, macos 12.7.5

  • 在 mac 下面通過 npm 安裝,默認參數都不加,一切都正常
  • 在 win11 下面通過 github 下載的執行檔,默認參數都不加,會出現 s2t.json not found or not accessible 的情況

如果 win 版本能夠自動 fallback 到一個默認的參數路徑,比如 ..\share\opencc\s2t.json 是不是會更易用?

@plum7x
Copy link
Author

plum7x commented Jun 21, 2024

這裡提供一個方法以便於在 Windows 中使用

儲存下內容為 opencc.ps1

[string] $PROGRAM_FILE_PATH = 'build\bin\opencc.exe'
[string] $CONFIGS_DIR_PATH = 'build\share\opencc'
$newArgs = $args
$index = '-c', '--config' | % {$newArgs.IndexOf($_)} | ? {$_ -ge 0}
if ($index.Count -le 0) {
    $newArgs += @('-c')
    $newArgs += @('s2tw.json')
}
$index | % {$newArgs[$_+1] = [IO.Path]::Combine($CONFIGS_DIR_PATH, $newArgs[$_+1])}
$input | & $PROGRAM_FILE_PATH @newArgs
exit $LASTEXITCODE

使用 opencc.ps1

PS >$OutputEncoding = New-Object System.Text.UTF8Encoding $False
PS >Get-Content input.txt -Encoding UTF8 | & opencc.ps1 -o output.txt

若想使用 opencc.exe 為命令而不是 opencc.ps1 或 opencc,則可以使用 Win-PS2EXE 將 ps1 檔轉為 exe 格式

希望將來能看到看到從根本解決此問題

@BYVoid
Copy link
Owner

BYVoid commented Jul 26, 2024

1.1.8版本加入了 --path.

@BYVoid BYVoid closed this as completed Jul 26, 2024
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

3 participants