user locale
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
"title": "Gancio",
|
"title": "Gancio",
|
||||||
"description": "A shared agenda for local communities",
|
"description": "A shared agenda for local communities",
|
||||||
"favicon" : "../dist/favicon.ico",
|
"favicon" : "../dist/favicon.ico",
|
||||||
"user_locale": "./user_locale.json",
|
"user_locale": "./user_locale",
|
||||||
"baseurl": "http://localhost:13120",
|
"baseurl": "http://localhost:13120",
|
||||||
"server": {
|
"server": {
|
||||||
"host": "localhost",
|
"host": "localhost",
|
||||||
|
|||||||
33
docs/dev.md
33
docs/dev.md
@@ -1,33 +0,0 @@
|
|||||||
---
|
|
||||||
layout: default
|
|
||||||
title: Develop
|
|
||||||
permalink: /dev
|
|
||||||
nav_order: 5
|
|
||||||
---
|
|
||||||
|
|
||||||
### Development Stack
|
|
||||||
|
|
||||||
**Gancio** is built with following technologies:
|
|
||||||
|
|
||||||
- [Nuxt.js](https://nuxtjs.org/)
|
|
||||||
- Vue.js
|
|
||||||
- Express
|
|
||||||
- Sequelize
|
|
||||||
- Element.ui
|
|
||||||
|
|
||||||
### Testing on your own machine
|
|
||||||
|
|
||||||
2. Download source
|
|
||||||
```bash
|
|
||||||
git clone https://git.lattuga.net/cisti/gancio
|
|
||||||
```
|
|
||||||
|
|
||||||
3. Install dependencies
|
|
||||||
```bash
|
|
||||||
yarn
|
|
||||||
```
|
|
||||||
|
|
||||||
4. Hacking
|
|
||||||
```bash
|
|
||||||
yarn dev
|
|
||||||
```
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
const it = {
|
export default {
|
||||||
common: {
|
common: {
|
||||||
add_event: 'Nuovo evento',
|
add_event: 'Nuovo evento',
|
||||||
next: 'Continua',
|
next: 'Continua',
|
||||||
@@ -210,4 +210,3 @@ const it = {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default it
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import VueI18n from 'vue-i18n'
|
import VueI18n from 'vue-i18n'
|
||||||
import it from '../locales/it.js'
|
|
||||||
import en from '../locales/en.js'
|
|
||||||
import merge from 'lodash/merge'
|
import merge from 'lodash/merge'
|
||||||
|
import locales from '../locales'
|
||||||
|
|
||||||
Vue.use(VueI18n)
|
Vue.use(VueI18n)
|
||||||
|
|
||||||
@@ -11,12 +10,13 @@ export default async ({ app, store }) => {
|
|||||||
// This way we can use it in middleware and pages asyncData/fetch
|
// This way we can use it in middleware and pages asyncData/fetch
|
||||||
|
|
||||||
const user_locale = await app.$axios.$get('/settings/user_locale')
|
const user_locale = await app.$axios.$get('/settings/user_locale')
|
||||||
|
for(let lang in user_locale) {
|
||||||
|
if (locales[lang]) merge(locales[lang], user_locale[lang])
|
||||||
|
}
|
||||||
|
|
||||||
app.i18n = new VueI18n({
|
app.i18n = new VueI18n({
|
||||||
locale: store.state.locale,
|
locale: store.state.locale,
|
||||||
fallbackLocale: 'it',
|
fallbackLocale: 'it',
|
||||||
messages: {
|
messages: locales
|
||||||
it: merge(it, user_locale),
|
|
||||||
en: merge(en, user_locale)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
const Mastodon = require('mastodon-api')
|
const Mastodon = require('mastodon-api')
|
||||||
const { setting: Setting } = require('../models')
|
const { setting: Setting } = require('../models')
|
||||||
const config = require('config')
|
const config = require('config')
|
||||||
|
const consola = require('consola')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
|
||||||
let user_locale_path = false
|
|
||||||
if (config.user_locale && fs.existsSync(path.resolve(config.user_locale))) {
|
|
||||||
user_locale_path = path.resolve(config.user_locale)
|
|
||||||
}
|
|
||||||
|
|
||||||
const settingsController = {
|
const settingsController = {
|
||||||
settings: { initialized: false },
|
settings: { initialized: false },
|
||||||
|
user_locale: {},
|
||||||
secretSettings: {},
|
secretSettings: {},
|
||||||
|
|
||||||
// initialize instance settings from db
|
|
||||||
async initialize () {
|
async initialize () {
|
||||||
if (!settingsController.settings.initialized) {
|
if (!settingsController.settings.initialized) {
|
||||||
|
|
||||||
|
// initialize instance settings from db
|
||||||
|
// note that this is done only once when the server starts
|
||||||
|
// and not for each request (it's a kind of cache)!
|
||||||
const settings = await Setting.findAll()
|
const settings = await Setting.findAll()
|
||||||
settingsController.settings.initialized = true
|
settingsController.settings.initialized = true
|
||||||
settings.forEach( s => {
|
settings.forEach( s => {
|
||||||
@@ -25,6 +25,18 @@ const settingsController = {
|
|||||||
settingsController.settings[s.key] = s.value
|
settingsController.settings[s.key] = s.value
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// initialize user_locale
|
||||||
|
if (config.user_locale && fs.existsSync(path.resolve(config.user_locale))) {
|
||||||
|
const user_locale = fs.readdirSync(path.resolve(config.user_locale))
|
||||||
|
user_locale.forEach( async f => {
|
||||||
|
consola.info(`Loading user locale ${f}`)
|
||||||
|
const locale = path.basename(f, '.js')
|
||||||
|
settingsController.user_locale[locale] =
|
||||||
|
(await import(path.resolve(config.user_locale, f))).default
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -46,11 +58,7 @@ const settingsController = {
|
|||||||
|
|
||||||
async getUserLocale(req, res) {
|
async getUserLocale(req, res) {
|
||||||
// load user locale specified in configuration
|
// load user locale specified in configuration
|
||||||
if (user_locale_path) {
|
res.json(settingsController.user_locale)
|
||||||
res.json(require(user_locale_path))
|
|
||||||
} else {
|
|
||||||
res.json({})
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async setRequest(req, res) {
|
async setRequest(req, res) {
|
||||||
|
|||||||
@@ -94,7 +94,6 @@ api.get('/event/unconfirm/:event_id', jwt, isAuth, isAdmin, eventController.unco
|
|||||||
// get event
|
// get event
|
||||||
api.get('/event/:event_id', jwt, fillUser, eventController.get)
|
api.get('/event/:event_id', jwt, fillUser, eventController.get)
|
||||||
|
|
||||||
|
|
||||||
// export events (rss/ics)
|
// export events (rss/ics)
|
||||||
api.get('/export/:type', exportController.export)
|
api.get('/export/:type', exportController.export)
|
||||||
|
|
||||||
|
|||||||
@@ -20,4 +20,4 @@ rss(version='2.0')
|
|||||||
| <pre>!{event.description}</pre>
|
| <pre>!{event.description}</pre>
|
||||||
| ]]>
|
| ]]>
|
||||||
pubDate= new Date(event.createdAt).toUTCString()
|
pubDate= new Date(event.createdAt).toUTCString()
|
||||||
guid(isPermaLink='false') #{config.baseurl}/event/#{event.id}
|
guid(isPermaLink='false') #{config.baseurl}/event/#{event.id}
|
||||||
|
|||||||
Reference in New Issue
Block a user