locales.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. const Model = require('objection').Model
  2. /**
  3. * Locales model
  4. */
  5. module.exports = class Locale extends Model {
  6. static get tableName() { return 'locales' }
  7. static get idColumn() { return 'code' }
  8. static get jsonSchema () {
  9. return {
  10. type: 'object',
  11. required: ['code', 'name'],
  12. properties: {
  13. code: {type: 'string'},
  14. isRTL: {type: 'boolean', default: false},
  15. name: {type: 'string'},
  16. nativeName: {type: 'string'},
  17. createdAt: {type: 'string'},
  18. updatedAt: {type: 'string'},
  19. availability: {type: 'integer'}
  20. }
  21. }
  22. }
  23. static get jsonAttributes() {
  24. return ['strings']
  25. }
  26. $beforeUpdate() {
  27. this.updatedAt = new Date().toISOString()
  28. }
  29. $beforeInsert() {
  30. this.createdAt = new Date().toISOString()
  31. this.updatedAt = new Date().toISOString()
  32. }
  33. static async getNavLocales({ cache = false } = {}) {
  34. return []
  35. // if (!WIKI.config.lang.namespacing) {
  36. // return []
  37. // }
  38. // if (cache) {
  39. // const navLocalesCached = await WIKI.cache.get('nav:locales')
  40. // if (navLocalesCached) {
  41. // return navLocalesCached
  42. // }
  43. // }
  44. // const navLocales = await WIKI.db.locales.query().select('code', 'nativeName AS name').whereIn('code', WIKI.config.lang.namespaces).orderBy('code')
  45. // if (navLocales) {
  46. // if (cache) {
  47. // await WIKI.cache.set('nav:locales', navLocales, 300)
  48. // }
  49. // return navLocales
  50. // } else {
  51. // WIKI.logger.warn('Site Locales for navigation are missing or corrupted.')
  52. // return []
  53. // }
  54. }
  55. }