user locale

This commit is contained in:
lesion 2019-07-26 23:51:32 +02:00
parent 0cf02a0b53
commit 04943a36b3
7 changed files with 28 additions and 55 deletions

View file

@ -2,7 +2,7 @@
"title": "Gancio",
"description": "A shared agenda for local communities",
"favicon" : "../dist/favicon.ico",
"user_locale": "./user_locale.json",
"user_locale": "./user_locale",
"baseurl": "http://localhost:13120",
"server": {
"host": "localhost",

View file

@ -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
```

View file

@ -1,4 +1,4 @@
const it = {
export default {
common: {
add_event: 'Nuovo evento',
next: 'Continua',
@ -210,4 +210,3 @@ const it = {
}
export default it

View file

@ -1,8 +1,7 @@
import Vue from 'vue'
import VueI18n from 'vue-i18n'
import it from '../locales/it.js'
import en from '../locales/en.js'
import merge from 'lodash/merge'
import locales from '../locales'
Vue.use(VueI18n)
@ -11,12 +10,13 @@ export default async ({ app, store }) => {
// This way we can use it in middleware and pages asyncData/fetch
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({
locale: store.state.locale,
fallbackLocale: 'it',
messages: {
it: merge(it, user_locale),
en: merge(en, user_locale)
}
messages: locales
})
}

View file

@ -1,21 +1,21 @@
const Mastodon = require('mastodon-api')
const { setting: Setting } = require('../models')
const config = require('config')
const consola = require('consola')
const path = require('path')
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 = {
settings: { initialized: false },
user_locale: {},
secretSettings: {},
// initialize instance settings from db
async initialize () {
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()
settingsController.settings.initialized = true
settings.forEach( s => {
@ -25,6 +25,18 @@ const settingsController = {
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) {
// load user locale specified in configuration
if (user_locale_path) {
res.json(require(user_locale_path))
} else {
res.json({})
}
res.json(settingsController.user_locale)
},
async setRequest(req, res) {

View file

@ -94,7 +94,6 @@ api.get('/event/unconfirm/:event_id', jwt, isAuth, isAdmin, eventController.unco
// get event
api.get('/event/:event_id', jwt, fillUser, eventController.get)
// export events (rss/ics)
api.get('/export/:type', exportController.export)