diff --git a/package.json b/package.json
index 43be195..844259b 100644
--- a/package.json
+++ b/package.json
@@ -1,34 +1,35 @@
{
- "name": "audiobookslibrary",
- "version": "0.2.0",
- "private": true,
- "scripts": {
- "serve": "vue-cli-service serve",
- "build": "vue-cli-service build",
- "lint": "vue-cli-service lint"
- },
- "dependencies": {
- "@mdi/font": "^3.6.95",
- "axios": "^0.19.0",
- "core-js": "^2.6.5",
- "crypto-js": "^3.1.9-1",
- "register-service-worker": "^1.6.2",
- "vue": "^2.6.10",
- "vue-axios": "^2.1.4",
- "vuetify": "^1.5.5"
- },
- "devDependencies": {
- "@vue/cli-plugin-babel": "^3.8.0",
- "@vue/cli-plugin-eslint": "^3.8.0",
- "@vue/cli-plugin-pwa": "^3.8.0",
- "@vue/cli-service": "^3.8.0",
- "babel-eslint": "^10.0.1",
- "eslint": "^5.16.0",
- "eslint-plugin-vue": "^5.0.0",
- "stylus": "^0.54.5",
- "stylus-loader": "^3.0.1",
- "vue-cli-plugin-vuetify": "^0.5.0",
- "vue-template-compiler": "^2.6.10",
- "vuetify-loader": "^1.0.5"
- }
+ "name": "audiobookslibrary",
+ "version": "0.2.0",
+ "private": true,
+ "scripts": {
+ "serve": "vue-cli-service serve",
+ "build": "vue-cli-service build",
+ "lint": "vue-cli-service lint"
+ },
+ "dependencies": {
+ "@mdi/font": "^3.6.95",
+ "axios": "^0.19.0",
+ "core-js": "^2.6.5",
+ "crypto-js": "^3.1.9-1",
+ "register-service-worker": "^1.6.2",
+ "vue": "^2.6.10",
+ "vue-axios": "^2.1.4",
+ "vue-i18n": "^8.11.2",
+ "vuetify": "^1.5.5"
+ },
+ "devDependencies": {
+ "@vue/cli-plugin-babel": "^3.8.0",
+ "@vue/cli-plugin-eslint": "^3.8.0",
+ "@vue/cli-plugin-pwa": "^3.8.0",
+ "@vue/cli-service": "^3.8.0",
+ "babel-eslint": "^10.0.1",
+ "eslint": "^5.16.0",
+ "eslint-plugin-vue": "^5.0.0",
+ "stylus": "^0.54.5",
+ "stylus-loader": "^3.0.1",
+ "vue-cli-plugin-vuetify": "^0.5.0",
+ "vue-template-compiler": "^2.6.10",
+ "vuetify-loader": "^1.0.5"
+ }
}
diff --git a/public/locales/en.json b/public/locales/en.json
deleted file mode 100644
index 5ad24ee..0000000
--- a/public/locales/en.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "About": "About",
- "Authors": "Authors",
- "AutoBookmarks": "Autobookmarks",
- "Book": "Book",
- "BookmarkSaved": "Bookmark saved",
- "BookmarkRemoved": "Bookmark removed",
- "Books": "Books",
- "DarkTheme": "Dark theme",
- "Error": "Error",
- "Information": "Information",
- "RemoveBookmark": "Remove bookmark",
- "SetBookmark": "Set bookmark"
-}
\ No newline at end of file
diff --git a/public/locales/locales.json b/public/locales/locales.json
deleted file mode 100644
index 1a7f6aa..0000000
--- a/public/locales/locales.json
+++ /dev/null
@@ -1,37 +0,0 @@
-[
- {
- "code": "en",
- "language": "Английский",
- "file": "en.json"
- },
- {
- "code": "en-au",
- "language": "Английский",
- "file": "en.json"
- },
- {
- "code": "en-gb",
- "language": "Английский",
- "file": "en.json"
- },
- {
- "code": "en-us",
- "language": "Английский",
- "file": "en.json"
- },
- {
- "code": "ru",
- "language": "Русский",
- "file": "ru.json"
- },
- {
- "code": "ru-ru",
- "language": "Русский",
- "file": "ru.json"
- },
- {
- "code": "ru-md",
- "language": "Русский",
- "file": "ru.json"
- }
-]
\ No newline at end of file
diff --git a/public/locales/ru.json b/public/locales/ru.json
deleted file mode 100644
index 0a8445c..0000000
--- a/public/locales/ru.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "About": "О приложении",
- "Authors": "Авторы",
- "AutoBookmarks": "Автозакладки",
- "Book": "Книга",
- "BookmarkSaved": "Закладка сохранена",
- "BookmarkRemoved": "Закладка удалена",
- "Books": "Книги",
- "DarkTheme": "Тёмная тема",
- "Error": "Ошибка",
- "Information": "Информация",
- "RemoveBookmark": "Удалить закладку",
- "SetBookmark": "Установить закладку"
-}
\ No newline at end of file
diff --git a/src/App.vue b/src/App.vue
index f1faadd..6066cad 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -26,21 +26,17 @@
-
+
mdi-bookmark-plus
- {{ locale.SetBookmark }}
+ {{ $t("setBookmark") }}
-
+
mdi-bookmark-minus
- {{ locale.RemoveBookmark }}
+ {{ $t("removeBookmark") }}
@@ -61,13 +57,13 @@
- {{ locale.DarkTheme }}
+ {{ $t("darkTheme") }}
- {{ locale.AutoBookmarks }}
+ {{ $t("autoBookmarks") }}
@@ -76,7 +72,7 @@
mdi-information-variant
- {{ locale.About }}
+ {{ $t("about") }}
@@ -89,15 +85,15 @@
centered
fixed-tabs
>
- {{ locale.Authors }}
+ {{ $t("authors") }}
- {{ locale.Books }}
+ {{ $t("books") }}
- {{ locale.Book }}
+ {{ $t("book") }}
@@ -188,8 +184,13 @@
darkTheme: false,
isLoading: false,
isMounted: false,
- volume: 5,
- locale: []
+ locale: { flag: 'ru', language: 'ru', title: 'Русский' },
+ locales: [
+ { flag: 'us', language: 'en', title: 'English' },
+ { flag: 'ru', language: 'ru', title: 'Русский' }
+ ],
+ volume: 5//,
+ //locale: []
}
},
@@ -203,6 +204,7 @@
let userLocale = navigator.language || navigator.userLanguage;
+ /*
this.axios.get("locales/locales.json")
.then(response => {
let localeLoaded = false;
@@ -218,7 +220,7 @@
console.log(error);
this.showMessage("Error", error);
});
-
+ */
this.axios.get("config.json")
.then(response => {
this.appNet = response.data.AppNet;
@@ -226,7 +228,7 @@
})
.catch(error => {
console.log(error);
- this.showMessage(this.locale.Error, error);
+ this.showMessage(this.$t("error"), error);
});
this.axios.get("lib/authors.json")
@@ -236,7 +238,7 @@
})
.catch(error => {
console.log(error);
- this.showMessage(this.locale.Error, error);
+ this.showMessage(this.$t("error"), error);
});
},
@@ -305,6 +307,7 @@
return hash.toString(CryptoJS.enc.Hex);
},
+ /*
loadLocale (langFile) {
this.axios.get("locales/" + langFile)
.then(response => {
@@ -315,6 +318,7 @@
this.showMessage("Error", error);
});
},
+ */
nextChapter () { this.$refs.Book.nextChapter(); },
@@ -345,7 +349,7 @@
.catch(error => {
this.isLoading = false;
console.log(error);
- this.showMessage(this.locale.Error, error);
+ this.showMessage(this.$t("error"), error);
});
this.activeTab = 2;
@@ -365,7 +369,7 @@
.catch(error => {
this.isLoading = false;
console.log(error);
- this.showMessage(this.locale.Error, error);
+ this.showMessage(this.$t("error"), error);
});
},
@@ -385,7 +389,7 @@
removeBookmark (silent = true) {
if (this.$refs.Book.items.length == 0) { return; }
localStorage.removeItem(this.getHash(this.$refs.Book.items));
- if (!silent) { this.showMessage(this.locale.Information, this.locale.BookmarkRemoved); }
+ if (!silent) { this.showMessage(this.$t("information"), this.$t("bookmarkRemoved")); }
},
setBookmark (silent = true) {
@@ -401,7 +405,16 @@
JSON.stringify(data)
);
- if (!silent) { this.showMessage(this.locale.Information, this.locale.BookmarkSaved); }
+ if (!silent) { this.showMessage(this.$t("information"), this.$t("bookmarkSaved")); }
+ },
+
+ setLocale (locale) {
+ this.locales.forEach(element => {
+ if (element.language == locale) {
+ this.locale = element;
+ }
+ });
+ this.$i18n.locale = locale;
},
showAboutDialog () {
@@ -422,7 +435,7 @@
"
Published under MIT license" +
"Git: https://home.cainet.info:3000/cai/AudioLib";
}
- this.showMessage(this.locale.About, aboutText);
+ this.showMessage(this.$t("about"), aboutText);
},
showMessage (title, text) {
diff --git a/src/main.js b/src/main.js
index 8a56948..36d7590 100644
--- a/src/main.js
+++ b/src/main.js
@@ -12,6 +12,7 @@ import Vue from 'vue'
import Axios from 'axios'
import VueAxios from 'vue-axios'
import './plugins/vuetify'
+import i18n from '@/plugins/i18n';
import App from './App.vue'
import './registerServiceWorker'
@@ -29,5 +30,6 @@ Vue.prototype.statuses = {
};
new Vue({
+ i18n,
render: h => h(App),
}).$mount('#app')
diff --git a/src/plugins/i18n.js b/src/plugins/i18n.js
new file mode 100644
index 0000000..6c807f2
--- /dev/null
+++ b/src/plugins/i18n.js
@@ -0,0 +1,43 @@
+import Vue from 'vue'
+import VueI18n from 'vue-i18n'
+
+Vue.use(VueI18n)
+
+const messages = {
+ "en": {
+ about: "About",
+ authors: "Authors",
+ autoBookmarks: "Autobookmarks",
+ book: "Book",
+ bookmarkSaved: "Bookmark saved",
+ bookmarkRemoved: "Bookmark removed",
+ books: "Books",
+ darkTheme: "Dark theme",
+ error: "Error",
+ information: "Information",
+ removeBookmark: "Remove bookmark",
+ setBookmark: "Set bookmark"
+ },
+ "ru": {
+ about: "О приложении",
+ authors: "Авторы",
+ autoBookmarks: "Автозакладки",
+ book: "Книга",
+ bookmarkSaved: "Закладка сохранена",
+ bookmarkRemoved: "Закладка удалена",
+ books: "Книги",
+ darkTheme: "Тёмная тема",
+ error: "Ошибка",
+ information: "Информация",
+ removeBookmark: "Удалить закладку",
+ setBookmark: "Установить закладку"
+ }
+}
+
+const i18n = new VueI18n({
+ locale: "ru", // set locale
+ fallbackLocale: "en", // set fallback locale
+ messages, // set locale messages
+})
+
+export default i18n
\ No newline at end of file
diff --git a/yarn.lock b/yarn.lock
index db20071..3faa4e0 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -8067,6 +8067,11 @@ vue-hot-reload-api@^2.3.0:
resolved "https://registry.yarnpkg.com/vue-hot-reload-api/-/vue-hot-reload-api-2.3.3.tgz#2756f46cb3258054c5f4723de8ae7e87302a1ccf"
integrity sha512-KmvZVtmM26BQOMK1rwUZsrqxEGeKiYSZGA7SNWE6uExx8UX/cj9hq2MRV/wWC3Cq6AoeDGk57rL9YMFRel/q+g==
+vue-i18n@^8.11.2:
+ version "8.11.2"
+ resolved "https://registry.yarnpkg.com/vue-i18n/-/vue-i18n-8.11.2.tgz#92827fc42449f4602d2a0ddb437dfc4e3370d9d7"
+ integrity sha512-STcpmxqBrG77SyWi7e0Yn/B3DjKR6mSDwYS4F/V7zoi+e/+CPbVb2TaBqFwnrkoDcPmRfjM7nTwsiRQQOGdifw==
+
vue-loader@^15.7.0:
version "15.7.0"
resolved "https://registry.yarnpkg.com/vue-loader/-/vue-loader-15.7.0.tgz#27275aa5a3ef4958c5379c006dd1436ad04b25b3"