]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - scripts/build/client.sh
Support i18n build
[github/Chocobozzz/PeerTube.git] / scripts / build / client.sh
1 #!/bin/bash
2
3 set -eu
4
5 declare -A languages
6
7 pre_build_hook () {
8 mkdir "./src/pending_locale" > /dev/null || true
9 mv ./src/locale/angular.*.xlf "./src/pending_locale"
10
11 if [ ! -z ${1+x} ]; then
12 mv "./src/pending_locale/angular.$1.xlf" "./src/locale"
13 fi
14 }
15
16 post_build_hook () {
17 mv ./src/pending_locale/* "./src/locale"
18 rmdir "./src/pending_locale/"
19 }
20
21 # Previous build failed
22 if [ ! -f "client/src/locale/angular.fr-FR.xlf" ]; then
23 git checkout -- client/src/locale/
24 rm -r client/src/pending_locale
25 fi
26
27 cd client
28
29 rm -rf ./dist ./compiled
30
31 pre_build_hook
32
33 defaultLanguage="en-US"
34 npm run ng build -- --output-path "dist/$defaultLanguage/" --deploy-url "/client/$defaultLanguage/" --prod --stats-json
35 mv "./dist/$defaultLanguage/assets" "./dist"
36 mv "./dist/$defaultLanguage/manifest.webmanifest" "./dist/manifest.webmanifest"
37
38 post_build_hook
39
40 # Don't build other languages if --light arg is provided
41 if [ -z ${1+x} ] || [ "$1" != "--light" ]; then
42 if [ ! -z ${1+x} ] && [ "$1" == "--light-fr" ]; then
43 languages=(["fr"]="fr-FR")
44 else
45 # Supported languages
46 languages=(
47 ["hu"]="hu-HU"
48 ["th"]="th-TH"
49 ["fi"]="fi-FI"
50 ["nl"]="nl-NL"
51 ["gd"]="gd"
52 ["el"]="el-GR"
53 ["es"]="es-ES"
54 ["oc"]="oc"
55 ["pt"]="pt-BR"
56 ["pt-PT"]="pt-PT"
57 ["sv"]="sv-SE"
58 ["pl"]="pl-PL"
59 ["ru"]="ru-RU"
60 ["zh-Hans"]="zh-Hans-CN"
61 ["zh-Hant"]="zh-Hant-TW"
62 ["fr"]="fr-FR"
63 ["ja"]="ja-JP"
64 ["eu"]="eu-ES"
65 ["ca"]="ca-ES"
66 ["cs"]="cs-CZ"
67 ["eo"]="eo"
68 ["de"]="de-DE"
69 ["it"]="it-IT"
70 )
71 fi
72
73 for key in "${!languages[@]}"; do
74 lang=${languages[$key]}
75
76 # TODO: remove when the project will use runtime translations
77 pre_build_hook "$lang"
78
79 npm run ng build -- --output-path "dist/build" --deploy-url "/client/$lang/" --prod --configuration="$lang"
80
81 mv "dist/build/$key" "dist/$lang"
82 rmdir "dist/build"
83
84 # Do not duplicate assets
85 rm -r "./dist/$lang/assets"
86
87 # TODO: remove when the project will use runtime translations
88 post_build_hook
89 done
90 fi
91
92 cd ../ && npm run build:embed && cd client/
93
94 # Copy runtime locales
95 cp -r "./src/locale" "./dist/locale"