Commit 04943a36 authored by les's avatar les
Browse files

user locale

parent 0cf02a0b
......@@ -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",
......
---
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
```
const it = {
export default {
common: {
add_event: 'Nuovo evento',
next: 'Continua',
......@@ -210,4 +210,3 @@ const it = {
}
export default it
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
})
}
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) {
......
......@@ -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)
......
......@@ -20,4 +20,4 @@ rss(version='2.0')
| <pre>!{event.description}</pre>
| ]]>
pubDate= new Date(event.createdAt).toUTCString()
guid(isPermaLink='false') #{config.baseurl}/event/#{event.id}
\ No newline at end of file
guid(isPermaLink='false') #{config.baseurl}/event/#{event.id}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment