Skip to content

Commit

Permalink
Fix translation files and update documentation (#12595)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina authored and villebro committed Jan 25, 2021
1 parent b07188e commit 278e5b8
Show file tree
Hide file tree
Showing 26 changed files with 98,938 additions and 42,319 deletions.
38 changes: 29 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ npm run test
```

To run a single test file:

```bash
npm run test -- path/to/file.js
```
Expand Down Expand Up @@ -723,14 +724,14 @@ See [`superset-frontend/cypress_build.sh`](https://github.com/apache/superset/bl
As an alternative you can use docker-compose environment for testing:

Make sure you have added below line to your /etc/hosts file:
```127.0.0.1 db```
`127.0.0.1 db`

If you already have launched Docker environment please use the following command to assure a fresh database instance:
```docker-compose down -v```
`docker-compose down -v`

Launch environment:

```CYPRESS_CONFIG=true docker-compose up```
`CYPRESS_CONFIG=true docker-compose up`

It will serve backend and frontend on port 8088.

Expand Down Expand Up @@ -794,22 +795,35 @@ LANGUAGES = {
### Extracting new strings for translation

```bash
flask fab babel-extract --target superset/translations --output superset/translations/messages.pot --config superset/translations/babel.cfg -k _ -k __ -k t -k tn -k tct
pybabel extract -F superset/translations/babel.cfg -o superset/translations/messages.pot -k _ -k __ -k t -k tn -k tct .
```

This will update the template file `superset/translations/messages.pot` with current application strings. Do not forget to update
this file with the appropriate license information.

### Updating language files

```bash
pybabel update -i superset/translations/messages.pot -d superset/translations --ignore-obsolete
```

This will update language files with the new extracted strings.

You can then translate the strings gathered in files located under
`superset/translation`, where there's one per language. You can use [Poedit](https://poedit.net/features)
to translate the `po` file more conveniently.
There are some [tutorials in the wiki](https://wiki.lxde.org/en/Translate_*.po_files_with_Poedit).

For the translations to take effect:
In the case of JS translation, we need to convert the PO file into a JSON file, and we need the global download of the npm package po2json.

```bash
# In the case of JS translation, we need to convert the PO file into a JSON file, and we need the global download of the npm package po2json.
npm install -g po2json
flask fab babel-compile --target superset/translations
# Convert the en PO file into a JSON file
po2json -d superset -f jed1.x superset/translations/en/LC_MESSAGES/messages.po superset/translations/en/LC_MESSAGES/messages.json
```

To convert all PO files to formatted JSON files you can use the `po2json.sh` script.

```bash
./scripts/po2json.sh
```

If you get errors running `po2json`, you might be running the Ubuntu package with the same
Expand All @@ -819,6 +833,12 @@ the executable path (e.g. `/usr/local/bin/po2json` instead of `po2json`).
If you get a lot of `[null,***]` in `messages.json`, just delete all the `null,`.
For example, `"year":["年"]` is correct while `"year":[null,"年"]`is incorrect.

For the translations to take effect we need to compile translation catalogs into binary MO files.

```bash
pybabel compile -d superset/translations
```

### Creating a new language dictionary

To create a dictionary for a new language, run the following, where `LANGUAGE_CODE` is replaced with
Expand Down
27 changes: 27 additions & 0 deletions scripts/po2json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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.

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
2 changes: 1 addition & 1 deletion superset-frontend/src/SqlLab/actions/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ export function popStoredQuery(urlId) {
.then(({ json }) =>
dispatch(
addQueryEditor({
title: json.title ? json.title : t('Sjsonhared query'),
title: json.title ? json.title : t('Shared query'),
dbId: json.dbId ? parseInt(json.dbId, 10) : null,
schema: json.schema ? json.schema : null,
autorun: json.autorun ? json.autorun : false,
Expand Down
Loading

0 comments on commit 278e5b8

Please sign in to comment.