diff options
Diffstat (limited to 'server/initializers')
-rw-r--r-- | server/initializers/constants.ts | 70 | ||||
-rw-r--r-- | server/initializers/migrations/0210-video-language.ts | 162 |
2 files changed, 199 insertions, 33 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index d1915586a..9c9c3afc0 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -13,7 +13,7 @@ let config: IConfig = require('config') | |||
13 | 13 | ||
14 | // --------------------------------------------------------------------------- | 14 | // --------------------------------------------------------------------------- |
15 | 15 | ||
16 | const LAST_MIGRATION_VERSION = 205 | 16 | const LAST_MIGRATION_VERSION = 210 |
17 | 17 | ||
18 | // --------------------------------------------------------------------------- | 18 | // --------------------------------------------------------------------------- |
19 | 19 | ||
@@ -196,6 +196,7 @@ const CONSTRAINTS_FIELDS = { | |||
196 | }, | 196 | }, |
197 | VIDEOS: { | 197 | VIDEOS: { |
198 | NAME: { min: 3, max: 120 }, // Length | 198 | NAME: { min: 3, max: 120 }, // Length |
199 | LANGUAGE: { min: 1, max: 10 }, // Length | ||
199 | TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length | 200 | TRUNCATED_DESCRIPTION: { min: 3, max: 250 }, // Length |
200 | DESCRIPTION: { min: 3, max: 10000 }, // Length | 201 | DESCRIPTION: { min: 3, max: 10000 }, // Length |
201 | SUPPORT: { min: 3, max: 300 }, // Length | 202 | SUPPORT: { min: 3, max: 300 }, // Length |
@@ -291,38 +292,7 @@ const VIDEO_LICENCES = { | |||
291 | 7: 'Public Domain Dedication' | 292 | 7: 'Public Domain Dedication' |
292 | } | 293 | } |
293 | 294 | ||
294 | // See https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers#Nationalencyklopedin | 295 | const VIDEO_LANGUAGES = buildLanguages() |
295 | const VIDEO_LANGUAGES = { | ||
296 | 1: 'English', | ||
297 | 2: 'Spanish', | ||
298 | 3: 'Mandarin', | ||
299 | 4: 'Hindi', | ||
300 | 5: 'Arabic', | ||
301 | 6: 'Portuguese', | ||
302 | 7: 'Bengali', | ||
303 | 8: 'Russian', | ||
304 | 9: 'Japanese', | ||
305 | 10: 'Punjabi', | ||
306 | 11: 'German', | ||
307 | 12: 'Korean', | ||
308 | 13: 'French', | ||
309 | 14: 'Italian', | ||
310 | 1000: 'Sign Language', | ||
311 | 1001: 'American Sign Language', | ||
312 | 1002: 'Arab Sign Language', | ||
313 | 1003: 'British Sign Language', | ||
314 | 1004: 'Brazilian Sign Language', | ||
315 | 1005: 'Chinese Sign Language', | ||
316 | 1006: 'Czech Sign Language', | ||
317 | 1007: 'Danish Sign Language', | ||
318 | 1008: 'French Sign Language', | ||
319 | 1009: 'German Sign Language', | ||
320 | 1010: 'Indo-Pakistani Sign Language', | ||
321 | 1011: 'Japanese Sign Language', | ||
322 | 1012: 'South African Sign Language', | ||
323 | 1013: 'Swedish Sign Language', | ||
324 | 1014: 'Russian Sign Language' | ||
325 | } | ||
326 | 296 | ||
327 | const VIDEO_PRIVACIES = { | 297 | const VIDEO_PRIVACIES = { |
328 | [VideoPrivacy.PUBLIC]: 'Public', | 298 | [VideoPrivacy.PUBLIC]: 'Public', |
@@ -521,6 +491,40 @@ function updateWebserverConfig () { | |||
521 | CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP) | 491 | CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP) |
522 | } | 492 | } |
523 | 493 | ||
494 | function buildLanguages () { | ||
495 | const iso639 = require('iso-639-3') | ||
496 | |||
497 | const languages: { [ id: string ]: string } = {} | ||
498 | |||
499 | const signLanguages = [ | ||
500 | 'sgn', // Sign languages (macro language) | ||
501 | 'ase', // American | ||
502 | 'sdl', // Arabian | ||
503 | 'bfi', // British | ||
504 | 'bzs', // Brazilian | ||
505 | 'csl', // Chinese | ||
506 | 'cse', // Czech | ||
507 | 'dsl', // Danish | ||
508 | 'fsl', // French | ||
509 | 'gsg', // German | ||
510 | 'pks', // Pakistan | ||
511 | 'jsl', // Japanese | ||
512 | 'sfs', // South African | ||
513 | 'swl', // Swedish | ||
514 | 'rsl' // Russian | ||
515 | ] | ||
516 | |||
517 | // Only add ISO639-1 languages and some sign languages (ISO639-3) | ||
518 | iso639 | ||
519 | .filter(l => { | ||
520 | return (l.iso6391 !== null && l.type === 'living') || | ||
521 | signLanguages.indexOf(l.iso6393) !== -1 | ||
522 | }) | ||
523 | .forEach(l => languages[l.iso6391 || l.iso6393] = l.name) | ||
524 | |||
525 | return languages | ||
526 | } | ||
527 | |||
524 | export function reloadConfig () { | 528 | export function reloadConfig () { |
525 | 529 | ||
526 | function directory () { | 530 | function directory () { |
diff --git a/server/initializers/migrations/0210-video-language.ts b/server/initializers/migrations/0210-video-language.ts new file mode 100644 index 000000000..b7ec90905 --- /dev/null +++ b/server/initializers/migrations/0210-video-language.ts | |||
@@ -0,0 +1,162 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | import { CONSTRAINTS_FIELDS } from '../index' | ||
3 | |||
4 | async function up (utils: { | ||
5 | transaction: Sequelize.Transaction, | ||
6 | queryInterface: Sequelize.QueryInterface, | ||
7 | sequelize: Sequelize.Sequelize | ||
8 | }): Promise<void> { | ||
9 | |||
10 | { | ||
11 | await utils.queryInterface.renameColumn('video', 'language', 'oldLanguage') | ||
12 | } | ||
13 | |||
14 | { | ||
15 | const data = { | ||
16 | type: Sequelize.STRING(CONSTRAINTS_FIELDS.VIDEOS.LANGUAGE.max), | ||
17 | allowNull: true, | ||
18 | defaultValue: null | ||
19 | } | ||
20 | await utils.queryInterface.addColumn('video', 'language', data) | ||
21 | } | ||
22 | |||
23 | { | ||
24 | const languages = [ | ||
25 | { | ||
26 | oldLanguage: 1, | ||
27 | newLanguage: 'en' | ||
28 | }, | ||
29 | { | ||
30 | oldLanguage: 2, | ||
31 | newLanguage: 'es' | ||
32 | }, | ||
33 | { | ||
34 | oldLanguage: 3, | ||
35 | newLanguage: 'zh' | ||
36 | }, | ||
37 | { | ||
38 | oldLanguage: 4, | ||
39 | newLanguage: 'hi' | ||
40 | }, | ||
41 | { | ||
42 | oldLanguage: 5, | ||
43 | newLanguage: 'ar' | ||
44 | }, | ||
45 | { | ||
46 | oldLanguage: 6, | ||
47 | newLanguage: 'pt' | ||
48 | }, | ||
49 | { | ||
50 | oldLanguage: 7, | ||
51 | newLanguage: 'bn' | ||
52 | }, | ||
53 | { | ||
54 | oldLanguage: 8, | ||
55 | newLanguage: 'ru' | ||
56 | }, | ||
57 | { | ||
58 | oldLanguage: 9, | ||
59 | newLanguage: 'ja' | ||
60 | }, | ||
61 | { | ||
62 | oldLanguage: 10, | ||
63 | newLanguage: 'pa' | ||
64 | }, | ||
65 | { | ||
66 | oldLanguage: 11, | ||
67 | newLanguage: 'de' | ||
68 | }, | ||
69 | { | ||
70 | oldLanguage: 12, | ||
71 | newLanguage: 'ko' | ||
72 | }, | ||
73 | { | ||
74 | oldLanguage: 13, | ||
75 | newLanguage: 'fr' | ||
76 | }, | ||
77 | { | ||
78 | oldLanguage: 14, | ||
79 | newLanguage: 'it' | ||
80 | }, | ||
81 | { | ||
82 | oldLanguage: 1000, | ||
83 | newLanguage: 'sgn' | ||
84 | }, | ||
85 | { | ||
86 | oldLanguage: 1001, | ||
87 | newLanguage: 'ase' | ||
88 | }, | ||
89 | { | ||
90 | oldLanguage: 1002, | ||
91 | newLanguage: 'sdl' | ||
92 | }, | ||
93 | { | ||
94 | oldLanguage: 1003, | ||
95 | newLanguage: 'bfi' | ||
96 | }, | ||
97 | { | ||
98 | oldLanguage: 1004, | ||
99 | newLanguage: 'bzs' | ||
100 | }, | ||
101 | { | ||
102 | oldLanguage: 1005, | ||
103 | newLanguage: 'csl' | ||
104 | }, | ||
105 | { | ||
106 | oldLanguage: 1006, | ||
107 | newLanguage: 'cse' | ||
108 | }, | ||
109 | { | ||
110 | oldLanguage: 1007, | ||
111 | newLanguage: 'dsl' | ||
112 | }, | ||
113 | { | ||
114 | oldLanguage: 1008, | ||
115 | newLanguage: 'fsl' | ||
116 | }, | ||
117 | { | ||
118 | oldLanguage: 1009, | ||
119 | newLanguage: 'gsg' | ||
120 | }, | ||
121 | { | ||
122 | oldLanguage: 1010, | ||
123 | newLanguage: 'pks' | ||
124 | }, | ||
125 | { | ||
126 | oldLanguage: 1011, | ||
127 | newLanguage: 'jsl' | ||
128 | }, | ||
129 | { | ||
130 | oldLanguage: 1012, | ||
131 | newLanguage: 'sfs' | ||
132 | }, | ||
133 | { | ||
134 | oldLanguage: 1013, | ||
135 | newLanguage: 'swl' | ||
136 | }, | ||
137 | { | ||
138 | oldLanguage: 1014, | ||
139 | newLanguage: 'rsl' | ||
140 | } | ||
141 | ] | ||
142 | |||
143 | for (const language of languages) { | ||
144 | const query = 'UPDATE "video" SET "language" = \'' + language.newLanguage + '\' WHERE "oldLanguage" = ' + language.oldLanguage | ||
145 | await utils.sequelize.query(query) | ||
146 | } | ||
147 | } | ||
148 | |||
149 | { | ||
150 | await utils.queryInterface.removeColumn('video', 'oldLanguage') | ||
151 | } | ||
152 | |||
153 | } | ||
154 | |||
155 | function down (options) { | ||
156 | throw new Error('Not implemented.') | ||
157 | } | ||
158 | |||
159 | export { | ||
160 | up, | ||
161 | down | ||
162 | } | ||