From 1dbf078728d7aafb83e58f7f3ce86e4179c2e414 Mon Sep 17 00:00:00 2001 From: liushuyu Date: Tue, 10 Dec 2019 00:53:26 -0700 Subject: [PATCH] i18n: automated locale detection and... ... manual selection box --- ui/merge-strings.js | 16 +++++++++++ ui/package.json | 5 +++- ui/src/App.vue | 35 ++++++++++++++++++++++++ ui/src/locales/.gitignore | 1 + ui/src/locales/en.json | 55 ++++++++++++++++++++++++++++++++++++++ ui/src/locales/messages.js | 54 ------------------------------------- ui/src/main.js | 2 +- ui/yarn.lock | 7 ++++- 8 files changed, 118 insertions(+), 57 deletions(-) create mode 100755 ui/merge-strings.js create mode 100644 ui/src/locales/.gitignore create mode 100644 ui/src/locales/en.json delete mode 100644 ui/src/locales/messages.js diff --git a/ui/merge-strings.js b/ui/merge-strings.js new file mode 100755 index 0000000..ccf624a --- /dev/null +++ b/ui/merge-strings.js @@ -0,0 +1,16 @@ +#!/bin/env node +const fs = require('fs') +const merge = require('deepmerge') +const glob = require('glob') + +glob('src/locales/!(messages).json', {}, (e, files) => { + let messages = [] + for (const file of files) { + console.log(`Loading ${file}...`) + const locale_messages = require(`./${file}`) + messages.push(locale_messages) + } + console.log('Merging messages...') + messages = merge.all(messages) + fs.writeFileSync('src/locales/messages.json', JSON.stringify(messages), {}) +}) diff --git a/ui/package.json b/ui/package.json index 6d6ea87..bb3baf9 100644 --- a/ui/package.json +++ b/ui/package.json @@ -5,7 +5,8 @@ "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", - "lint": "vue-cli-service lint" + "lint": "vue-cli-service lint", + "postinstall": "node merge-strings.js" }, "dependencies": { "axios": "^0.19.0", @@ -21,6 +22,7 @@ "@vue/cli-service": "^4.1.1", "@vue/eslint-config-standard": "^5.0.1", "babel-eslint": "^10.0.3", + "deepmerge": "^4.2.2", "eslint": "^6.7.2", "eslint-plugin-import": "^2.18.2", "eslint-plugin-node": "^10.0.0", @@ -28,6 +30,7 @@ "eslint-plugin-standard": "^4.0.1", "eslint-plugin-vue": "^6.0.1", "express": "^4.17.1", + "glob": "^7.1.6", "http-proxy-middleware": "^0.20.0", "vue-template-compiler": "^2.6.10" } diff --git a/ui/src/App.vue b/ui/src/App.vue index ec584d4..c3214d7 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -18,6 +18,14 @@

{{ $t('app.maintenance_title', {'name': $root.$data.attrs.name}) }}

+ + + + {{locale.locale}} + @@ -27,6 +35,33 @@ + +