]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - scripts/build/client.sh
Support i18n build
[github/Chocobozzz/PeerTube.git] / scripts / build / client.sh
index 780adb0c6c891dd48e86fff17602da268a6b86e6..99394838aa3bd578c3a9585754fd7b884c72e9cd 100755 (executable)
@@ -2,24 +2,26 @@
 
 set -eu
 
+declare -A languages
+
 pre_build_hook () {
-  mkdir "./src/locale/pending_target/" > /dev/null || true
-  mv ./src/locale/target/angular_*.xml "./src/locale/pending_target"
+  mkdir "./src/pending_locale" > /dev/null || true
+  mv ./src/locale/angular.*.xlf "./src/pending_locale"
 
   if [ ! -z ${1+x} ]; then
-    mv "./src/locale/pending_target/angular_$1.xml" "./src/locale/target"
+    mv "./src/pending_locale/angular.$1.xlf" "./src/locale"
   fi
 }
 
 post_build_hook () {
-  mv ./src/locale/pending_target/* "./src/locale/target/"
-  rmdir "./src/locale/pending_target/"
+  mv ./src/pending_locale/* "./src/locale"
+  rmdir "./src/pending_locale/"
 }
 
 # Previous build failed
-if [ ! -f client/src/locale/target/angular_fr_FR.xml ]; then
-    git checkout -- client/src/locale/target/
-    rm -r client/src/locale/pending_target/
+if [ ! -f "client/src/locale/angular.fr-FR.xlf" ]; then
+    git checkout -- client/src/locale/
+    rm -r client/src/pending_locale
 fi
 
 cd client
@@ -28,7 +30,7 @@ rm -rf ./dist ./compiled
 
 pre_build_hook
 
-defaultLanguage="en_US"
+defaultLanguage="en-US"
 npm run ng build -- --output-path "dist/$defaultLanguage/" --deploy-url "/client/$defaultLanguage/" --prod --stats-json
 mv "./dist/$defaultLanguage/assets" "./dist"
 mv "./dist/$defaultLanguage/manifest.webmanifest" "./dist/manifest.webmanifest"
@@ -38,20 +40,48 @@ post_build_hook
 # Don't build other languages if --light arg is provided
 if [ -z ${1+x} ] || [ "$1" != "--light" ]; then
     if [ ! -z ${1+x} ] && [ "$1" == "--light-fr" ]; then
-        languages=("fr_FR")
+        languages=(["fr"]="fr-FR")
     else
         # Supported languages
-        languages=("zh_Hant_TW" "fr_FR" "ja_JP" "eu_ES" "ca_ES" "cs_CZ" "eo" "de_DE" "it_IT" "nl_NL" "es_ES" "oc" "pt_BR" "pt_PT" "sv_SE" "pl_PL" "ru_RU" "zh_Hans_CN")
+        languages=(
+            ["hu"]="hu-HU"
+            ["th"]="th-TH"
+            ["fi"]="fi-FI"
+            ["nl"]="nl-NL"
+            ["gd"]="gd"
+            ["el"]="el-GR"
+            ["es"]="es-ES"
+            ["oc"]="oc"
+            ["pt"]="pt-BR"
+            ["pt-PT"]="pt-PT"
+            ["sv"]="sv-SE"
+            ["pl"]="pl-PL"
+            ["ru"]="ru-RU"
+            ["zh-Hans"]="zh-Hans-CN"
+            ["zh-Hant"]="zh-Hant-TW"
+            ["fr"]="fr-FR"
+            ["ja"]="ja-JP"
+            ["eu"]="eu-ES"
+            ["ca"]="ca-ES"
+            ["cs"]="cs-CZ"
+            ["eo"]="eo"
+            ["de"]="de-DE"
+            ["it"]="it-IT"
+        )
     fi
 
-    for lang in "${languages[@]}"; do
+    for key in "${!languages[@]}"; do
+        lang=${languages[$key]}
+
         # TODO: remove when the project will use runtime translations
         pre_build_hook "$lang"
 
-        npm run ng build -- --prod --i18n-file "./src/locale/target/angular_$lang.xml" --i18n-format xlf --i18n-locale "$lang" \
-            --output-path "dist/$lang/" --deploy-url "/client/$lang/"
+        npm run ng build --  --output-path "dist/build" --deploy-url "/client/$lang/" --prod --configuration="$lang"
+
+        mv "dist/build/$key" "dist/$lang"
+        rmdir "dist/build"
 
-        # Do no duplicate assets
+        # Do not duplicate assets
         rm -r "./dist/$lang/assets"
 
         # TODO: remove when the project will use runtime translations
@@ -59,7 +89,7 @@ if [ -z ${1+x} ] || [ "$1" != "--light" ]; then
     done
 fi
 
-NODE_ENV=production npm run webpack -- --config webpack/webpack.video-embed.js --mode production --json > "./dist/embed-stats.json"
+cd ../ && npm run build:embed && cd client/
 
 # Copy runtime locales
-cp -r "./src/locale/target" "./dist/locale"
+cp -r "./src/locale" "./dist/locale"