Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / i18n / scripts / extract.sh
blob3c24eb5b8bda54c7a1d15505d5bd34e36d886949
1 #!/usr/bin/env bash
2 set -eo pipefail
4 ##
5 # Extract all the files we need to parse to get the translations
6 # - react-components
7 # - proton-shared
8 # - app sources
10 # We remove as much files a possible so it's faster
11 getFileList() {
12 # Remove what we do not need to filter + it makes find more complex
13 rm -rf node_modules | true
14 rm -rf webpack:/*/webpack | true
15 rm -rf webpack:/*/locales | true
17 grep -Ril "from 'ttag'" .
20 getDistDirectory() {
21 if [ -s "dist" ]; then
22 echo "extract from dist bundle local"
23 return 0
26 # Cache for the CI so we're faster
27 if [ -s 'webapp-bundle.tar.gz' ]; then
28 echo "we extract the bundle"
29 rm -rf dist || true
30 mkdir dist
31 tar xzf webapp-bundle.tar.gz -C dist
32 else
33 echo "bundle must be built first"
34 exit 1
38 function main {
39 ls -lSha
40 pwd;
42 appName="$(jq -r .name package.json)"
44 if [ ! -d "/tmp/sourcemapper" ]; then
45 echo "missing source mapper, run ./build.sh"
46 exit 1
47 fi;
49 getDistDirectory
51 # Extract all the code available inside the dist and only the one we built (post tree-shacking)
52 for file in $(find ./dist/ -type f -name "*.js.map"); do
53 echo "[Parsing] $file";
54 if [[ "$OSTYPE" = "darwin"* ]]; then
55 if [[ "$(uname -m)" == 'arm64' ]]; then
56 /tmp/sourcemapper/bin/isourcemapper-arm --input "$file" --output 'i18n-js' &> /dev/null &
57 else
58 /tmp/sourcemapper/bin/isourcemapper --input "$file" --output 'i18n-js' &> /dev/null &
60 else
61 /tmp/sourcemapper/bin/sourcemapper --input "$file" --output 'i18n-js' &> /dev/null &
63 done;
65 wait;
67 # Extract on top of the extracted code from the bundle
68 # Use direct relative path instead of npx or dlx since it doesn't resolve to the installed dependencies
70 cd i18n-js;
71 echo "Running ttag extract"
72 # Output from ttag extract is full of babel errors, silence it
73 ../../../node_modules/.bin/ttag extract $(getFileList) -o "../${1}" 2>&1;
74 echo "done"
77 # Remove useless path
78 if [[ "$OSTYPE" = "darwin"* ]]; then
79 sed -i '' 's|webpack:/||g;s| /src/app/| src/app/|g' "$1";
80 else
81 sed -i 's|webpack:/||g;s| /src/app/| src/app/|g' "$1";
84 #rm -rf "./i18n-js";
87 main "$1";