-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from cartesiancs/feat/locale
Feat/locale
- Loading branch information
Showing
16 changed files
with
323 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { ReactiveController, ReactiveControllerHost } from "lit"; | ||
import { rendererModal } from "../utils/modal"; | ||
import EnLang from "../locale/en.json"; | ||
import KoLang from "../locale/ko.json"; | ||
import { property, state } from "lit/decorators.js"; | ||
|
||
type AbleLanguage = "en" | "ko"; | ||
|
||
export class LocaleController implements ReactiveController { | ||
host: ReactiveControllerHost; | ||
|
||
value: AbleLanguage = "en"; | ||
|
||
constructor(host: ReactiveControllerHost) { | ||
(this.host = host).addController(this); | ||
|
||
window.electronAPI.req.store.get("LANG").then((item) => { | ||
this.value = item.value; | ||
}); | ||
} | ||
|
||
public t(target) { | ||
if (this.value == "en") { | ||
return this.getValueByPath(EnLang, target); | ||
} | ||
|
||
if (this.value == "ko") { | ||
return this.getValueByPath(KoLang, target); | ||
} | ||
} | ||
|
||
public changeLanguage(lang: AbleLanguage) { | ||
this.value = lang; | ||
window.electronAPI.req.store.set("LANG", lang); | ||
} | ||
|
||
private getValueByPath(json, path) { | ||
if (typeof path !== "string" || !path) { | ||
return ""; | ||
} | ||
|
||
const keys = path.split("."); | ||
let current = json; | ||
|
||
for (const key of keys) { | ||
if (current && Object.prototype.hasOwnProperty.call(current, key)) { | ||
current = current[key]; | ||
} else { | ||
return ""; | ||
} | ||
} | ||
|
||
return current; | ||
} | ||
|
||
hostConnected() { | ||
window.electronAPI.req.store.get("LANG").then((item) => { | ||
this.value = item.value; | ||
this.host.requestUpdate(); | ||
}); | ||
} | ||
hostDisconnected() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"test": "test", | ||
"render": { | ||
"start": "render start" | ||
}, | ||
"setting": { | ||
"select_project_folder": "Select Folder", | ||
"video_duration": "Duration", | ||
"seconds": "Seconds", | ||
"seconds_unit": "s", | ||
"frame": "Frame", | ||
"resolution": "Resolution", | ||
"save_project": "Save Project", | ||
"load_project": "Load Project", | ||
"bitrate": "Bitrate", | ||
"bitrate_unit": "bitrate", | ||
"export": "Export", | ||
"need_select_project_folder": "Select a project folder", | ||
"text": "text", | ||
"position": "Position", | ||
"opacity": "Opacity", | ||
"audio": "Audio" | ||
}, | ||
"modal": { | ||
"change_language": "Change Language", | ||
"change_language_description": "If you change the language, you will have to restart the app.", | ||
"needs_to_restart": " Needs to Restart", | ||
"needs_to_restart_description": "WARNING: You may lose unsaved tasks.", | ||
"restart": "Restart", | ||
"close": "Close" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"test": "테스트", | ||
"render": { | ||
"start": "랜더링 시작" | ||
}, | ||
"setting": { | ||
"select_project_folder": "프로젝트 폴더 지정", | ||
"video_duration": "영상 길이", | ||
"seconds": "초단위", | ||
"seconds_unit": "초", | ||
"frame": "프레임", | ||
"resolution": "해상도", | ||
"save_project": "프로젝트 저장", | ||
"load_project": "프로젝트 불러오기", | ||
"bitrate": "비트레이트", | ||
"bitrate_unit": "bitrate", | ||
"export": "내보내기", | ||
"need_select_project_folder": "프로젝트 폴더를 지정해주세요.", | ||
"text": "텍스트", | ||
"position": "위치", | ||
"opacity": "불투명도", | ||
"audio": "오디오" | ||
}, | ||
"modal": { | ||
"change_language": "언어 변경", | ||
"change_language_description": "언어를 변경하시면 앱을 재시작해야 합니다.", | ||
"needs_to_restart": "재시작 필요", | ||
"needs_to_restart_description": "경고: 저장되지 않은 작업물은 사라질 수 있습니다. 프로젝트를 저장했는지 확인해주세요.", | ||
"restart": "재시작", | ||
"close": "닫기" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.