W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
在這個示例中,我們希望捆綁附加的 i18n JSON 文件,這些文件看起來像這樣:
de.json
{
"hello": "Guten Tag!",
"bye": "Auf Wiedersehen!"
}
在這種情況下,我們將這些文件存儲在 tauri.conf.json 旁邊的 lang 目錄中。為此,我們將 "lang/*" 添加到資源(resources),并將 $RESOURCE/lang/* 添加到 fs 范圍,就像上面所示的那樣。
請注意,您必須配置允許列表(allowlist),以啟用 path > all 和您需要的 fs API,在這個示例中是 fs > readTextFile。
import { resolveResource } from '@tauri-apps/api/path'
// alternatively, use `window.__TAURI__.path.resolveResource`
import { readTextFile } from '@tauri-apps/api/fs'
// alternatively, use `window.__TAURI__.fs.readTextFile`
// `lang/de.json` is the value specified on `tauri.conf.json > tauri > bundle > resources`
const resourcePath = await resolveResource('lang/de.json')
const langDe = JSON.parse(await readTextFile(resourcePath))
console.log(langDe.hello) // This will print 'Guten Tag!' to the devtools console
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: