如要支援更廣泛的語言設定,並改善 Looker 專案中的字串管理,請將 .strings 檔案轉換為 .strings.json 格式。完成現代化程序後,您就能運用更強大的本地化功能,讓不同地區的使用者更輕鬆存取及使用資料應用程式。本指南提供遷移現有檔案的步驟。
如要將 .strings 檔案轉換為 .strings.json 檔案,請按照下列步驟操作:
- 如果使用 7.12 之前的 Looker 版本,請關閉「Legacy .strings files for localization」(舊版本地化 .strings 檔案) 舊版功能。
- 按一下專案檔案清單右上方的「+」圖示,然後選取「建立語言代碼字串檔案」,為專案建立新的
.strings.json檔案。 - 為新的
.strings.json檔案命名。.strings檔案的標題必須與使用該語言代碼的使用者或群組所指派的語言代碼相符,且預設語言代碼檔案的標題必須與專案資訊清單檔案中default_locale的值相符。 - 新
.strings.json檔案中顯示的程式碼片段提供 JSON 格式範例。刪除這個範例,並換成一對大括號:{} - 從舊的
.strings檔案複製鍵/值組合,並貼到大括號內。 - 將所有等號換成半形冒號。
- 移除所有註解,或將註解重新格式化為個別註解或註解陣列,如下圖所示。
- 將所有半形分號換成半形逗號。
鍵/值組合的 .strings.json 格式通常如下所示:
{
"flight_info" : "Flight Info",
"id" : "Identifier",
"airline" : "Air Carrier"
}
如要設定註解格式,可以使用下列格式:
{
" My Comment": {
"my_comment_array": [
"The name of this file should be the associated locale code followed by '.strings.json'",
"There is one .strings.json file per locale.",
"Define your translated strings one key at a time",
"Keys can be any string; choose whatever scheme helps you stay organized",
"Then, set your Lookml label and description parameters to the desired key values.",
"To choose this file as the master key list and as the one to validate against",
"set its locale code ('test') as the default_locale in the manifest file"
],
"value": "Translation for My Comment"
},
"My Key": {
"value": "Translation for My Key",
"comment": "Define your translated strings with a comment or an array of comments"
}
}