Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed May 15, 2024
1 parent 4c31d77 commit 6ac1fc5
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 2,358 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ testCSV.csv
apache-superset-*.tar.gz*
release.json

# Translation binaries
# Translation-related files
# these json files are generated by ./scripts/po2json.sh
superset/translations/**/messages.json
# these mo binary files are generated by `pybabel compile`
superset/translations/**/messages.mo

docker/requirements-local.txt
Expand Down
22 changes: 15 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ RUN --mount=type=bind,target=./package.json,src=./superset-frontend/package.json
COPY ./superset-frontend ./
# This seems to be the most expensive step
RUN npm run ${BUILD_CMD}

# Compile translations for the frontend
WORKDIR /app
COPY superset/translations ./superset/translations
COPY ./scripts/po2json.sh ./scripts/po2json.sh
RUN ./scripts/po2json.sh
COPY ./scripts/translations/po2json.sh ./scripts/translations/po2json.sh
RUN ./scripts/translations/po2json.sh

######################################################################
# Final lean image...
Expand Down Expand Up @@ -87,16 +90,21 @@ RUN --mount=type=cache,target=/root/.cache/pip \
pip install --upgrade setuptools pip && \
pip install -r requirements/base.txt

# Copy the compiled frontend assets
COPY --chown=superset:superset --from=superset-node /app/superset/static/assets superset/static/assets

# Copy the compiled translations for the frontend
COPY --chown=superset:superset --from=superset-node /app/superset/superset/translations/*/LC_MESSAGES/*.json superset/static/translations

## Lastly, let's install superset itself
COPY --chown=superset:superset superset superset
RUN --mount=type=cache,target=/root/.cache/pip \
pip install -e . \
&& flask fab babel-compile --target superset/translations \
&& chown -R superset:superset superset/translations
pip install -e .

# Compile translations
RUN pybabel compile -d superset/translations
# Compile translations for the backend - this generates .mo files
COPY ./scripts/translations/generate_po_files.sh ./scripts/translations/
RUN ./scripts/translations/generate_po_files.sh && \
chown -R superset:superset superset/translations

COPY --chmod=755 ./docker/run-server.sh /usr/bin/
USER superset
Expand Down
9 changes: 8 additions & 1 deletion RELEASING/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,14 @@ Create the distribution
cd superset-frontend/
npm ci && npm run build
cd ../
flask fab babel-compile --target superset/translations

# Compile translations for the frontend
./scripts/translations/po2json.sh

# Compile translations for the backend
./scripts/translations/generate_po_files.sh

# build the python distribution
python setup.py sdist
```

Expand Down
File renamed without changes.
15 changes: 5 additions & 10 deletions scripts/po2json.sh → scripts/translations/generate_po_files.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
Expand All @@ -15,13 +16,7 @@
# specific language governing permissions and limitations
# under the License.

for file in $( find superset/translations/** );
do
extension=${file##*.}
filename="${file%.*}"
if [ $extension == "po" ]
then
po2json --domain superset --format jed1.x $file $filename.json
./superset-frontend/node_modules/.bin/prettier --write $filename.json
fi
done
# This script generates .mo binary files from .po translation files
# these .mo files are used by the backend to load translations

flask fab babel-compile --target superset/translations
34 changes: 34 additions & 0 deletions scripts/translations/po2json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.


# This script generates .json files from .po translation files
# these json files are used by the frontend to load translations

npm install -g po2json prettier
for file in $( find superset/translations/** -name '*.po' );
do
extension=${file##*.}
filename="${file%.*}"
if [ $extension == "po" ]
then
echo "po2json --domain superset --format jed1.x $file $filename.json"
po2json --domain superset --format jed1.x $file $filename.json
prettier --write $filename.json
fi
done
Loading

0 comments on commit 6ac1fc5

Please sign in to comment.