From 2c845e74c77f43a2863c6fd1e141d160795c3b85 Mon Sep 17 00:00:00 2001 From: NhanPT Date: Sun, 20 Nov 2022 14:41:46 +0700 Subject: [PATCH] add language selector --- assets/css/theme.css | 5 +++++ assets/js/mountain.js | 14 +++++++++----- assets/languages/en.json | 8 ++++++++ assets/languages/vi.json | 4 ++++ templates/modals/all.html | 1 + templates/modals/language.html | 20 ++++++++++++++++++++ templates/modals/premium.html | 2 +- templates/pages/index.html | 6 ++++-- templates/parts/footer.html | 1 + templates/parts/header.html | 29 +++++++++++++++++++++++++++++ 10 files changed, 82 insertions(+), 8 deletions(-) create mode 100644 templates/modals/language.html diff --git a/assets/css/theme.css b/assets/css/theme.css index 0f9f7af..7ccd59b 100644 --- a/assets/css/theme.css +++ b/assets/css/theme.css @@ -68,4 +68,9 @@ .dropdown-item.active { background-color: var(--bs-indigo); +} + +body { + opacity: 0; + transition: opacity 0.2s; } \ No newline at end of file diff --git a/assets/js/mountain.js b/assets/js/mountain.js index bb7962c..d7c8fff 100644 --- a/assets/js/mountain.js +++ b/assets/js/mountain.js @@ -182,7 +182,7 @@ function goto(path) { }) } if (breadcrumbs.length > 0) - breadcrumbs[0].name = `${$t('files.icons.home')} ${breadcrumbs[0].name}` + breadcrumbs[0].name = "" this.breadcrumbs = breadcrumbs }) .finally(() => { @@ -449,8 +449,12 @@ window.onhashchange = () => { // AlpineJS i18n document.addEventListener('alpine-i18n:ready', async function () { const en = await get('/assets/languages/en.json') - const choosen = await get('/assets/languages/vi.json') - - window.AlpineI18n.create('en', { ...en, ...choosen }); - window.AlpineI18n.fallbackLocale = 'en'; + let selected = document.querySelector('#language')?.value + if (!selected || selected.length !== 2) { + window.AlpineI18n.create('en', en); + } else { + const choosen = await get(`/assets/languages/${selected}.json`) + window.AlpineI18n.create(selected, { ...en, ...choosen }); + window.AlpineI18n.fallbackLocale = 'en'; + } }); \ No newline at end of file diff --git a/assets/languages/en.json b/assets/languages/en.json index aa194ac..809910e 100644 --- a/assets/languages/en.json +++ b/assets/languages/en.json @@ -1,6 +1,14 @@ { "en": { + "language": { + "en": "English", + "vi": "Tiếng Việt" + }, "header": { + "setting": { + "title": "Setting", + "language": "Language" + }, "sort": { "title": "Sort", "name": "Name", diff --git a/assets/languages/vi.json b/assets/languages/vi.json index 2a5b328..d23cc0b 100644 --- a/assets/languages/vi.json +++ b/assets/languages/vi.json @@ -1,6 +1,10 @@ { "vi": { "header": { + "setting": { + "title": "Cài đặt", + "language": "Ngôn ngữ" + }, "sort": { "title": "Sắp xếp", "name": "Tên", diff --git a/templates/modals/all.html b/templates/modals/all.html index d5d859e..3d9445f 100644 --- a/templates/modals/all.html +++ b/templates/modals/all.html @@ -1,4 +1,5 @@ {{define "modals"}} +{{template "languageModal" .}} {{template "renameModal" .}} {{template "deleteModal" .}} {{template "destinationModal" .}} diff --git a/templates/modals/language.html b/templates/modals/language.html new file mode 100644 index 0000000..e1dd117 --- /dev/null +++ b/templates/modals/language.html @@ -0,0 +1,20 @@ +{{define "languageModal"}} + +{{end}} \ No newline at end of file diff --git a/templates/modals/premium.html b/templates/modals/premium.html index 1fd5a80..d4817ec 100644 --- a/templates/modals/premium.html +++ b/templates/modals/premium.html @@ -1,5 +1,5 @@ {{define "premiumModal"}} -